//#####################################################################################################################################
//##################################################################################################################################### REGISTRATION FORM
//#####################################################################################################################################
function valid_final()
{

 // PRIVACY INFO
 var error_privacy ='';
 var error_privacy_info = false;
 document.getElementById('error_privacy').className = "";
 document.getElementById('error_privacy').innerHTML = "";
 
 if(document.getElementById('terms_ok').checked == false)
	{
	 error_privacy += "<b>- You must agree to <u>BlueCat's terms and conditions</u></b><br/>";
	 error_privacy_info = true;
	}

 if(!verif_empty(document.getElementById('captcha-form').value))
	{
	 error_privacy += '<b>- You must retype the <u>validation code</u></b><br/>';
	 error_privacy_info = true;
	 
	if(error_privacy_info == true)
		 {
		  document.getElementById('error_privacy').className = "error";
		  document.getElementById('error_privacy').innerHTML = error_privacy;
		  valid_registration2();
		  return false
		 } 
	else
		 {
		  document.getElementById('error_privacy').className = "valid";
		  document.getElementById('error_privacy').innerHTML = "<b>Valid Information</b>";
		  valid_registration3();
		  return true;
		 } 	 
	}
 else
	{
	 $.ajax(
		 {
		  url: 'external/image_valid/validate_image.php',
		  data: 
			{
			 entry_text: document.getElementById('captcha-form').value
			},
		  dataType: 'html',
		  success: function(data, textStatus) 
			{
			 if(data == "false")
				{
				 error_privacy += '<b>- Wrong <u>validation code</u></b><br/>'
				 error_privacy_info = true
				}

			 if(error_privacy_info == true)
				 {
				  document.getElementById('error_privacy').className = "error";
				  document.getElementById('error_privacy').innerHTML = error_privacy;
				  valid_registration2();
				  return false;
				 } 
			 else
				 {
				  document.getElementById('error_privacy').className = "valid";
				  document.getElementById('error_privacy').innerHTML = "<b>Valid Information</b>";
				  valid_registration3();
				  return true;
				 } 
			}
		  }	 
	 );
	}
}



//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################


function valid_registration2()
{
 var error = false
 var msg = "Error in : ";
 
 if(!valid_login())
	{
	 error = true;
	}
	
 if(!valid_contact())
	{
	 error = true;
	}
	
 alert("Error in the form, please check your info");
}



//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################



function valid_registration3()
{
 var error = false
 var msg = "Error in : ";
 
 if(!valid_login())
	{
	 msg += "Login info - "
	 error = true;
	}
	
 if(!valid_contact())
	{
	 msg += "Contact info - "
	 error = true;
	}
	
 if(error == true)
	{
	 alert("Error in the form, please check your info");
	 return false;
	}
	
 document.register_form.submit();
}



//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################



function valid_privacy()
{

 // PRIVACY INFO
 var error_privacy ='';
 var error_privacy_info = false;
 document.getElementById('error_privacy').className = "";
 document.getElementById('error_privacy').innerHTML = "";
 
 if(document.getElementById('terms_ok').checked == false)
	{
	 error_privacy += "<b>- You must agree to <u>BlueCat's terms and conditions</u></b><br/>";
	 error_privacy_info = true;
	}

 if(!verif_empty(document.getElementById('captcha-form').value))
	{
	 error_privacy += '<b>- You must retype the <u>validation code</u></b><br/>';
	 error_privacy_info = true;
	}
 else
	{
	 $.ajax(
		 {
		  url: 'external/image_valid/validate_image.php',
		  data: 
			{
			 entry_text: document.getElementById('captcha-form').value
			},
		  dataType: 'html',
		  success: function(data, textStatus) 
			{
			 if(data == "false")
				{
				 error_privacy += '<b>- Wrong <u>validation code</u></b><br/>'
				 error_privacy_info = true
				 
				 if(error_privacy_info == true)
					 {
					  document.getElementById('error_privacy').className = "error";
					  document.getElementById('error_privacy').innerHTML = error_privacy;
					  return false;
					 } 
				 else
					 {
					  document.getElementById('error_privacy').className = "valid";
					  document.getElementById('error_privacy').innerHTML = "<b>valid information</b>";
					  return true;
					 } 
				}
			}
		  }	 
	 );
	}
 if(error_privacy_info == true)
	 {
	  document.getElementById('error_privacy').className = "error";
	  document.getElementById('error_privacy').innerHTML = error_privacy;
	  return false
	 } 
 else
	 {
	  document.getElementById('error_privacy').className = "valid";
	  document.getElementById('error_privacy').innerHTML = "<b>valid information</b>";
	  return true;
	 } 
}



