//////////////Function For Chack Number Only//////////
function VNum(contents){
var checkOK = "0123456789";
var checkStr = contents;
var allValid = true;
var ch;

for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
{ 
if (ch == checkOK.charAt(j))
{
break;
}
if (j == 9)
{
allValid = false;
break;
}
} 
if (!allValid)
{
return (false);
}
}
return (true);
}

//******FUNCTION FOR TRIM A STRING*****//
function TrimStr(str)
{  while(str.charAt(0) == (" ") )
{  str = str.substring(1);
}
while(str.charAt(str.length-1) == " " )
{  str = str.substring(0,str.length-1);
}
return str;
}
//////////////Function for Date check////
function dateCheck(m, d, y) 
{ 
if(m.value != '')
{ 
if(m.value == "4" || m.value == "6" || m.value == "9" || m.value == "11")
{ 
if(d.value == "31")
{ 
alert("Invalid date of birth") 
d.focus(); 
return false; 
} 
} 
if(m.value == "2")
{ 
if(parseInt(y.value)%4 != 0 && d.value == "29")
{ 
alert("Invalid date of birth") 
d.focus(); 
return false; 
} 
else if(d.value == 30 || d.value == 31)
{ 
alert("Invalid date of birth") 
d.focus(); 
return false; 
} 
} 
return true; 
} 
} 

/////////////////////////////////
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 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++){   
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
} 
return this
}

