/*email check function*/
//------------------Email checking functions---------------------------
function emailcheck(str) 
{
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
//alert("The eMail address '@' convention appears to be invalid.")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
//alert("The eMail address 'dot' convention appears to be invalid.")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
//alert("The eMail address '@' convention appears to be invalid.")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
//alert("The eMail address 'dot' convention appears to be invalid.")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
//alert("The eMail address 'dot' convention appears to be invalid.")
return false
}
if (str.indexOf(" ")!=-1){
//alert("The eMail address spacing convention appears to be invalid.")
return false
}

return true 
}
//----------End of email checking funcition-------------
//------------------User existing check through -AJAX- --------------------------
function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function check_user() {
	//alert();
	var  user_name=document.joinform1.username.value;
	//document.getElementById('username_info2').style.display='none';
	//document.getElementById('username_info1').style.display='none';
	if(emailcheck(document.joinform1.username.value)==false &&  user_name!="")
		{
			alert("please specify valid email id");
			document.joinform1.username.focus();
			document.joinform1.username.value='';
			//document.getElementById('username_info2').style.display='block';
			//document.getElementById('username_info1').style.display='none';
			return false
		}
		else
		{
     var req = Inint_AJAX();
	req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
				 //alert(req.responseText);
				 	if(req.responseText=="This ID already exists in our database")
					{
						document.joinform1.username.value='';	
					}
                    document.getElementById('disp').innerHTML=req.responseText; //retuen value
               } 
          }
     };
     req.open("GET", "usercheck.php?user_name="+user_name,true); //make connection
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req.send(null); //send value
	}
}
//---------------------------Change country flag---------------------------------
function chang_countryflag(countrySelect)
{
	
	var currentop = countrySelect.options[countrySelect.selectedIndex]
      countryNum    =  currentop.getAttribute('countryNum');
      countryValue  =  currentop.value;
	 countryNum  =  currentop.getAttribute('countrynum');//alert(countryNum)
	var req = Inint_AJAX();
	req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById('show_flag').innerHTML=req.responseText; //retuen value
					document.getElementById('phoneCountry').value=countryNum;//phoneCountry
               } 
          }
     };
     req.open("GET", "usercheck.php?country_id="+countryValue,true); //make connection
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req.send(null); //send value
}
//------------------------------End of flag change------------------------------
function validate()
{
		if(document.joinform1.username.value=="")
		{ 
			//document.getElementById('username_info1').style.display='block';
			alert("Email missing");
			document.joinform1.username.focus();
			return false;
		}
		if(emailcheck(document.joinform1.username.value)==false)
		{
			alert("Please valid Email id");
			document.joinform1.username.value='';
			document.joinform1.username.focus();
			return false
		}
		
		if(document.joinform1.password.value=="")
		{ 
			alert("password missing");
			document.joinform1.password.focus();
			return false;
		}
		if(document.joinform1.cpassword.value=="")
		{ 
			alert("confirm password missing");
			document.joinform1.cpassword.focus();
			return false;
		}
		//alert(document.joinform1.password.value.length);
		if(document.joinform1.password.value.length < 6)
		{
			//document.getElementById('password_info2').style.display='block';
			alert("Password minimum 6 char");
			document.joinform1.password.focus();
			return false;
		}
		if(document.joinform1.cpassword.value!=document.joinform1.password.value)
		{ 
			alert("password mismatch");
			document.joinform1.cpassword.select();
			document.joinform1.password.select();
			return false;
		}
		if(document.joinform1.country.value=='')
		{
			//document.getElementById('password_info2').style.display='block';
			alert("Please select country");
			document.joinform1.country.focus();
			return false;
		}
		if(document.getElementById("state").value==0)
		{
			//document.getElementById('password_info2').style.display='block';
			alert("Please select state");
			document.getElementById("state").focus();
			return false;
		}
		if(document.getElementById("city").value==0)
		{
			//document.getElementById('password_info2').style.display='block';
			alert("Please select city");
			document.getElementById("city").focus();
			return false;
		}
		if(document.joinform1.mobno1.value =='')
		{ 
			alert("Please fill the code for mobile no.");
			document.joinform1.mobno1.focus();
			return false;
		}
		if(isNaN(document.joinform1.mobno1.value))
		{ 
			alert("Numeric number only");
			document.joinform1.mobno1.value='';
			document.joinform1.mobno1.focus();
			return false;
		}
		if(document.joinform1.mobno.value =='')
		{ 
			alert("Please fill the mobile no.");
			document.joinform1.mobno.focus();
			return false;
		}
		if(isNaN(document.joinform1.mobno.value))
		{ 
			alert("Numeric number only");
			document.joinform1.mobno.value='';
			document.joinform1.mobno.focus();
			return false;
		}
		if(document.joinform1.mobno.value != '')
		{
			if(document.joinform1.mobno.value.length != 10)
			{ 
				alert("Please enter valid no");
				document.joinform1.mobno.value='';
				document.joinform1.mobno.focus();
				return false;
			}
		}
		if(document.joinform1.phno1.value=='')
		{ 
				alert("Please fill the code for no.");
				document.joinform1.phno1.focus();
				return false;
		}
		if(document.joinform1.phno1.value!='')
		{
			if(isNaN(document.joinform1.phno1.value))
			{ 
				alert("Numeric number only");
				document.joinform1.phno1.value='';
				document.joinform1.phno1.focus();
				return false;
			}
		}
		if(document.joinform1.phno2.value=='')
			{ 
				alert("Plese fill the code for phone");
				document.joinform1.phno2.focus();
				return false;
			}
		if(document.joinform1.phno2.value !='')
		{
			if(isNaN(document.joinform1.phno2.value))
			{ 
				alert("Numeric number only");
				document.joinform1.phno2.value='';
				document.joinform1.phno2.focus();
				return false;
			}
		}
		if(document.joinform1.phno.value=='')
		{ 
				alert("Please fill the phone no");
				document.joinform1.phno.focus();
				return false;
		}
		if(document.joinform1.phno.value !='')
		{
			if(isNaN(document.joinform1.phno.value))
			{ 
				alert("Numeric number only");
				document.joinform1.phno.value='';
				document.joinform1.phno.focus();
				return false;
			}
		}
	/*	if(document.joinform1.code.value=="")
		{ 
			alert("Code missing");
			document.joinform1.code.focus();
			return false;
		}
		if(document.joinform1.CHKBOX_1.checked == false )
		{
			alert(" Please Read 'Terms And Conditions' and select 'I Agree to dollarpaisa.com' ");
			return false;
		}*/
	return true;
}