//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################



function valid_login()
{
 // LOGIN INFO
 var error_login ='';
 var error_login_info = false;
 document.getElementById('error_login').className = "";
 document.getElementById('error_login').innerHTML = "";
  
 //----------------------------------------------------------- EMAIL
 if(!verif_mail(document.getElementById('email').value))
	{
	 error_login += '<b>- Please provide a valid <u>business email address</u></b><br/>';
	 error_login_info = true;
	}
 else
	{
	 if(document.getElementById('email').value != document.getElementById('email2').value)
		{
		 error_login += '<b>- The <u>email address</u> entries do not match</b><br/>';
		 error_login_info = true;
		}
	}
 //----------------------------------------------------------- EMAIL
 //##################
 //##################
 //##################
 //----------------------------------------------------------- PASSWORD
 if(document.getElementById('pass').value.length < 8)
	{
	 error_login += '<b>- <u>Password</u> must contain 8 characters minimum</b><br/>';
	 error_login_info = true;
	}
 else
	{
	if(!verif_password(document.getElementById('pass').value))
		{
		 error_login += '<b>- <u>Password</u> must contain both upper - and lowercase alphanumeric characters (only a-z, A-Z, 0-9)</b><br/>';
		 error_login_info = true;
		}
	else
		{
		 if(document.getElementById('pass').value != document.getElementById('pass2').value)
			{
			 error_login += '<b>- The <u>password</u> entries do not match</b><br/>';
			 error_login_info = true;
			}
		}
	}
 //----------------------------------------------------------- PASSWORD
 
 if(error_login_info == true)
	 {
	  document.getElementById('error_login').className = "error";
	  document.getElementById('error_login').innerHTML = error_login;
	  return false
	 } 
 else
	 {
	  document.getElementById('error_login').className = "valid";
	  document.getElementById('error_login').innerHTML = "<b>valid information</b>";
	  return true;
	 } 
}




//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################