function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
}
return true
}
/************************************************************************/
function validateForm(frm)
{	
//alert("Hi");
//if(frm.cmb_title.selectedIndex==0)
//	{
//		alert("Please select your TITLE.");
//		frm.cmb_title.focus();
//		//frm.cmb_title.style.backgroundColor="#FFBBBB";
//		return false;
//	}
//alert(frm);
if(frm.txtFname.value=="")
{

alert("Please enter your FIRST NAME. For example: If your name is Gaurav Kumar Singh, you need to enter Gaurav.");
frm.txtFname.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
else if(!checktext(frm.txtFname.value))
{
alert("Please enter only Alphabets.")
frm.txtFname.select();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}


//  Middle Name Validation.
if((frm.txtMname.value!="") && !checktext(frm.txtMname.value))
{
alert("Please enter only Alphabets.");
frm.txtMname.select();
return false;
}


if(frm.txtLname.value=="")
{
alert("Please enter your LAST NAME. For example: If your name is Gaurav Kumar Singh, you need to enter Singh.");
frm.txtLname.focus();
//frm.txtLname.style.backgroundColor="#FFBBBB";
return false;
}
else if(!checktext(frm.txtLname.value))
{
alert("Please enter only Alphabets.")
frm.txtLname.select()
//frm.txtLname.style.backgroundColor="#FFBBBB";
return false;
}
if(frm.txtGender.selectedIndex==0)
{
alert("Please select your Gender.");
frm.txtGender.focus();
//frm.cmb_title.style.backgroundColor="#FFBBBB";
return false;
}	

if(frm.cmb_day_dob.value=="")
{
alert("Please select the DATE you were born on. Please remember that you MUST be 18 years or over so that we can process your order.");
frm.cmb_day_dob.focus();
//frm.cmb_day_dob.style.backgroundColor="#FFBBBB";
return false;
}
if(frm.cmb_month_dob.value=="")
{
alert("Please select the MONTH you were born in.");
frm.cmb_month_dob.focus();
//frm.cmb_month_dob.style.backgroundColor="#FFBBBB";
return false;
}
if(frm.cmb_year_dob.value=="")
{
alert("Please select the YEAR you were born on.");
frm.cmb_year_dob.focus();
//frm.cmb_year_dob.style.backgroundColor="#FFBBBB";
return false;
}
else if(!dateCheck(frm.cmb_month_dob, frm.cmb_day_dob, frm.cmb_year_dob))
{ 
return false
}
if(frm.mob_number.value=="")
{
alert("Please Enter Your Mobile Number.");
frm.mob_number.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
else if(frm.mob_number.value.length<10)
{
alert("Please enter only Valid Mobile Number.");
frm.mob_number.select()
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}		

else if(!VNum(frm.mob_number.value))
{
alert("Please enter only NUMBERS in Mobile Number.");
frm.mob_number.select()
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}	
if(frm.cmb_contime.selectedIndex==0)
{
alert("Please select Contact Time.");
frm.cmb_contime.focus();
//frm.cmb_title.style.backgroundColor="#FFBBBB";
return false;
}	
//if(frm.txtCardNumber.value=="")
//	{
//		alert("Please enter your Account Number.");
//		frm.txtCardNumber.focus();
//		//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
//		return false;
//	}
//	  else if(!VNum(frm.txtCardNumber.value))
//	{
//		alert("Please enter only NUMBERS in Card Number.");
//		frm.txtCardNumber.select()
//		//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
//		return false;
//	}
//if(frm.txtCardNumber.value=="")
//	{
//		alert("Please enter your CARD NUMBER.");
//		frm.txtCardNumber.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.txtCardHolder.value=="")
//	{
//		alert("Please enter your NAME. For example: If your name is Gaurav, you need to enter Gaurav.");
//		frm.txtCardHolder.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//	else if(!checktext(frm.txtCardHolder.value))
//	{
//		alert("Please enter only Alphabets.")
//		frm.txtCardHolder.select();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//	
//if(frm.cmbCardType.value=="")
//	{
//		alert("Please Select Your Card Type.");
//		frm.cmbCardType.focus();
//		//frm.cmb_month_dob.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.txtCVVNumber.value=="")
//	{
//		alert("Please enter your CVV NUMBER.");
//		frm.txtCVVNumber.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
// else if(!VNum(frm.txtCVVNumber.value))
//	{
//		alert("Please enter only NUMBERS in CVV NUMBER.");
//		frm.txtCVVNumber.select()
//		//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.cmbExpiryMonth.value=="")
//	{
//		alert("Please Select Your Card's Expiry Month.");
//		frm.cmbExpiryMonth.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.cmbExpiryYear.value=="")
//	{
//		alert("Please Select Your Card's Expiry Year.");
//		frm.cmbExpiryYear.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.cmbValidMonth.value=="")
//	{
//		alert("Please Select Your Card's Month.");
//		frm.cmbValidMonth.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	
//if(frm.cmbvalidYear.value=="")
//	{
//		alert("Please Select Your Card's Year.");
//		frm.cmbvalidYear.focus();
//		//frm.txtFname.style.backgroundColor="#FFBBBB";
//		return false;
//	}	

if(frm.txtBillingAddress.value=="")
{
alert("Please Enter Your Billing Address.");
frm.txtBillingAddress.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
if(frm.txtCity.value=="")
{
alert("Please Enter Your City Name.");
frm.txtCity.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
else if(!checktext(frm.txtCity.value))
{
alert("Please enter only Alphabets.")
frm.txtCity.select();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
if(frm.txtPinCode.value=="")
{
alert("Please Enter Your PinCode.");
frm.txtPinCode.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}	
else if(frm.txtPinCode.value.length<6)
{
alert("Please enter only Valid PIN CODE.");
frm.txtPinCode.select()
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}		

else if(!VNum(frm.txtPinCode.value))
{
alert("Please enter only NUMBERS in PIN CODE.");
frm.txtPinCode.select()
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}	
if(frm.txtstate.value=="")
{
alert("Please Enter Your State Name.");
frm.txtstate.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}
else if(!checktext(frm.txtstate.value))
{
alert("Please enter only Alphabets.")
frm.txtstate.select();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}		
if(frm.typ.value!="")
{
if(frm.txt_PayNUmber.value=="")
{
alert("Please Enter Number.");
frm.txt_PayNUmber.focus();
//frm.txtFname.style.backgroundColor="#FFBBBB";
return false;
}
}	

//if((frm.txtHPhone.value!="") && isNaN(frm.txtHPhone.value))
//	{
//		alert("Please enter only Numeric Character in Landline Number.");
//		frm.txtHPhone.select();
//		return false;
//	}
//	/*
//	var mobNo =frm.txtMobile.value;
//	if (!checkUKTelephone(mobNo))
//	{
//    	alert(PhnumberErrors[PhnumberErrorNo]);
//		frm.txtMobile.select()
//		//frm.txtMobile.style.backgroundColor="#FFBBBB";
//	 	return false;
//	}
//	*/
//var myTelNo = document.getElementById('tel').value;
//		if (!checkUKTelephone (myTelNo)) {
//     alert (telNumberErrors[telNumberErrorNo]);
//	 frm.tel.select();
//	 return false;
//		}
/*********************************/
var emailID=frm.txtEmail;
if ((emailID.value==null)||(emailID.value==""))
{
alert("Please enter your email address. For example: david.jones@example.co.uk. We need this information so that we may contact you in case of any problems with your order or if there are any updates related to your order.")
//alert("1");
emailID.focus()
//emailID.style.backgroundColor="#FFBBBB";
return false;
}
if (emailID.value.indexOf("@")<0)
{
alert("Please enter your email address. For example: david.jones@example.co.uk. We need this information so that we may contact you in case of any problems with your order or if there are any updates related to your order.")
//alert("2");
emailID.focus()
//emailID.style.backgroundColor="#FFBBBB";
return false;
}
if (emailID.value.indexOf(".")<0)
{
alert("Please enter your email address. For example: david.jones@example.co.uk. We need this information so that we may contact you in case of any problems with your order or if there are any updates related to your order.")
//alert("3");
emailID.focus()
//emailID.style.backgroundColor="#FFBBBB";
return false;
}
/*********************************/
/*if(frm.cmb_contime.value=="")
{
alert("We may need to speak to you in case of any problems with your order or if there are any updates related to your order. Please let us know the best time to contact you.");
frm.cmb_contime.focus();
//frm.cmb_contime.style.backgroundColor="#FFBBBB";
return false;
}
*/

/*if(frm.haveMobile.value=="")
{
alert("Please Enter FIRST NAME");
frm.haveMobile.focus();
return false;
}
if(frm.wantSameNum.value=="")
{
alert("Please Enter FIRST NAME");
frm.wantSameNum.focus();
return false;
}*/

//document.getElementById('frmPersonalDetail').submit();
//parent.location='orderform.asp#step2';
return true;
}
/**********************************************************************/

///////////////////////Validation For Bank Detail	
function validatebank(formbank)
{	
if(formbank.txtAccholder.value=="")
{
alert("Please enter accountholder Name.");
formbank.txtAccholder.focus();
//formbank.txtAccholder.style.backgroundColor="#FFBBBB";
return false;
}
else if(!checktext(formbank.txtAccholder.value))
{
alert("Please enter only Alphabets.")
formbank.txtAccholder.select()
//formbank.txtAccholder.style.backgroundColor="#FFBBBB";
return false;
}
if(formbank.txtAccNumber.value=="")
{
alert("Please enter your Account Number.");
formbank.txtAccNumber.focus();
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}
else if(!VNum(formbank.txtAccNumber.value))
{
alert("Please enter only NUMBERS in account number.");
formbank.txtAccNumber.select()
//formbank.txtAccNumber.style.backgroundColor="#FFBBBB";
return false;
}

if(formbank.txtSortCode.value=="")
{
alert("Please enter Sort Code.");
formbank.txtSortCode.focus();
//formbank.txtSortcode.style.backgroundColor="#FFBBBB";
return false;
}
else if(!VNum(formbank.txtSortCode.value))
{
alert("Please enter only NUMBERS in sort code.");
formbank.txtSortCode.select()
//formbank.txtSortCode.style.backgroundColor="#FFBBBB";
return false;
}
if(formbank.bankaddress1.value=="")
{
alert("Please enter bank address!");
return false;
}
if(formbank.cmb_year_bank.selectedIndex==0)
{
alert("Please select time with bank.");
formbank.cmb_year_bank.focus();
//formbank.cmb_year_bank.style.backgroundColor="#FFBBBB";
return false;
}
if(formbank.cmb_months_bank.selectedIndex<0)
{
alert("Please select time with bank.");
formbank.cmb_months_bank.focus();
//formbank.cmb_months_bank.style.backgroundColor="#FFBBBB";
return false;
}

//window.location='orderform.asp#step4';
return true;
}
function valid ()
{
if(document.search.BankRecord.options[document.search.BankRecord.selectedIndex].value=="")
{
alert("Bank Address not found. Go for valid Sort Code");
return false;
}
else if(document.search.BankRecord.options[document.search.BankRecord.selectedIndex].value=="Error: No Records Found")
{
alert("Bank Address not found. Go for valid Sort Code");
return false;
}
return true;
}

/**********************/
function clearBox(ctrlName)
{	
ctrlName.style.backgroundColor="#FFFFFF";
}
/*****************************/
function checktext(Contents)
{
var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
var checkStr = Contents;
var allValid = true;

for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)

if (ch == checkOK.charAt(j))
break;
if (j == 54 )
{
allValid = false;
break;
}
}

if (!allValid)
{
return false;
}
else
{
return true;
}
}
function checkText(ctrlName,msg)
{	
if(ctrlName.value='')
{
ctrlName.style.backgroundColor="#FFBBBB";
alert("Enter your "+msg);
return false;
}
}
/**********************/
function checkCombo(ctrlName,msg)
{
if(ctrlName.selectedIndex==0)
{
alert("Select Your "+msg);
ctrlName.style.backgroundColor="#FFBBBB";
return false;
}
}
/*********************/
/*****************/
function showNum(id)
{
if(id=='NO')
{
document.getElementById('samenum').style.visibility='hidden';
document.getElementById('invis').style.visibility='hidden';
}
else
{
document.getElementById('samenum').style.visibility='visible';
document.getElementById('invis').style.visibility='visible';
}
}
/****************/
function popUpHelp(netname)
{
window.open('help.asp?netname='+netname,'help','width=400,height=100,resizable=no,scrollbars=no');
}
/*******************/
function manualAddress(chkVal)
{
if(document.frmAddress.chkManualAdd.checked)
{
document.frmAddress.txtStreet.readOnly=false;
document.frmAddress.txtHouseNo.readOnly=false;
document.frmAddress.txtCity.readOnly=false;
document.frmAddress.txtCounty.readOnly=false;
document.frmAddress.txtPostcode.readOnly=false;
document.getElementById('POSTCODE').innerHTML='';
document.getElementById('TDPOSTCODE').style.backgroundColor='';
document.getElementById('btnAuto').disabled=true;
/********************************/
document.frmAddress.txtStreet.value='';
document.frmAddress.txtHouseNo.value='';
document.frmAddress.txtCity.value='';
document.frmAddress.txtCounty.value='';
document.frmAddress.txtPostcode.value='';
document.frmAddress.autopostcode.value='';
/*******************************/
}
else
{
document.frmAddress.txtStreet.readOnly=true;
document.frmAddress.txtHouseNo.readOnly=true;
document.frmAddress.txtCity.readOnly=true;
document.frmAddress.txtCounty.readOnly=true;
document.frmAddress.txtPostcode.readOnly=true;
//document.frmAddress.autopostcode.readOnly=true;
document.frmAddress.txtStreet.value='';
document.frmAddress.txtHouseNo.value='';
document.frmAddress.txtCity.value='';
document.frmAddress.txtCounty.value='';
document.frmAddress.txtPostcode.value='';
document.frmAddress.autopostcode.value='';
document.getElementById('btnAuto').disabled=false;
}
}
/******************/
