// JavaScript Document
function makeObject()
{
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
	x = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
	x = new XMLHttpRequest();
	}
	return x;
}

//call the function makeObject()
var request = makeObject();
function show_error(str,div_id){ 
	document.getElementById(div_id).style.display = "block";
	document.getElementById(div_id).innerHTML = str;
}
function hide_error(div_id){ 

			 document.getElementById(div_id).style.display = "none";
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function Register_Check()
	{		
		
		var ReturnValue 	= true;	
		
		if(document.registration_form.firstName.value==''){
			show_error('<font class="error">First Name is empty!</font>','Error_firstName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_firstName');	
		}
		
		if(document.registration_form.lastName.value==''){
			show_error('<font class="error">Last Name is empty!</font>','Error_lastName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_lastName');	
		}

		if(document.registration_form.email.value==''){
			show_error('<font class="error">Email Address is empty!</font>','Error_remail');
			ReturnValue		= false; 			
		}else if (echeck(document.registration_form.email.value)==false) {
			show_error("<font color='red'>Invalid Email Address.</font>",'Error_remail');		     	
			ReturnValue		= false; 			
		}else{
			hide_error('Error_remail');	
		}
		
		if( ( document.registration_form.year.value=='' )||( document.registration_form.month.value=='' )||( document.registration_form.day.value=='' ) ){
			show_error('<font class="error">Please select correct DOB!</font>','Error_dob');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_dob');	
		}

		if(document.registration_form.country.value==''){
			show_error('<font class="error">Please Select Your Country!</font>','Error_Country');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_Country');	
		}
		
		if(document.registration_form.zip.value==''){
			show_error('<font class="error">Zip Code is Empty!</font>','Error_zip');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_zip');	
		}
		
		if(document.registration_form.username.value==''){
			show_error('<font class="error">Username is Empty!</font>','Error_rlogin');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_rlogin');	
		}
		
		if(document.registration_form.password1.value==''){
			show_error('<font class="error">Password is empty!</font>','CheckPassMsg');
			ReturnValue		= false; 			
		}else if( document.registration_form.password1.value.length < 4 ){
			show_error("<font class='error'>Passwords should be minimum of 4 characters</font>",'CheckPassMsg');
            ReturnValue=false;	
		}else{
			hide_error('CheckPassMsg');	
		}

		if((document.registration_form.password2.value!=document.registration_form.password1.value)&&(document.registration_form.password1.value!='')){
			show_error('<font class="error">Confirm Your Password.</font>','CheckPassConfMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckPassConfMsg');	
		}
		return ReturnValue;
		//return false;
	}

function Register_Check_Edit()
	{		
		
		var ReturnValue 	= true;	
		
		if(document.registration_form.firstName.value==''){
			show_error('<font class="error">First Name is empty!</font>','Error_firstName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_firstName');	
		}
		
		if(document.registration_form.lastName.value==''){
			show_error('<font class="error">Last Name is empty!</font>','Error_lastName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_lastName');	
		}

		if(document.registration_form.email.value==''){
			show_error('<font class="error">Email Address is empty!</font>','Error_remail');
			ReturnValue		= false; 			
		}else if (echeck(document.registration_form.email.value)==false) {
			show_error("<font color='red'>Invalid Email Address.</font>",'Error_remail');		     	
			ReturnValue		= false; 			
		}else{
			hide_error('Error_remail');	
		}
		
		if( ( document.registration_form.year.value=='' )||( document.registration_form.month.value=='' )||( document.registration_form.day.value=='' ) ){
			show_error('<font class="error">Please select correct DOB!</font>','Error_dob');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_dob');	
		}

		if(document.registration_form.country.value==''){
			show_error('<font class="error">Please Select Your Country!</font>','Error_Country');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_Country');	
		}
		
		if(document.registration_form.zip.value==''){
			show_error('<font class="error">Zip Code is Empty!</font>','Error_zip');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_zip');	
		}		
		
		if(document.registration_form.password1.value!=''){
			if( document.registration_form.password1.value.length < 4 ){
				show_error("<font class='error'>Passwords should be minimum of 4 characters</font>",'CheckPassMsg');
				ReturnValue=false;	
			}else{
				hide_error('CheckPassMsg');	
			}
	
			if((document.registration_form.password2.value!=document.registration_form.password1.value)&&(document.registration_form.password1.value!='')){
				show_error('<font class="error">Confirm Your Password.</font>','CheckPassConfMsg');
				ReturnValue		= false; 			
			}else{
				hide_error('CheckPassConfMsg');	
			}
		}
		return ReturnValue;
		//return false;

	}

function Register_Verification()
	{		
		
		var ReturnValue 	= true;	
		
		if(document.registration_form.firstName.value==''){
			show_error('<font class="error">First Name is empty!</font>','Error_firstName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_firstName');	
		}
		
		if(document.registration_form.lastName.value==''){
			show_error('<font class="error">Last Name is empty!</font>','Error_lastName');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_lastName');	
		}

		if(document.registration_form.email.value==''){
			show_error('<font class="error">Email Address is empty!</font>','Error_remail');
			ReturnValue		= false; 			
		}else if (echeck(document.registration_form.email.value)==false) {
			show_error("<font color='red'>Invalid Email Address.</font>",'Error_remail');		     	
			ReturnValue		= false; 			
		}else{
			hide_error('Error_remail');	
		}
		
		if( ( document.registration_form.year.value=='' )||( document.registration_form.month.value=='' )||( document.registration_form.day.value=='' ) ){
			show_error('<font class="error">Please select correct DOB!</font>','Error_dob');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_dob');	
		}

		if(document.registration_form.country.value==''){
			show_error('<font class="error">Please Select Your Country!</font>','Error_Country');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_Country');	
		}
		
		if(document.registration_form.zip.value==''){
			show_error('<font class="error">Zip Code is Empty!</font>','Error_zip');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_zip');	
		}
		
		if(document.registration_form.username.value==''){
			show_error('<font class="error">Username is Empty!</font>','Error_rlogin');
			ReturnValue		= false; 			
		}else{
			hide_error('Error_rlogin');	
		}
		
		if(document.registration_form.password1.value==''){
			show_error('<font class="error">Password is empty!</font>','CheckPassMsg');
			ReturnValue		= false; 			
		}else if( document.registration_form.password1.value.length < 4 ){
			show_error("<font class='error'>Passwords should be minimum of 4 characters</font>",'CheckPassMsg');
            ReturnValue=false;	
		}else{
			hide_error('CheckPassMsg');	
		}

		if((document.registration_form.password2.value!=document.registration_form.password1.value)&&(document.registration_form.password1.value!='')){
			show_error('<font class="error">Confirm Your Password.</font>','CheckPassConfMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckPassConfMsg');	
		}
		
		
		if( ReturnValue ){
				$('SignUp').hide();
//				$('OtherSites').show();
//				document.registration_form.ButtonSubmit.disabled = false;
				document.registration_form.submit();
		}
		
	}
function CheckAvailEmail(url){
		if(document.registration_form.email.value==''){
			show_error('<font color="red">Enter Email Address to see the Availability!</font>','CheckEmailMsg');
		}else if (echeck(document.registration_form.email.value)==false) {
			show_error("<font color='red'>Invalid email address.</font>",'CheckEmailMsg');		     	
		}else{
				hide_error('ExecuteErrorEmail');
				hide_error('CheckEmailMsg');
				document.getElementById('CheckEmail').style.display = "block";
				request.open('POST', url);	
				request.onreadystatechange = function () {
				if (request.readyState == 4) {
						responsestring = request.responseText;						
						var msg = responsestring.split("=");
					if (msg[1] == 'sorry') {
							document.getElementById('CheckEmail').style.display = "none";
							show_error('<font color="red">We\'re sorry it\'s already taken.</font>','CheckEmailMsg');
							
					}else {				
							document.getElementById('CheckEmail').style.display = "none";
							show_error('<font color="blue">Available.</font>','CheckEmailMsg');
					}		
		
				}	
			}		
			request.send('');
		}
}
function CheckAvailUsername(url){
		if(document.registration_form.username.value==''){
			show_error('<font color="red">Enter Username to see the Availability!</font>','CheckUserMsg');
		}else{
				hide_error('ExecuteErrorUser');
				hide_error('CheckUserMsg');
				document.getElementById('CheckUser').style.display = "block";
				request.open('POST', url);	
				request.onreadystatechange = function () {
				if (request.readyState == 4) {
						responsestring = request.responseText;
						var msg = responsestring.split("=");
					if (msg[1] == 'sorry') {
							document.getElementById('CheckUser').style.display = "none";
							show_error('<font color="red">We\'re sorry it\'s already taken.</font>','CheckUserMsg');
							
					}else {				
							document.getElementById('CheckUser').style.display = "none";
							show_error('<font color="blue">Available.</font>','CheckUserMsg');
					}		
		
				}	
			}		
			request.send('');
		}
}