//////////////////////////////////////////////
//		KoolPassion.com SingUp Page
//		Script File 01-07-2010
//////////////////////////////////////////////
  function OnCountryDDchange() {
    //document.getElementById("user_city").value = "";
    obj = document.getElementById("country");
    if (obj.value == "Pakistan") {
      document.getElementById("city1").style.display="";
      document.getElementById("city2").style.display="none";
    }
    else {
      document.getElementById("city1").style.display="none";
      document.getElementById("city2").style.display="";
    }
    /*OnUserTypeDDChange();*/
  }
/////////////////////////////////////////////////////////////////////////////////////////////////
//// UserName Check
function GetXmlHttpObject()
{
	
	var xmlHttp=null;
	try
	{
	 // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
 }
return xmlHttp;
}

// Check user availability

	function CheckAvail()
	{
	var rand_no = Math.ceil(1000*Math.random())
		xmlHttp=GetXmlHttpObject()
		// if browser not found
		if (xmlHttp==null)
		{
			 alert ("Browser does not support HTTP Request")
			 return
		 }
	document.getElementById("divAvail").style.display='block';
		 // Server Url
		var url="include/userchk.php"
		// Query string variable 
		url=url+"?username="+document.getElementById("username").value+"&show="+rand_no;//+"&fname="+document.getElementById("txtFirstName").value+"&lname="+document.getElementById("txtLastName").value;
		// Call back function for check response state.
		xmlHttp.onreadystatechange=usernamechk 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		
	}
	function usernamechk() 
	{ 
		document.getElementById("divAvail").innerHTML="<img src=images/loading.gif />";
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			// Assign server reponse to div.
			 document.getElementById("divAvail").innerHTML=xmlHttp.responseText 
		 } 
	}
//////////////////////////////////////////////////////////////////////////////////////
//// Password Strength
function passwordStrength(password)
{
	document.getElementById("passCheck").style.display='block';
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	 document.getElementById("passwordDescription").innerHTML = desc[score];
	 document.getElementById("passwordStrength").className = "strength" + score;
}
//////////////////////////////////////////////////////////////////////////////////////
//// Form Check
function checkform(){
	var error =0;
	var name ="";
	var username ="";
	var pass ="";
	var email="";
	var gender="";
	var city="";
	var contact ="";
	var agree="";
	var vercode="";
	
	if (document.joinNow.name.value=="") {
			document.joinNow.name.style.background='#FF0000';
			name = "<li>Enter Your Name !</li>";
			error =1;			
	}else{
		document.joinNow.name.style.background='#FFF';
	}
	if (document.joinNow.user.value=="") {
			document.joinNow.user.style.background='#FF0000';
			username = "<li>Enter User Name !</li>";
			error =1;			
	}else if((document.joinNow.user.value.length < 5) || (document.joinNow.user.value.length > 16)) {
			document.joinNow.user.style.background='#FF0000';
			username = "<li>InValid User Name !</li>";
			error =1;	
	}else{
		document.joinNow.user.style.background='#FFF';
	}
	
	if (document.joinNow.pass.value.length < 5) {
			document.joinNow.pass.style.background='#FF0000';
			pass = "<li>Enter Password !</li>";
			error =1;			
	}else if(document.joinNow.pass.value!=document.joinNow.repass.value){
		document.joinNow.pass.style.background='#FF0000';
		document.joinNow.repass.style.background='#FF0000';
		pass = "<li>Password Not Match!</li>";
		error =1;			
	}else{
		document.joinNow.pass.style.background='#FFF';
		document.joinNow.repass.style.background='#FFF';
	}
	var emailchk = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!emailchk.test(document.joinNow.email.value)) {
			document.joinNow.email.style.background='#FF0000';
			email = "<li>Please provide a valid email address!</li>";
			error =1;			
	}else{
		document.joinNow.email.style.background='#FFF';
	}
	if ( ( joinNow.gender[0].checked == false ) && ( joinNow.gender[1].checked == false ) ) {
	//alert ( "Please choose your Gender: Male or Female" ); return false; 
			document.joinNow.gender[0].style.background='#FF0000';
			document.joinNow.gender[1].style.background='#FF0000';
			gender = "<li>Please Choose Your Gender Male /  Female !</li>";
			error =1;			
	}else{
		document.joinNow.gender[0].style.background='#FFF';
		document.joinNow.gender[1].style.background='#FFF';
	}
		
	
	if (document.joinNow.country.value=="Pakistan") {
			if (document.getElementById("city1").value=="") {		
				document.getElementById("city1").style.background='#FF0000';
				city = "<li>Select City!</li>";
				error =1;			
			}else{
				document.getElementById("city1").style.background='#FFF';
			}			
	}else{
		if (document.getElementById("city2").value=="") {		
				document.getElementById("city2").style.background='#FF0000';
				city = "<li>Enter City!</li>";
				error =1;			
			}else{
				document.getElementById("city2").style.background='#FFF';
			}
	}

	if (document.joinNow.contact.value.length < 7) {
			document.joinNow.contact.style.background='#FF0000';
			contact = "<li>Enter Contact No. !</li>";
			error =1;			
	}else{
		document.joinNow.contact.style.background='#FFF';
	}

	if ( joinNow.agree.checked == false ) {
		document.joinNow.agree.style.background='#FF0000';
		agree = "<li>Please check the Terms & Conditions box.</li>";
	}else{
		document.joinNow.agree.style.background='#FFF';
	}
	if ((document.joinNow.vercode.value.length < 6) || (document.joinNow.vercode.value.length > 6)) {
			document.joinNow.vercode.style.background='#FF0000';
			vercode = "<li>Enter Security Code !</li>";
			error =1;			
	}else{
		document.joinNow.vercode.style.background='#FFF';
	}

