/////////////////////////////////////////////
//SecurityCode and EventList Ajax
/////////////////////////////////////////////

    var XMLHttpReq = false;
    var secruityCodeErr = true;
    var getResult = false;
    var submitForm = null;
	function pausecomp(millis)
	{
		var date = new Date();
		var curDate = null;
		
		do { curDate = new Date(); }
		while(curDate-date < millis);
	} 

     function createXMLHttpRequest() {
		if(window.XMLHttpRequest) { //Mozilla
			XMLHttpReq = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE
			try {
				XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	}

	function sendRequest(url,state) {
		var topic ;
		topic = document.getElementById("interestarea");
		if(state!=1){
			if(topic!=null){
				//解决url带参数的时候不能带&字符的问题
				if(topic.value.indexOf("&")>-1){
					topic = topic.value.replace("&","|");
				}else{
					topic = topic.value;
				}
				url = url + "?topic=" + topic;
			}//alert(url);
		}
		getResult = false;
		createXMLHttpRequest();
		XMLHttpReq.open("GET", url, true);
		if(state==1){
			XMLHttpReq.onreadystatechange = processResponse;
		}
		else{
			XMLHttpReq.onreadystatechange = getevents;
		}
		XMLHttpReq.send(null);
				
	}
//SecurityCode
    function processResponse() {
        
    	if (XMLHttpReq.readyState == 4) {
    	 
        	if (XMLHttpReq.status == 200) { 
				var res=XMLHttpReq.responseText;
				var code = document.getElementById("securitycode");
				var securitycodeError = document.getElementById("securitycodeError");
				var securitycodeImage = document.getElementById("securitycodeImage");
				getResult = true;
    	
				if(res.Trim()=="true"){
					code.style.background="#FFFFFF";
					securitycodeError.style.display="none";
					secruityCodeErr =false;
					
					if (submitForm != null) {
						if (submitForm.id=="contactmeForm")
							contactme_saveCookie();
						if (submitForm.id=="tellafriendForm")
							tellafriend_saveCookie();
						if (submitForm.id=="purchasepastForm")
							purchasepast_saveCookie();
						if (submitForm.id=="speakersponsorForm")
							beaspeak_saveCookie();
						setVisible('nowloading',true);
						submitForm.submit();
						return true;
					}
					
				}else{
					code.style.background="#FFFF33";
					securitycodeError.innerHTML="<span class='form_error_message'>Security code is wrong</span>";
					securitycodeError.style.display="block";
					secruityCodeErr =true;
					regenerateSecurityCode(secruityCodeErr);
					return false;
				}
		} 
        }
    }
    	
//EventList
    function getevents() {

    	if (XMLHttpReq.readyState == 4) {
        	if (XMLHttpReq.status == 200) { 
			var res=XMLHttpReq.responseText.Trim();
			var event = document.getElementById("forevent");
			event.innerHTML = "";
			var resArray = res.split("@");
			//alert(resArray);
			//alert(event);
			if(resArray.length<=1){
				event.options.add(new Option('No matchable events...',''));
				//event.innerHTML = "<option value='' selected='selected'>No matchable events...</option>";
			}else{
				event.options.add(new Option('Please Choose...',''));
				for(var i=1;i<resArray.length;i++){
					event.options.add(new Option(resArray[i],resArray[i]));
					//event.innerHTML = event.innerHTML+"<option value='"+resArray[i]+"'>"+resArray[i]+"</option>";
				}
			}
			
			
		  } 
      }
    }
    
    
	String.prototype.Trim = function(){
	 	return this.replace(/(^\s*)|(\s*$)/g, "");
	}
	
    function checkSecurityCode() {

		getResult = false;
		var code = document.getElementById("securitycode").value;
		if (code != ""){
			sendRequest('../Home/testcaptcha.jsp?j_captcha_response='+code,1);
		}
     }

    function checkSecurityCodeEmpty() {
		var withError = true;
		var securitycodeError = document.getElementById("securitycodeError");	
		var code = document.getElementById("securitycode");
		if(code.value ==""){
			code.style.background="#FFFF33";
			securitycodeError.innerHTML="<span class='form_error_message'>Security Code is required</span>";
			securitycodeError.style.display="block";
			withError=true;
		}else{
			code.style.background="#FFFFFF";
			securitycodeError.style.display="none";
			withError=false;
		}
		return withError;
	
     }
  
	function regenerateSecurityCode(clear) {

		var imageobject= document.getElementById("securitycodeImage");
		imageobject.src="/opencms/opencms/jcaptcha?a="+Math.floor(Math.random()*11);
		if (clear)
		document.getElementById("securitycode").value ="";
	}

/////////////////////////////////////////////
//Check OnKeyPress
/////////////////////////////////////////////

	function checkempty(id){
		var aa = document.getElementById(id);
		var bb = document.getElementById(id + "Error");
		aa.style.background="#FFFFFF";
		bb.style.display="none";
	}

/////////////////////////////////////////////
//Contact Me
/////////////////////////////////////////////

	function contactme_checkout(){
		var withError = false;


		
		if (contactme_checkemail()){
			withError = true;
		}
		
		if(contactme_checkfirstname()){ 
			withError = true;
		}
		
		if(contactme_checkfamilyname()) {
			withError = true;
		}
		
		if(contactme_checkjobtitle()) {
			withError = true;
		}
		

		if(contactme_checkcompanyname()) {
			withError = true;
		}

		if(contactme_checkphoneno1()) {
			withError = true;
		}

		if(contactme_checkphoneno2()) {
			withError = true;
		}
		
		if(contactme_checkphoneno3()) {
			withError = true;
		}
		
		if(contactme_checkphoneno4()) {
			withError = true;
		}
		
		if(contactme_checksalutation()) {
			withError = true;
		}
		
		if(contactme_checkcountry()) {
			withError = true;
		}
		
		if (contactme_checkcontact()) {
			withError = true;
		}
		
		if (checkSecurityCodeEmpty()) {
			withError = true;
		}

		if (!withError) {
			//submitForm =document.contactmeForm;
			submitForm = document.getElementById("contactmeForm");
			//contactme_saveCookie();
			checkSecurityCode();
		}	
	}
	
	function contactme_checksalutation(){
		var withError = false;
		var salutation= document.getElementById("salutation");

		var salutationError= document.getElementById("salutationError");
		if(salutation.selectedIndex == "0") {
			salutation.style.background="#FFFF33";
			salutationError.innerHTML="<span class='form_error_message'>Select one option</span>";
			salutationError.style.display="block";
			withError= true;
		} else{
			salutation.style.background="#FFFFFF";
			salutationError.style.display="none";
			withError = false;
		}

		return withError;
	}

	function contactme_checkemail(){
		var withError=false;
		var u = /^[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9_\.]+[\.a-zA-Z]+$/;
		var emailaddressError = document.getElementById("emailaddressError");
		var emailaddress = document.getElementById("emailaddress");
		if(emailaddress.value==""){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email address is required</span>";
			emailaddressError.style.display="block";
			withError= true;
		}else if(emailaddress.value.match(u)==null){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email address is invalid in format</span>";
			emailaddressError.style.display="block";
			withError= true;
		}else{
			emailaddress.style.background="#FFFFFF";
			emailaddressError.style.display="none";
		}
		return withError;
	}

	function contactme_checkfirstname(){
		
		var withErro=false;
		var firstnameError = document.getElementById("firstnameError");
		var firstname = document.getElementById("firstname");
		if(firstname.value==""){
			firstname.style.background="#FFFF33";
			firstnameError.innerHTML="<span class='form_error_message'>First name is required</span>";
			firstnameError.style.display="block";
			withError= true;
		}else{
			firstname.style.background="#FFFFFF";
			firstnameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function contactme_checkfamilyname(){
		
		var withErro=false;
		var familynameError = document.getElementById("familynameError");
		var familyname = document.getElementById("familyname");
		if(familyname.value==""){
			familyname.style.background="#FFFF33";
			familynameError.innerHTML="<span class='form_error_message'>Family name is required</span>";
			familynameError.style.display="block";
			withError= true;
		}else{
			familyname.style.background="#FFFFFF";
			familynameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function contactme_checkjobtitle(){
		var withErro=false;
		var jobtitleError = document.getElementById("jobtitleError");
		var jobtitle = document.getElementById("jobtitle");
		if(jobtitle.value==""){
			jobtitle.style.background="#FFFF33";
			jobtitleError.innerHTML="<span class='form_error_message'>Job title is required</span>";
			jobtitleError.style.display="block";
			withError= true;
		}else{
			jobtitle.style.background="#FFFFFF";
			jobtitleError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function contactme_checkcompanyname(){
		var companynameError = document.getElementById("companynameError");
		var companyname = document.getElementById("companyname");
		
		if(companyname.value==""){
			companyname.style.background="#FFFF33";
			companynameError.innerHTML="<span class='form_error_message'>Company is required</span>";
			companynameError.style.display="block";
			withError= true;
		}else{
			companyname.style.background="#FFFFFF";
			companynameError.style.display="none";
			withError= false;
		}
		return withError;
	}
	
	function contactme_checkcountry(){
		var withError = false;
		var country= document.getElementById("country");

		var countryError= document.getElementById("countryError");
		if(country.selectedIndex == "0") {
			country.style.background="#FFFF33";
			countryError.innerHTML="<span class='form_error_message'>Select one option</span>";
			countryError.style.display="block";
			withError= true;
		} else{
			country.style.background="#FFFFFF";
			countryError.style.display="none";
			withError = false;
		}

		return withError;
	}

	function contactme_checkphoneno1(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno1Error");
		var phoneno1 = document.getElementById("phoneno1");
		if(phoneno1.value.match(u)==null){
			phoneno1.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Country code is invalid. Please input numeric only</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno1.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		
		return withError;
	}
	
	function contactme_checkphoneno2(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno2Error");
		var phoneno2 = document.getElementById("phoneno2");
		if(phoneno2.value.match(u)==null){
			phoneno2.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Area code is invalid. Please input numeric only</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno2.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		
		return withError;
	}
	
	function contactme_checkphoneno3(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno3Error");
		var phoneno3 = document.getElementById("phoneno3");
		if (phoneno3.value =="" ) {
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is required</span>";
			phonenoError.style.display="block";
			withError =true;
		} else if(phoneno3.value.match(u)==null){
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is invalid. Please input numeric only</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno3.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		
		return withError;
	}
	
	function contactme_checkphoneno4(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno4Error");
		var phoneno4 = document.getElementById("phoneno4");
		if(phoneno4.value.match(u)==null){
			phoneno4.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Ext is invalid. Please input numeric only</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno4.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		
		return withError;
	}
	
	function contactme_checkcontact(){
		var withError = false;
		var contact= document.getElementById("contact");

		var contactError= document.getElementById("contactError");
		if(contact.selectedIndex == "0") {
			contact.style.background="#FFFF33";
			contactError.innerHTML="<span class='form_error_message'>Select one option</span>";
			contactError.style.display="block";
			withError= true;
		} else{
			contact.style.background="#FFFFFF";
			contactError.style.display="none";
			withError = false;
		}

		return withError;
	}

	function contactme_reset(){
		document.getElementById("contactmeForm").reset();
	}



/////////////////////////////////////////////
//Tell a Friend
/////////////////////////////////////////////
	function tellafriend_checkout(){
		var withError = false;


		
		if (tellafriend_checkyouname()){
			withError = true;
		}
		
		if(tellafriend_checkyouemail()){ 
			withError = true;
		}
		
		if(tellafriend_checknameofcoll()) {
			withError = true;
		}
		
		if(tellafriend_checkemailofcoll()) {
				withError = true;
		}
		
		if (checkSecurityCodeEmpty()) {
			withError = true;
		}

		if (!withError) {
			//submitForm =document.tellafriendForm;
			submitForm = document.getElementById("tellafriendForm");
			//tellafriend_saveCookie();
			checkSecurityCode();
		}
	}
	
	function tellafriend_checkyouname(){
		var withError =false;
		
		var younameError = document.getElementById("younameError");
		var youname = document.getElementById("youname");
		if(youname.value==""){
			youname.style.background="#FFFF33";
			younameError.innerHTML="<span class='form_error_message'>Your name is required</span>";
			younameError.style.display="block";
			withError= true;
		} else{
			youname.style.background="#FFFFFF";
			younameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function tellafriend_checkyouemail(){
		var withError =false;
		var u = /^[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9_\.]+[\.a-zA-Z]+$/;
		var youemailError = document.getElementById("youemailError");
		var youemail = document.getElementById("youemail");
		
		if(youemail.value==""){
			youemail.style.background="#FFFF33";
			youemailError.innerHTML="<span class='form_error_message'>Your email is required</span>";
			youemailError.style.display="block";
			withError= true;
		} else if(youemail.value.match(u)==null){
			youemail.style.background="#FFFF33";
			youemailError.innerHTML="<span class='form_error_message'>Your email is invalid in format</span>";
			youemailError.style.display="block";
			withError= true;
		}else{
			youemail.style.background="#FFFFFF";
			youemailError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function tellafriend_checknameofcoll(){
		var withError =false;
		var nameofcollError = document.getElementById("nameofcollError");
		var nameofcoll = document.getElementById("nameofcoll");
		
		if(nameofcoll.value==""){
			nameofcoll.style.background="#FFFF33";
			nameofcollError.innerHTML="<span class='form_error_message'>Name of colleague is required</span>";
			nameofcollError.style.display="block";
			withError= true;
		} else{
			nameofcoll.style.background="#FFFFFF";
			nameofcollError.style.display="none";
			withError= false;
		}
		return withError;
	}
	function tellafriend_checkemailofcoll(){
		
		
		var withError =false;
		
		var u = /^[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9_\.]+[\.a-zA-Z]+$/;
		var emailofcollError = document.getElementById("emailofcollError");
		var emailofcoll = document.getElementById("emailofcoll");
		
		if(emailofcoll.value==""){
			emailofcoll.style.background="#FFFF33";
			emailofcollError.innerHTML="<span class='form_error_message'>Email of colleague is required</span>";
			emailofcollError.style.display="block";
			withError= true;
		} else if(emailofcoll.value.match(u)==null){
			emailofcoll.style.background="#FFFF33";
			emailofcollError.innerHTML="<span class='form_error_message'>Email of colleague is invalid in format</span>";
			emailofcollError.style.display="block";
			withError= true;
		}else{
			emailofcoll.style.background="#FFFFFF";
			emailofcollError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function tellafriend_reset(){
		document.getElementById("tellafriendForm").reset();
	}
	

/////////////////////////////////////////////
//Purchase Past
/////////////////////////////////////////////
	function purchasepast_checkout(){
		var withError = false;


		
		if (purchasepast_checkemail()){
			withError = true;
		}
		
		if(purchasepast_checkfirstname()){ 
			withError = true;
		}
		
		if(purchasepast_checkfamilyname()) {
			withError = true;
		}
		
		if(purchasepast_checkjobtitle()) {
				withError = true;
		}
		
		if(purchasepast_checkcompanyname()) {
			withError = true;
		}
		
		if(purchasepast_checkphoneno1()) {
			withError = true;
		}
		
		if(purchasepast_checkphoneno2()) {
			withError = true;

		}
		if(purchasepast_checkphoneno3()) {
			withError = true;
		}
		if(purchasepast_checkphoneno4()) {
			withError = true;
		}
		
		if (checkSecurityCodeEmpty()) {
			withError = true;
		}
		
		if (purchasepast_checkinterestarea()) {
			withError = true;
		}
		
		if (purchasepast_checkforevent()) {
			withError = true;
		}
		
		if (purchasepast_checksalutation()) {
			withError = true;
		}

		if (!withError) {
			//submitForm =document.purchasepastForm;
			submitForm = document.getElementById("purchasepastForm");
			//purchasepast_saveCookie();
			checkSecurityCode();
		}
	}
	
	function purchasepast_checkinterestarea(){
		var withError = false;
		var interestarea= document.getElementById("interestarea");
		var interestareaError= document.getElementById("interestareaError");
		
		if(interestarea.selectedIndex == "0") {
			interestarea.style.background="#FFFF33";
			interestareaError.innerHTML="<span class='form_error_message'>Select one option</span>";
			interestareaError.style.display="block";
			withError= true;
		} else{
			interestarea.style.background="#FFFFFF";
			interestareaError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function purchasepast_checkforevent(){
		var withError = false;
		var forevent= document.getElementById("forevent");
		var foreventError= document.getElementById("foreventError");
		
		if(forevent.value == "") {
			forevent.style.background="#FFFF33";
			foreventError.innerHTML="<span class='form_error_message'>Select one option</span>";
			foreventError.style.display="block";
			withError= true;
		} else{
			forevent.style.background="#FFFFFF";
			foreventError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function purchasepast_checksalutation(){
		var withError = false;
		var salutation= document.getElementById("salutation");
		var salutationError= document.getElementById("salutationError");
		
		if(salutation.selectedIndex == "0") {
			salutation.style.background="#FFFF33";
			salutationError.innerHTML="<span class='form_error_message'>Select one option</span>";
			salutationError.style.display="block";
			withError= true;
		} else{
			salutation.style.background="#FFFFFF";
			salutationError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function purchasepast_checkemail(){
		var withError = false;
		var u = /^[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9_\.]+[\.a-zA-Z]+$/;
		var emailaddressError = document.getElementById("emailaddressError");
		var emailaddress = document.getElementById("emailaddress");
		
		if(emailaddress.value==""){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email address is required</span>";
			emailaddressError.style.display="block";
			withError= true;
		} else if(emailaddress.value.match(u)==null){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email is invalid in format</span>";
			emailaddressError.style.display="block";
			withError= true;
		} else{
			emailaddress.style.background="#FFFFFF";
			emailaddressError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function purchasepast_checkfirstname(){
		var withError = false;
		
		var firstnameError = document.getElementById("firstnameError");
		var firstname = document.getElementById("firstname");
		if(firstname.value==""){
			firstname.style.background="#FFFF33";
			firstnameError.innerHTML="<span class='form_error_message'>First name is required</span>";
			firstnameError.style.display="block";
			withError= true;
		}else{
			firstname.style.background="#FFFFFF";
			firstnameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function purchasepast_checkfamilyname(){
		var withError = false;
		
		var familynameError = document.getElementById("familynameError");
		var familyname = document.getElementById("familyname");
		if(familyname.value==""){
			familyname.style.background="#FFFF33";
			familynameError.innerHTML="<span class='form_error_message'>Family name is required</span>";
			familynameError.style.display="block";
			withError= true;
		}else{
			familyname.style.background="#FFFFFF";
			familynameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function purchasepast_checkjobtitle(){
		
		var withError = false;
		var jobtitleError = document.getElementById("jobtitleError");
		var jobtitle = document.getElementById("jobtitle");
		if(jobtitle.value==""){
			jobtitle.style.background="#FFFF33";
			jobtitleError.innerHTML="<span class='form_error_message'>Job title is required</span>";
			jobtitleError.style.display="block";
			withError= true;
		} else {
			jobtitle.style.background="#FFFFFF";
			jobtitleError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function purchasepast_checkcompanyname(){
		var withError = false;
		var companynameError = document.getElementById("companynameError");
		var companyname = document.getElementById("companyname");
		if(companyname.value==""){
			companyname.style.background="#FFFF33";
			companynameError.innerHTML="<span class='form_error_message'>Company name is required</span>";
			companynameError.style.display="block";
			withError= true;
		} else {
			companyname.style.background="#FFFFFF";
			companynameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function purchasepast_checkphoneno1(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno1Error");
		var phoneno1 = document.getElementById("phoneno1");
		
		
		if(phoneno1.value.match(u)==null){
			phoneno1.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Country code is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno1.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}
	function purchasepast_checkphoneno2(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno2Error");
		var phoneno2 = document.getElementById("phoneno2");
		if(phoneno2.value.match(u)==null){
			phoneno2.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Area code is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno2.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError
	}
	function purchasepast_checkphoneno3(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno3Error");
		var phoneno3 = document.getElementById("phoneno3");
		
		if (phoneno3.value =="" ) {
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is required</span>";
			phonenoError.style.display="block";
			withError =true;
		} else if(phoneno3.value.match(u)==null){
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno3.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}
	
	function purchasepast_checkphoneno4(){
	
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno4Error");
		var phoneno4 = document.getElementById("phoneno4");
		if(phoneno4.value.match(u)==null){
			phoneno4.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Ext is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno4.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}

	function purchasepast_reset(){
		document.getElementById("purchasepastForm").reset();
	}


/////////////////////////////////////////////
//Be a Speaker
/////////////////////////////////////////////

	function beaspeak_checkout(){

		var withError = false;

		
		
		if (beaspeak_checkspeakerSponsor()){
			withError = true;
		}
		
		if(beaspeak_checkemail()){ 
			withError = true;
		}
		
		if(beaspeak_checkfirstname()) {
			withError = true;
		}
		
		if(beaspeak_checkfamilyname()) {
				withError = true;
		}
		
		if(beaspeak_checkjobtitle()) {
			withError = true;
		}
		
		if(beaspeak_checkcompanyname()) {
			withError = true;
		}
		
		if(beaspeak_checkphoneno1()) {
			withError = true;
		}
		
		if (beaspeak_checkphoneno2()) {
			withError = true;
		}
		
		if (beaspeak_checkphoneno3()) {
			withError = true;
		}
		if (beaspeak_checkphoneno4()) {
			withError = true;
		}
		
		if (checkSecurityCodeEmpty()) {
			withError = true;
		}

		
		if (beaspeak_checkforevent()) {
			withError = true;
		}
		
				
		if (beaspeak_checksalutation()) {
			withError = true;
		}
		
				
		if (beaspeak_checkcountry()) {
			withError = true;
		}
		
		if (!withError) {
			//submitForm =document.speakersponsorForm;
			submitForm = document.getElementById("speakersponsorForm");
			//beaspeak_saveCookie();
			checkSecurityCode();
		}
	
	}

	function beaspeak_checkspeakerSponsor(){
	  var withError = false;
		var speaker= document.getElementById("speaker");
		var sponsor= document.getElementById("sponsor");
		var speakerSponsorError= document.getElementById("speakerSponsorError");
		
		if(!speaker.checked && !sponsor.checked) {
			speakerSponsorError.innerHTML="<span class='form_error_message'>Select at least one option</span>";
			speakerSponsorError.style.display="block";
			withError= true;
		} else{
			speakerSponsorError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function beaspeak_checkforevent(){
		var withError = false;
		var forevent= document.getElementById("forevent");
		var foreventError= document.getElementById("foreventError");
		
		if(forevent.selectedIndex == "0") {
			forevent.style.background="#FFFF33";
			foreventError.innerHTML="<span class='form_error_message'>Select one option</span>";
			foreventError.style.display="block";
			withError= true;
		} else{
			forevent.style.background="#FFFFFF";
			foreventError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function beaspeak_checksalutation(){
		var withError = false;
		var salutation= document.getElementById("salutation");
		var salutationError= document.getElementById("salutationError");
		
		if(salutation.selectedIndex == "0") {
			salutation.style.background="#FFFF33";
			salutationError.innerHTML="<span class='form_error_message'>Select one option</span>";
			salutationError.style.display="block";
			withError= true;
		} else{
			salutation.style.background="#FFFFFF";
			salutationError.style.display="none";
			withError = false;
		}

		return withError;
	}
	
	function beaspeak_checkemail(){
		
		var withError = false;
		var u = /^[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9_\.]+[\.a-zA-Z]+$/;
		var emailaddressError = document.getElementById("emailaddressError");
		var emailaddress = document.getElementById("emailaddress");
		
		if(emailaddress.value==""){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email address is required</span>";
			emailaddressError.style.display="block";
			withError= true;
		} else 	if(emailaddress.value.match(u)==null){
			emailaddress.style.background="#FFFF33";
			emailaddressError.innerHTML="<span class='form_error_message'>Email address is invalid in format</span>";
			emailaddressError.style.display="block";
			withError= true;
		}else{
			emailaddress.style.background="#FFFFFF";
			emailaddressError.style.display="none";
			withError= false;
		}
		
		return withError;
	}

	function beaspeak_checkfirstname(){
		var withError = false;
		var u = /^[a-zA-Z]*$/;
		var firstnameError = document.getElementById("firstnameError");
		var firstname = document.getElementById("firstname");

		if(firstname.value==""){
			firstname.style.background="#FFFF33";
			firstnameError.innerHTML="<span class='form_error_message'>First name is required</span>";
			firstnameError.style.display="block";
			withError= true;
		}else{
			firstname.style.background="#FFFFFF";
			firstnameError.style.display="none";
			withError = false;
		}
		return withError;
	}

	function beaspeak_checkfamilyname(){

		var withError = false;
		var u = /^[a-zA-Z]*$/;
		var familynameError = document.getElementById("familynameError");
		var familyname = document.getElementById("familyname");
		
		if(familyname.value==""){
			familyname.style.background="#FFFF33";
			familynameError.innerHTML="<span class='form_error_message'>Family name is required</span>";
			familynameError.style.display="block";
			withError= true;
		}else{
			familyname.style.background="#FFFFFF";
			familynameError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function beaspeak_checkjobtitle(){
		var withError =false;
		var jobtitleError = document.getElementById("jobtitleError");
		var jobtitle = document.getElementById("jobtitle");
		
		if(jobtitle.value==""){
			jobtitle.style.background="#FFFF33";
			jobtitleError.innerHTML="<span class='form_error_message'>Job title is required</span>";
			jobtitleError.style.display="block";
			withError= true;
		} else {
			jobtitle.style.background="#FFFFFF";
			jobtitleError.style.display="none";
			withError= false;
		}
		return withError;
	}

	function beaspeak_checkcompanyname(){
		var withError =false;
		var companyname = document.getElementById("companyname");
		var companynameError = document.getElementById("companynameError");
		
		if(companyname.value==""){
			companyname.style.background="#FFFF33";
			companynameError.innerHTML="<span class='form_error_message'>Company name is required</span>";
			companynameError.style.display="block";
			withError= true;
		} else {
			companyname.style.background="#FFFFFF";
			companynameError.style.display="none";
			withError= false;
		}
		return withError;
	}
	
	function beaspeak_checkcountry(){
		var withError = false;
		var country= document.getElementById("country");
		var countryError= document.getElementById("countryError");
		
		if(country.selectedIndex == "0") {
			country.style.background="#FFFF33";
			countryError.innerHTML="<span class='form_error_message'>Select one option</span>";
			countryError.style.display="block";
			withError= true;
		} else{
			country.style.background="#FFFFFF";
			countryError.style.display="none";
			withError = false;
		}

		return withError;
	}

	function beaspeak_checkphoneno1(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno1Error");
		var phoneno1 = document.getElementById("phoneno1");
		
		if(phoneno1.value.match(u)==null){
			phoneno1.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Country code is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno1.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}
	function beaspeak_checkphoneno2(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno2Error");
		var phoneno2 = document.getElementById("phoneno2");
		
		if(phoneno2.value.match(u)==null){
			phoneno2.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Area code is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno2.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError
	}
	function beaspeak_checkphoneno3(){
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno3Error");
		var phoneno3 = document.getElementById("phoneno3");
		
		if (phoneno3.value =="" ) {
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is required</span>";
			phonenoError.style.display="block";
			withError =true;
		} else if(phoneno3.value.match(u)==null){
			phoneno3.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Phone number is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno3.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}
	function beaspeak_checkphoneno4(){
	
		var withError = false;
		var u = /^[0-9]*$/;
		var phonenoError = document.getElementById("phoneno4Error");
		var phoneno4 = document.getElementById("phoneno4");
		
		if(phoneno4.value.match(u)==null){
			phoneno4.style.background="#FFFF33";
			phonenoError.innerHTML="<span class='form_error_message'>Ext is invalid in format</span>";
			phonenoError.style.display="block";
			withError =true;
		}else{
			phoneno4.style.background="#FFFFFF";
			phonenoError.style.display="none";
			withError =false;
		}
		return withError;
	}

	function beaspeak_reset(){
		document.getElementById("speakersponsorForm").reset();
	}


/////////////////////////////////////////////
//Auto Fill In
/////////////////////////////////////////////

function beaspeak_checkCookie() {
	var be_a_speak = new Array("0","","","","","0","","","","","");
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var country = document.getElementById("country");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	
	if (readCookie("be_a_speak")!=null)
		be_a_speak = readCookie("be_a_speak").split("|");
	salutation.selectedIndex = be_a_speak[0];
	firstname.value = be_a_speak[1];
	familyname.value = be_a_speak[2];
	jobtitle.value = be_a_speak[3];
	companyname.value = be_a_speak[4];
	country.selectedIndex = be_a_speak[5];
	phoneno1.value = be_a_speak[6];
	phoneno2.value = be_a_speak[7];
	phoneno3.value = be_a_speak[8];
	phoneno4.value = be_a_speak[9];
	emailaddress.value = be_a_speak[10];
}

function beaspeak_saveCookie() {
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var country = document.getElementById("country");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	var be_a_speak = "";
	
	be_a_speak = salutation.selectedIndex;
	be_a_speak += "|";
	be_a_speak += firstname.value;
	be_a_speak += "|";
	be_a_speak += familyname.value;
	be_a_speak += "|";
	be_a_speak += jobtitle.value;
	be_a_speak += "|";
	be_a_speak += companyname.value;
	be_a_speak += "|";
	be_a_speak += country.selectedIndex;
	be_a_speak += "|";
	be_a_speak += phoneno1.value;
	be_a_speak += "|";
	be_a_speak += phoneno2.value;
	be_a_speak += "|";
	be_a_speak += phoneno3.value;
	be_a_speak += "|";
	be_a_speak += phoneno4.value;
	be_a_speak += "|";
	be_a_speak += emailaddress.value;
	createCookie("be_a_speak", be_a_speak,30);
}

function purchasepast_checkCookie() {
	var buy_past_presentations = new Array("0","","","","","","","","","");
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	
	if (readCookie("buy_past_presentations")!=null)
		buy_past_presentations = readCookie("buy_past_presentations").split("|");
	salutation.selectedIndex = buy_past_presentations[0];
	firstname.value = buy_past_presentations[1];
	familyname.value = buy_past_presentations[2];
	jobtitle.value = buy_past_presentations[3];
	companyname.value = buy_past_presentations[4];
	phoneno1.value = buy_past_presentations[5];
	phoneno2.value = buy_past_presentations[6];
	phoneno3.value = buy_past_presentations[7];
	phoneno4.value = buy_past_presentations[8];
	emailaddress.value = buy_past_presentations[9];
}

function purchasepast_saveCookie() {
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	var buy_past_presentations = "";
	
	buy_past_presentations = salutation.selectedIndex;
	buy_past_presentations += "|";
	buy_past_presentations += firstname.value;
	buy_past_presentations += "|";
	buy_past_presentations += familyname.value;
	buy_past_presentations += "|";
	buy_past_presentations += jobtitle.value;
	buy_past_presentations += "|";
	buy_past_presentations += companyname.value;
	buy_past_presentations += "|";
	buy_past_presentations += phoneno1.value;
	buy_past_presentations += "|";
	buy_past_presentations += phoneno2.value;
	buy_past_presentations += "|";
	buy_past_presentations += phoneno3.value;
	buy_past_presentations += "|";
	buy_past_presentations += phoneno4.value;
	buy_past_presentations += "|";
	buy_past_presentations += emailaddress.value;
	createCookie("buy_past_presentations", buy_past_presentations,30);
}

function contactme_checkCookie() {
	var contact_us = new Array("0","","","","","0","","","","","");
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var country = document.getElementById("country");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	
	if (readCookie("contact_us")!=null)
		contact_us = readCookie("contact_us").split("|");
	salutation.selectedIndex = contact_us[0];
	firstname.value = contact_us[1];
	familyname.value = contact_us[2];
	jobtitle.value = contact_us[3];
	companyname.value = contact_us[4];
	country.selectedIndex = contact_us[5];
	phoneno1.value = contact_us[6];
	phoneno2.value = contact_us[7];
	phoneno3.value = contact_us[8];
	phoneno4.value = contact_us[9];
	emailaddress.value = contact_us[10];
}

function contactme_saveCookie() {
	var salutation = document.getElementById("salutation");
	var firstname = document.getElementById("firstname");
	var familyname = document.getElementById("familyname");
	var jobtitle = document.getElementById("jobtitle");
	var companyname = document.getElementById("companyname");
	var country = document.getElementById("country");
	var phoneno1 = document.getElementById("phoneno1");
	var phoneno2 = document.getElementById("phoneno2");
	var phoneno3 = document.getElementById("phoneno3");
	var phoneno4 = document.getElementById("phoneno4");
	var emailaddress = document.getElementById("emailaddress");
	var contact_us = "";
	
	contact_us = salutation.selectedIndex;
	contact_us += "|";
	contact_us += firstname.value;
	contact_us += "|";
	contact_us += familyname.value;
	contact_us += "|";
	contact_us += jobtitle.value;
	contact_us += "|";
	contact_us += companyname.value;
	contact_us += "|";
	contact_us += country.selectedIndex;
	contact_us += "|";
	contact_us += phoneno1.value;
	contact_us += "|";
	contact_us += phoneno2.value;
	contact_us += "|";
	contact_us += phoneno3.value;
	contact_us += "|";
	contact_us += phoneno4.value;
	contact_us += "|";
	contact_us += emailaddress.value;
	createCookie("contact_us",contact_us,30);
}

function tellafriend_checkCookie() {
	var mother_tell_a_friend = new Array("","");
	var youname = document.getElementById("youname");
	var youemail = document.getElementById("youemail");
	
	if (readCookie("mother_tell_a_friend")!=null)
		mother_tell_a_friend = readCookie("mother_tell_a_friend").split("|");
	youname.value = mother_tell_a_friend[0];
	youemail.value = mother_tell_a_friend[1];
}

function tellafriend_saveCookie() {
	var youname = document.getElementById("youname");
	var youemail = document.getElementById("youemail");
	var mother_tell_a_friend = "";
	
	mother_tell_a_friend = youname.value;
	mother_tell_a_friend += "|";
	mother_tell_a_friend += youemail.value;
	createCookie("mother_tell_a_friend",mother_tell_a_friend,30);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