function valid_contact ()
{
 // BUSINESS INFO
 var error_contact ='';
 var error_contact_info = false;
 document.getElementById('error_contact').className = "";
 document.getElementById('error_contact').innerHTML = "";
 
 //----------------------------------------------------------- FIRST NAME 
 if(!verif_empty(document.getElementById('first').value))
	{
	 error_contact += '<b>- You must fill your <u>first name</u></b><br/>';
	 error_contact_info = true;
	}
 if(!verif_alpha(document.getElementById('first').value))
	{
	 error_contact += '<b>- Your <u>first name</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- FIRST NAME 
 //##################
 //##################
 //##################
 //----------------------------------------------------------- LAST NAME 
 if(!verif_empty(document.getElementById('last').value))
	{
	 error_contact += '<b>- You must fill your <u>last name</u></b><br/>';
	 error_contact_info = true;
	}
 if(!verif_alpha(document.getElementById('last').value))
	{
	 error_contact += '<b>- Your <u>last name</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- LAST NAME 
 //##################
 //##################
 //##################
 //----------------------------------------------------------- COMPANY 
 if(!verif_empty(document.getElementById('company').value))
	{
	 error_contact += '<b>- You must fill your <u>company name</u></b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- COMPANY
 //##################
 //##################
 //##################
 //----------------------------------------------------------- ADDRESS 
 if(!verif_empty(document.getElementById('address').value))
	{
	 error_contact += '<b>- You must fill your/company <u>address</u></b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- ADDRESS
 //##################
 //##################
 //##################
 //----------------------------------------------------------- CITY 
 if(!verif_empty(document.getElementById('city').value))
	{
	 error_contact += '<b>- You must fill your <u>city name</u></b><br/>';
	 error_contact_info = true;
	}
 if(!verif_alpha(document.getElementById('city').value))
	{
	 error_contact += '<b>- Your <u>city name</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- CITY 
 //##################
 //##################
 //##################
 //----------------------------------------------------------- COUNTRY
 if(document.getElementById('country').value == "none")
	{
	 error_contact += '<b>- Select a <u>country</u></b><br/>';
	 error_contact_info = true;
	}
 else
	{
	 if(document.getElementById('choice').value == "select")
		{
		 if(document.getElementById('stateList').value == "none")
			{
			 error_contact += '<b>- Select a <u>state/province</u></b><br/>';
			 error_contact_info = true;
			}
			
		}
	}
 
 //----------------------------------------------------------- COUNTRY

 
 if(error_contact_info == true)
	{
	 document.getElementById('error_contact').className = "error";
	 document.getElementById('error_contact').innerHTML = error_contact;
	 return false;
	}
 else
	 {
	  document.getElementById('error_contact').className = "valid";
	  document.getElementById('error_contact').innerHTML = "<b>valid information</b>";
	  return true;
	 } 
}


//#####################################################################################################################################
//##################################################################################################################################### CONTACT SUPPORT TEAM FORM
//#####################################################################################################################################

function valid_contact_support()
{
 var error = false;
 if(!valid_perso_info_support())
	{
	 error = true;
	}
 if(!valid_contacts_info_support())
	{
	 error = true;
	} 
 if(!valid_request_info_support())
	{
	 error = true;
	}
 
 if(error == true)
	{
	 alert("Error in the form, please check your info");
	 return false;
	}
 document.contact_support_form.submit();
}
//########################################## REQUEST INFORMATION
function valid_request_info_support()
{
 // PERSONNAL INFO
 var error_request ='';
 var error_request_info = false;
 document.getElementById('error_request').className = "";
 document.getElementById('error_request').innerHTML = "";	
 
//----------------------------------------------------------- REQUEST 
 if(!verif_empty(document.getElementById('request').value) || document.getElementById('request').value == "Type in your request...")
	{
	 error_request += '<b>- You must fill <u>the purpose of your request</u></b><br/>';
	 error_request_info = true;
	}
//----------------------------------------------------------- REQUEST 
 if(error_request_info == true)
	 {
	  document.getElementById('error_request').className = "error";
	  document.getElementById('error_request').innerHTML = error_request;
	  return false
	 } 
 else
	 {
	  document.getElementById('error_request').className = "valid";
	  document.getElementById('error_request').innerHTML = "<b>Valid Information</b>";
	  return true;
	 }  
}

//########################################## PERSONNAL INFORMATION
function valid_perso_info_support()
{
 // PERSONNAL INFO
 var error_perso ='';
 var error_perso_info = false;
 document.getElementById('error_perso').className = "";
 document.getElementById('error_perso').innerHTML = "";	
 
//----------------------------------------------------------- FIRST NAME 
 if(!verif_empty(document.getElementById('first').value))
	{
	 error_perso += '<b>- You must fill your <u>first name</u></b><br/>';
	 error_perso_info = true;
	}
 if(!verif_alpha(document.getElementById('first').value))
	{
	 error_perso += '<b>- Your <u>first name</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_perso_info = true;
	}
 //----------------------------------------------------------- FIRST NAME 
 //##################
 //##################
 //##################
 //----------------------------------------------------------- LAST NAME 
 if(!verif_empty(document.getElementById('last').value))
	{
	 error_perso += '<b>- You must fill your <u>last name</u></b><br/>';
	 error_perso_info = true;
	}
 if(!verif_alpha(document.getElementById('last').value))
	{
	 error_perso += '<b>- Your <u>last name</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_perso_info = true;
	}
 //----------------------------------------------------------- LAST NAME 
 //##################
 //##################
 //################## 
  //----------------------------------------------------------- JOB TITLE
 if(!verif_empty(document.getElementById('title').value))
	{
	 error_perso += '<b>- You must fill your <u>job title</u></b><br/>';
	 error_perso_info = true;
	}
 if(!verif_alpha(document.getElementById('title').value))
	{
	 error_perso += '<b>- Your <u>job title</u> must contain only alphanumeric characters a-z A-Z</b><br/>';
	 error_perso_info = true;
	}
 //----------------------------------------------------------- JOB TITLE
 //##################
 //##################
 //##################
 //----------------------------------------------------------- COMPANY 
 if(!verif_empty(document.getElementById('company').value))
	{
	 error_perso += '<b>- You must fill your <u>company name</u></b><br/>';
	 error_perso_info = true;
	}
 //----------------------------------------------------------- COMPANY
 
 if(error_perso_info == true)
	 {
	  document.getElementById('error_perso').className = "error";
	  document.getElementById('error_perso').innerHTML = error_perso;
	  return false
	 } 
 else
	 {
	  document.getElementById('error_perso').className = "valid";
	  document.getElementById('error_perso').innerHTML = "<b>Valid Information</b>";
	  return true;
	 }  
}

//########################################## CONTACTS INFORMATION
function valid_contacts_info_support()
{
 // CONTACTS INFO
 var error_contact ='';
 var error_contact_info = false;
 document.getElementById('error_contact').className = "";
 document.getElementById('error_contact').innerHTML = "";	
 
 //----------------------------------------------------------- EMAIL
 if(!verif_mail(document.getElementById('email').value))
	{
	 error_contact += '<b>- Please provide a valid <u>business email address</u></b><br/>';
	 error_contact_info = true;
	}
 //----------------------------------------------------------- EMAIL
 
 //----------------------------------------------------------- OTHER EMAIL
 if(verif_empty(document.getElementById('email2').value))
	{
	 if(!verif_mail_lite(document.getElementById('email2').value))
		{
		 error_contact += '<b>- Please provide a valid <u>alternate email address</u></b><br/>';
		 error_contact_info = true;
		}
	}
 //----------------------------------------------------------- OTHER EMAIL
 
//----------------------------------------------------------- PRIMARY PHONE
 if(!verif_empty(document.getElementById('phone').value))
	{
	 error_contact += '<b>- You must fill your <u>phone number</u></b><br/>';
	 error_contact_info = true;
	}
//----------------------------------------------------------- PRIMARY PHONE

 if(error_contact_info == true)
	 {
	  document.getElementById('error_contact').className = "error";
	  document.getElementById('error_contact').innerHTML = error_contact;
	  return false;
	 } 
 else
	 {
	  document.getElementById('error_contact').className = "valid";
	  document.getElementById('error_contact').innerHTML = "<b>Valid information</b>";
	  return true;
	 }  
}

//#####################################################################################################################################
//##################################################################################################################################### RESET PASSWORD
//#####################################################################################################################################

function valid_new_password()
{

 // PASSWORD INFO
 var error_password ='';
 var error_password_info = false;
 document.getElementById('error_password').className = "";
 document.getElementById('error_password').innerHTML = "";	

 //----------------------------------------------------------- PASSWORD
 if(document.getElementById('pass').value.length < 8)
	{
	 error_password += '<b>- <u>Password</u> must contain 8 characters minimum</b><br/>';
	 error_password_info = true;
	}
 else
	{
	if(!verif_password(document.getElementById('pass').value))
		{
		 error_password += '<b>- <u>Password</u> must contain both upper - and lowercase alphanumeric characters (only a-z, A-Z, 0-9)</b><br/>';
		 error_password_info = true;
		}
	else
		{
		 if(document.getElementById('pass').value != document.getElementById('pass2').value)
			{
			 error_password += '<b>- The <u>password</u> entries do not match</b><br/>';
			 error_password_info = true;
			}
		}
	}
 //----------------------------------------------------------- PASSWORD
 if(error_password_info == true)
	 {
	  document.getElementById('error_password').className = "error";
	  document.getElementById('error_password').innerHTML = error_password;
	  return false;
	 } 
 else
	 {
	  document.reset_password.submit();
	 }  
}

//#####################################################################################################################################
//##################################################################################################################################### GENERAL FUNCTIONS
//#####################################################################################################################################

function verif_empty(field)
{
 field = field.replace(/^\s*|\s*$/,"");
 if(field.length < 1)
	 return false;
 return true;
}




//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################




function verif_alpha(field)
{
 var reg = new RegExp(/[^A-Za-z -]+/);
 if (reg.test(field))
	 return false;
 return true;
}




//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################




function verif_password(field)
{
 var reg = new RegExp(/[^A-Za-z0-9]+/);
 if (reg.test(field))
	 return false;
 return true;
}




//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################


function verif_mail(email) 
{

 testm = false ;

 var at = 0;
 var dot = 0;
 
  for (var j=1 ; j<(email.length) ; j++) 
	{
	if (email.charAt(j)=='@') 
		{
		 at = j+1;
		 for (var k=j ; k<(email.length-2) ; k++) 
			{
			 if (email.charAt(k)=='.') 
				dot = k;
			}
		}
	}
	
 var tabmail = ["teampcs","yahoo", "hotmail","gmail","rediffmail","aol","163","mail","123mail","21cn","vsnl","mynet","msn","uol","126","terra","libero","sify","indiatimes","plasa","prodigy","gmx","streamyx","bigpond","hanmail","ig","cantv","comcast","rediff","sbcglobal","t-online","telkom","optusnet","tm","sancharnet","tiscali","tom","freemail","rogers","shaw","sina","arcor","mweb","seznam","singnet","sohu","sympatico","bol","earthlink","korea","lycos","online","virgilio","att","o2","runbox","touchtelindia","usa","walla","wanadoo","web.com","webmail","adelphia","btinternet","cbn","daum","qatar","argentina","blueyonder","europe","home.com","iol","isb","myjaring","pchome","poczta","yahoomail","bellsouth","bluewin","caramail","cogeco","comsats","coqui","eyou","india","info","iprimus","latinmail","maktoob","otenet","planet","pvfcco","telnor","bezeqint","cox","direcway","discoverymail","dreamwiz","engineer","fastmail","iinet","netscape","netspace","pandora","skynet","superonline","123","attglobal","cable.com","charter","etang","fastwebnet","free","frontiernet","gawab","globe","hccnet","inbox","incnets","inwind","juno","megared","ms6","neostrada","netpci","netvigator","netzero","ntlworld","ono","parsonline","peoplepc","pop","racsa","spymac","superig","superlink","tlen","verizon","videotron","vtown","woh","yandex","2156","54532","aanet","abcnet","adinet","adsl","ahoo","aim","aliceadsl","allstream","altavista","andinet","anet","aql","arnet","asr","bangkokmail","batelco","beotel","bigpind","bih","birch","biz","bloomer","bom3","cableone","carib-link","centennialpr","centrin","cg.com","chello","chinaren","cincinnatibell","comcel","consultent","crypthon","cura","cybercable","cybron","dailytechinfo","dataxprs","dcemail","debitel","doboj","dookie","e-xtra","eastlink","eiluae","eirindia","elnics","emcali","enel","etapaonline","eth","eunet","excite","ezaccess","fchb","freechal","freent","freeserve","frizz","fsnet","fulladsl","gers11","giascl01","giga","glay","gvii","hawaii","here","hinet","homail","homecall","hotamil","hotcom","hotmai","hotmal","hotmial","hotpop","hriders","htomail","ic24","iname","indatimes","indo","inet","infoweb","insightbb","interfree","intergate","iomind","isp","itelefonica","jarring","katamail","knology","kornet","lantic","latnet","lavalife","linuxmail","liwest","ljosland","loxinfo","mail15","mailcity","mailto","maktoop","malaysia","mantramail","menara","mindspring","ms1","ms14","ms51","myney","myway","naver","nc.com","net4u","netcabo","netcon","netian","netsolir","nickart","onlinehome","operamail","ozemail","paran","pekafrooz","pipeline","pobox","poctza","portugalmail","primus.ca","prtc","ptt","qld","queretaro","rdslink","redifmail","resa","reymoreno","rgu","rinsa","rr","sailormoon","sesz","sgatuae","sifymail","sndt","speedconnect","stonline","suite224","supaero","supereva","swissonline","talk21","tee","telcel","tele2","teleline","telia","telkomsa","telmex","telsur","telusplanet","thaimail","ttnet","tugamail","tuktuk","turkcell","tutopia","ultratv","unet","verat","vr-web","vsni","wandoo","westnet","winning","wtal","ya","yaahoo","yagoo","yahool","yahooo","yahoooo","yahopo","yaoo","yhaoo","yshoo","ystreamyx","ytu","zen.com","rocketmail","comcast","excite","netcom","earthlink"];

 for(var i=0; i<tabmail.length; ++i)
	{
	 if(email.substring(at, dot) == tabmail[i])
		{
		 return false;
		}
	}
  
 var reg = new RegExp("^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi");
 //Test if the first name contains numbers
 if (email.search( reg ) == -1)
	{
	 return false;
	} 
 
 for (var j=1 ; j<(email.length) ; j++) 
	{
	 if (email.charAt(j)=='@') 
		{
		 if (j<(email.length-4))
			{
			 for (var k=j ; k<(email.length-2) ; k++) 
				{
				 if (email.charAt(k)=='.') 
					testm = true;
				}
			}
		}
	}
 if (testm==false) 
	{
	 return false;
	}
return true;
}

function verif_mail_lite(email) 
{

 testm = false ;

 var at = 0;
 var dot = 0;
 
  for (var j=1 ; j<(email.length) ; j++) 
	{
	if (email.charAt(j)=='@') 
		{
		 at = j+1;
		 for (var k=j ; k<(email.length-2) ; k++) 
			{
			 if (email.charAt(k)=='.') 
				dot = k;
			}
		}
	}
	

 var reg = new RegExp("^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi");
 //Test if the first name contains numbers
 if (email.search( reg ) == -1)
	{
	 return false;
	} 
 
 for (var j=1 ; j<(email.length) ; j++) 
	{
	 if (email.charAt(j)=='@') 
		{
		 if (j<(email.length-4))
			{
			 for (var k=j ; k<(email.length-2) ; k++) 
				{
				 if (email.charAt(k)=='.') 
					testm = true;
				}
			}
		}
	}
 if (testm==false) 
	{
	 return false;
	}
return true;
}


//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################




function ESX_download() { 
	if (document.form1.agree.checked == false){
		alert ('Error');
		return false;
	} else { 	

	return true;
	}
}



function serverEVAL_download() { 
	if (document.form1.agree.checked == false){
		alert ('Error');
		return false;
	} else { 	
	 //window.open ("http://free-trial.s3.amazonaws.com/BlueCat_Virtual_Appliance_VMware_Server_Eval.zip","mywindow");

	return true;
	}
}







//#####################################################################################################################################
//#####################################################################################################################################
//#####################################################################################################################################