if(error==1){
	document.getElementById("ErrorBox").style.display='block';
	document.getElementById("ErrorBox").focus();
	document.getElementById("ErrorBox").innerHTML="<div id=\"system-message\"><dd class=\"error\"><ul>" + name + username + pass + email + gender + city + contact + agree + vercode +"</ul></dd></div>";

	return false;
	}

return true;	
}
//////////////////////////////////////////////////////////////////////////////////////
//// Form Password Recovery
function passrecform(){
	var error=0;
	var email="";
	var vercode="";
	var emailchk = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!emailchk.test(document.PassGet.email.value)) {
			document.PassGet.email.style.background='#FF0000';
			email = "<li>Please provide a valid email address!</li>";
			error =1;			
	}else{
		document.PassGet.email.style.background='#FFF';
	}
	
	if ((document.PassGet.vercode.value.length < 6) || (document.PassGet.vercode.value.length > 6)) {
			document.PassGet.vercode.style.background='#FF0000';
			vercode = "<li>Enter Security Code !</li>";
			error =1;			
	}else{
		document.PassGet.vercode.style.background='#FFF';
	}
if(error==1){
	document.getElementById("ErrorBox").style.display='block';
	document.getElementById("ErrorBox").focus();
	document.getElementById("ErrorBox").innerHTML="<div id=\"system-message\"><dd class=\"error\"><ul>" + email + vercode +"</ul></dd></div>";

	return false;
	}

return true;	
}
//////////////////////////////////////////////////////////////////////////////////////
//// Form Contact Us
function Contactform(){
	var error=0;
	var name = "";
	var email="";
	var msg="";
	var vercode="";
	var subject="";
	var contact="";
	
	
	if (document.contact.name.value.length < 6){
			document.contact.name.style.background='#FF0000';
			name = "<li>Enter Your Name !</li>";
			error =1;			
	}else{
		document.contact.name.style.background='#FFF';
	}
	
	
	
	var emailchk = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!emailchk.test(document.contact.email.value)) {
			document.contact.email.style.background='#FF0000';
			email = "<li>Please provide a valid email address!</li>";
			error =1;			
	}else{
		document.contact.email.style.background='#FFF';
	}
	
	if ((document.contact.vercode.value.length < 6) || (document.contact.vercode.value.length > 6)) {
			document.contact.vercode.style.background='#FF0000';
			vercode = "<li>Enter Security Code !</li>";
			error =1;			
	}else{
		document.contact.vercode.style.background='#FFF';
	}
	if (document.contact.subject.value==""){
			document.contact.subject.style.background='#FF0000';
			msg = "<li>Select Subject !</li>";
			error =1;			
	}else{
		document.contact.subject.style.background='#FFF';
	}
	if (document.contact.contact.value.length < 6){
			document.contact.contact.style.background='#FF0000';
			contact = "<li>Enter Your Contact No. !</li>";
			error =1;			
	}else{
		document.contact.contact.style.background='#FFF';
	}
	
	if (document.contact.message.value.length < 6){
			document.contact.message.style.background='#FF0000';
			msg = "<li>Enter Your Meassage !</li>";
			error =1;			
	}else{
		document.contact.message.style.background='#FFF';
	}
if(error==1){
	document.getElementById("ErrorBox").style.display='block';
	document.getElementById("ErrorBox").focus();
	document.getElementById("ErrorBox").innerHTML="<div id=\"system-message\"><dd class=\"error\"><ul>"+ name + email + contact +subject + msg +vercode +"</ul></dd></div>";

	return false;
	}

return true;	
}

