// JavaScript Document
// Terms and Condition
function termsandcondition()
{
	window.open ("termscondition.php","mywindow",
    "location=0,status=0,scrollbars=1,resizable=1,width=600,height=710");
}

function copy_billing_to_shipping()
{
if (document.register.copy_bill_to_shipping.checked==true)
{
document.register.shipping_firstname.value = document.register.billing_firstname.value;
document.register.shipping_lastname.value = document.register.billing_lastname.value;
document.register.shipping_address.value = document.register.billing_address.value;
document.register.shipping_city.value = document.register.billing_city.value;
document.register.shipping_state.value = document.register.billing_state.value;
//document.register.shipping_country.value = document.register.billing_country.value;
document.register.shipping_pincode.value = document.register.billing_pincode.value;
document.register.ship_phno.value = document.register.bill_phno.value;
}
if (document.register.copy_bill_to_shipping.checked==false)
{
document.register.shipping_firstname.value = "";
document.register.shipping_lastname.value = "";
document.register.shipping_address.value = "";
document.register.shipping_city.value = "";
document.register.shipping_state.value = "";
//document.register.shipping_country.value = "";
document.register.ship_phno.value = "";

}
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
  } 
  
function form_validation()
{
 
 if(document.register.txtfname.value=="")
  {
	 alert('Enter First Name');
	 document.register.txtfname.focus();
	 return false; 
  }
  if(document.register.txtlname.value=="")
  {
	 alert('Enter Last Name');
	 document.register.txtlname.focus();
	 return false; 
  }
  if(document.register.txtemail.value == "")
  {
    alert('Enter Email-Id');
	document.register.txtemail.focus();
	return false;
  }
  
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.register.txtemail.value;
   if(reg.test(address) == false) 
   {
      alert('Enter valid Email-Id');
	  document.register.txtemail.focus();
      return false;
   }
  if(document.register.txtpwd.value == "")
  {
    alert('Enter Password');
	document.register.txtpwd.focus();
	return false;
  }
  
  var len = document.register.txtpwd.value;
  if(len.length<6)
  {
    alert('Password length should be grater then 6 charecter');
	document.register.txtpwd.focus();
	return false;
  }
  
  // Confirm password validation
   if(document.register.txtconpass.value == "")
  {
    alert('Enter Confirm Password');
	document.register.txtconpass.focus();
	return false;
  }
  
  var password = document.register.txtpwd.value;
  var confpassword = document.register.txtconpass.value;
  if(password != confpassword)
  {
    alert('Passwords are not matching');
	return false;
  }
   if(document.register.word.value == "")
  {
    alert('Enter the characters you see in picture');
	document.register.word.focus();
	return false;
  }

  if(document.register.check_terms_conditon.checked == false)
  {
    alert('Please, read and accept the terms and conditions.');
	document.register.check_terms_conditon.focus();
	return false;
  }
  
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhoneNo(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
 
	function ChangePassword()
	{
		var frm;
		frm = document.change_pass;
		
		if(frm.oldpass.value == "")
		{	
			alert("Enter the Old Password");
			frm.oldpass.focus();
			return false;
		}
		if(frm.password.value == "")
		{	
			alert("Enter New Password");
			frm.password.focus();
			return false;
		}
		if(frm.confpassword.value == "")
		{	
			alert("Enter the Confirm Password");
			frm.confpassword.focus();
			return false;
		}
		if(frm.password.value != frm.confpassword.value)
		{	
			alert("Passwords are not matching");
			frm.confpassword.focus();
			return false;
		}
	}

function IsNewId(str)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  }
	var url="pagecontrols/check_unique_email.php";
	url=url+"?id="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged2;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged2()
{
if (xmlhttp.readyState==4)
  {
	 if(xmlhttp.responseText != "")
	 {
		 alert(xmlhttp.responseText);
		 document.register.txtemail.focus();
		 return false;
	 }
 	 //document.getElementById("txtErr").innerHTML=xmlhttp.responseText;
  }
}


function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
		  // code for IE6, IE5
		  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

function BillingValidate()
{
	 
  if(document.register.billing_firstname.value == "")
  {
    alert('Enter First Name in billing');
	document.register.billing_firstname.focus();
	return false;
  }
  
  if(document.register.billing_lastname.value == "")
  {
    alert('Enter Last Name in billing');
	document.register.billing_lastname.focus();
	return false;
  }
  
  if(document.register.billing_address.value == "")
  {
    alert('Enter Address in billing');
	document.register.billing_address.focus();
	return false;
  }
  
  if(document.register.billing_city.value =="")
  {
    alert('Enter City in billing');
	document.register.billing_city.focus();
	return false;
  }
  
  if(document.register.billing_state.value == "")
  {
    alert('Enter State in billing');
	document.register.billing_state.focus();
	return false;
  }
  
  if(document.register.billing_country.value =="")
  {
    alert('Enter Country in billing');
	document.register.billing_country.focus();
	return false;
  }
  
  if(document.register.billing_pincode.value =="")
  {
    alert('Enter Pincode in billing');
	document.register.billing_pincode.focus();
	return false;
  }
  if(document.register.bill_phno.value =="")
  {
    alert('Enter Telephone No in billing');
	document.register.bill_phno.focus();
	return false;
  }
  if(isNaN(document.register.bill_phno.value)==true)
  {
    alert('Enter numeric value for Telephone No');
	document.register.bill_phno.focus();
	return false;
  }
   if(isNaN(document.register.billing_pincode.value)==true)
  {
    alert('Enter numeric value for Pin Code');
	document.register.billing_pincode.focus();
	return false;
  }
  
  // Shipping Information Validation
  
   if(document.register.shipping_firstname.value == "")
  {
    alert('Enter First Name in shipping');
	document.register.shipping_firstname.focus();
	return false;
  }
  
  if(document.register.shipping_lastname.value == "")
  {
    alert('Enter Last Name in shipping');
	document.register.shipping_lastname.focus();
	return false;
  }
  
  if(document.register.shipping_address.value == "")
  {
    alert('Enter Address in shipping');
	document.register.shipping_address.focus();
	return false;
  }
  
  if(document.register.shipping_city.value =="")
  {
    alert('Enter City in shipping');
	document.register.shipping_city.focus();
	return false;
  }
  
  if(document.register.shipping_state.value == "")
  {
    alert('Enter State in shipping');
	document.register.shipping_state.focus();
	return false;
  }
  
  if(document.register.shipping_country.value =="0")
  {
    alert('Select Country in shipping');
	document.register.shipping_country.focus();
	return false;
  }
  
 /* if(document.register.shipping_country.value !="India" || document.register.shipping_country.value !="india" || document.register.shipping_country.value !="INDIA")
  {
    alert('Sorry, currently items are shipped only within India.');
	document.register.shipping_country.focus();
	return false;
  }*/
  
  if(document.register.shipping_pincode.value =="")
  {
    alert('Enter Pincode in shipping');
	document.register.shipping_pincode.focus();
	return false;
  }
  if(document.register.ship_phno.value =="")
  {
    alert('Enter Telephone No in shipping');
	document.register.ship_phno.focus();
	return false;
  }
  if(isNaN(document.register.ship_phno.value)==true)
  {
    alert('Enter numeric value for Telephone No');
	document.register.ship_phno.focus();
	return false;
  }
  if(isNaN(document.register.shipping_pincode.value)==true)
  {
    alert('Enter numeric value for Pin Code');
	document.register.shipping_pincode.focus();
	return false;
  }	
}
