var downloadFormBox;
function download() {
	
	var email = getCookie('demail');
	var name = getCookie('dname');
	var org = getCookie('dorg');
	var phone = getCookie('dphone');
	
	var form = jQuery('.downloadWhitepaperForm form');
	
	if (email != '') jQuery("#dEmail",form).val(email);
	if (name != '') jQuery("#dName",form).val(name);
	if (org != '') jQuery("#dOrg",form).val(org);
	if (phone != '') jQuery("#dPhone",form).val(phone);

	if (typeof(downloadFormBox) == 'undefined') 
		downloadFormBox = new Boxy(".downloadWhitepaperForm", {
			title: "Download whitepaper",
			modal: true,
			center: true
		});
	else 
		downloadFormBox.show();
		
	return false;
}

function submitDownload(form,scriptSubmit) {
	
	if(typeof(scriptSubmit)=="false") scriptSubmit = false;
	form = jQuery(form);
	var nForm = jQuery("#dName",form);
	var oForm = jQuery("#dOrg",form);
	var eForm = jQuery("#dEmail",form);
	var pForm = jQuery("#dPhone",form);
	
	setCookie('demail',eForm.val());
	setCookie('dphone',pForm.val());
	setCookie('dname',nForm.val());
	setCookie('dorg',oForm.val());
	
	if(oForm.val()=='') {
		oForm.css("border-color","#ff0000")
		alert("Please fill in your organization!");
		return false;
	}else oForm.css("border-color","#5991BF");
	
	if(nForm.val()=='') {
		nForm.css("border-color","#ff0000")
		alert("Please fill in your name!");
		return false;
	}
	else nForm.css("border-color","#5991BF");
	
	if(pForm.val()=='') {
		pForm.css("border","1px solid #ff0000")
		alert("Please fill in your phone!");
		return false;
	}else pForm.css("border-color","#5991BF");
	
	if(eForm.val()=='') {
		eForm.css("border","1px solid #ff0000")
		alert("Please fill in your email!");
		return false;
	}else eForm.css("border-color","#5991BF");
	if(scriptSubmit) form.submit();
	return true;
}



/**
 * @param name - name of cookie
 * @param value = value of cookie 
 * @param expire = expiration in minutes
 */
function setCookie(name, value, expire, path, domain, secure) {
	var today = new Date();
	/**
	 * defaults
	 */
	if(typeof(path) == "undefined") path = '';
	if(typeof(domain) == "undefined") domain = '';
	if(typeof(secure) == "undefined") secure = '';
	
	var expireTime = new Date();
	expireTime.setTime(today.getTime() + 60000*expire);
	document.cookie = name+"="+escape(value) + ";expires="+expireTime.toGMTString() + 
					( ( path ) ? ";path=" + path : "" ) +
					( ( domain ) ? ";domain=" + domain : "" ) +
					( ( secure ) ? ";secure" : "" );;
} //end setCookie

/**
 * returns the cookie with the name "name"
 */
function getCookie(name) {
	var cookie=""+document.cookie;
	var ind=cookie.indexOf(name);
	if (ind==-1 || name=="") return ""; 
	var indend=cookie.indexOf(';',ind);
	if (indend==-1) indend=cookie.length; 
	 return unescape(cookie.substring(ind+name.length+1,indend));
} //end getCookie

/**
 * deletes a cookie
 */
function deleteCookie(name,path,domain){
	setCookie(name, 'deleted', -1,path,domain);
}