function ValidateForm(form)
{
	var x = form.elements;
	for (var i=0;i<x.length;i++)
	{
		EleObj=x[i].id;
		LastIndex = EleObj.substring(EleObj.length-2,EleObj.length)
		switch(LastIndex)
		{
			case "_R":
				if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
			break;
			case "_E":
				if(ValidateForm_Email(x[i],x[i].title)==false)
					return false;
			break;
			case "_I":
			if(document.getElementById('country').value=="USA")
			{
			 	var regEx = /[0-9]{5}/;
				if(regEx.test(document.getElementById('pincode_I').value))
			    {
			   	}
			    else
			    {
			    alert('Invalid US Zip Code');
			    document.getElementById('pincode_I').focus();
			    return false;
			    }
	
			}
			else
			{
			if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;	
			}
			break;
			case "_L":
			if(document.getElementById('scountry').value=="USA")
			{
			 	var regEx = /[0-9]{5}/;
				if(regEx.test(document.getElementById('spincode_L').value))
			    {
			   	}
			    else
			    {
			    alert('Invalid US Zip Code');
			    document.getElementById('spincode_L').focus();
			    return false;
			    }
	
			}
			else
			{
			if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;	
			}
			
			break;
			case "_N":
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;
			break;
		}		
	}
return true;
}

function ValidateForm_Required(Ctrl,msg)
{
	if(trimString(Ctrl.value) == "")
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function ValidateForm_Checked(Ctrl,msg)
{
	if(Ctrl.checked == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function ValidateForm_Numeric(Ctrl,valid_chars,msg)
{
	if(chkNumericValidate(Ctrl.value,valid_chars) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function chkNumericValidate(strString,strValidChars)
{
   var strChar;
   var blnResult = true; 
   	for (i = 0; i < strString.length && blnResult == true; i++)
   {
	  strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
    	   blnResult = false;
      }
   }
   return blnResult;
}
function ValidateForm_Email(Ctrl,msg)
{
	if(chkEmailValidate(Ctrl.value) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}

function ValidateForm_Confirm(Ctrl1,Ctrl2,msg)
{
	if(Ctrl1.value != Ctrl2.value)
	{
		alert(msg);
		Ctrl2.focus();
		return false;
	}
	return true;
}

function chkEmailValidate(str)
{
	return(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str));
}
function trimString (str)
{
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function AddressSame(Obj)
{
	if(Obj.checked==true)
	{
		document.getElementById('sfname_R').value = document.getElementById('bfname_R').value;
		document.getElementById('slname_R').value = document.getElementById('blname_R').value;
		document.getElementById('sfaddress_R').value = document.getElementById('bfaddress_R').value;
		document.getElementById('ssaddress').value = document.getElementById('bsaddress').value;
		document.getElementById('sphone_R').value = document.getElementById('phone_R').value;
		document.getElementById('sphone1').value = document.getElementById('phone1').value;
		document.getElementById('sphone2').value = document.getElementById('phone2').value;
		document.getElementById('scity_R').value = document.getElementById('city_R').value;
		document.getElementById('scounty').value = document.getElementById('county').value;
		document.getElementById('spincode_I').value = document.getElementById('pincode_I').value;		
		document.getElementById('scountry').value = document.getElementById('country').value;		
		
	}
	
}
