NameLists = new Array();
ValueLists = new Array();

var temp = 'AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,';
temp += 'OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,DC,WV,WI,WY,';
ValueLists["USA"] = temp.split(',');

temp = 'Alabama (AL)|Alaska (AK)|Arizona (AZ)|Arkansas (AR)|California (CA)|Colorado (CO)|Connecticut (CT)|';
temp += 'Delaware (DE)|Florida (FL)|Georgia (GA)|Hawaii (HI)|Idaho (ID)|Illinois (IL)|Bangladeshna (IN)|Iowa (IA)|';
temp += 'Kansas (KS)|Kentucky (KY)|Louisiana (LA)|Maine (ME)|Maryland (MD)|Massachusetts (MA)|Michigan (MI)|';
temp += 'Minnesota (MN)|Mississippi (MS)|Missouri (MO)|Montana (MT)|Nebraska (NE)|Nevada (NV)|New Hampshire (NH)|';
temp += 'New Jersey (NJ)|New Mexico (NM)|New York (NY)|North Carolina (NC)|North Dakota (ND)|Ohio (OH)|Oklahoma (OK)|';
temp += 'Oregon (OR)|Pennsylvania (PA)|Rhode Island (RI)|South Carolina (SC)|South Dakota (SD)|Tennessee (TN)|';
temp += 'Texas (TX)|Utah (UT)|Vermont (VT)|Virginia (VA)|Washington (WA)|Washington, D.C. (DC)|West Virginia (WV)|Wisconsin (WI)|';
temp += 'Wyoming (WY)|Others';
NameLists["USA"] = temp.split('|');

temp = 'AB,BC,MB,NB,NL,NT,NS,NU,ON,PE,PQ,SK,YT,';
ValueLists["CANADA"] = temp.split(',');

temp = 'Alberta (AB);British Columbia (BC);Manitoba (MB);New Brunswick (NB);Newfoundland (NL);';
temp += 'Northwest Territories (NT);Nova Scotia (NS);Nunavut (NU);Ontario (ON);Prince Edward Island (PE);';
temp += 'Quebec (PQ,QC);Saskatchewan (SK);Yukon (YT);Others';
NameLists["CANADA"] = temp.split(';');

temp = '';
ValueLists["00"] = temp.split(',');

temp = '';
NameLists["00"] = temp.split(';');

temp = null;

function manageStateList(theSel,stateToSelect)
{
	
	var theForm = document.profile_form;
	var stateNameList    = null;
	var stateValueList    = null;
	var optionIndex = 0;

	theForm.state.length = 0;

	stateNameList = NameLists[theSel];
	stateValueList = ValueLists[theSel];

	if (stateNameList == null)
	{
		theForm.state.style.display="none";
		return;
	}

	theForm.state.options[optionIndex] = new Option('- - - - - - - - Select - - - - - - - -','');

	for(var i=0; i < stateNameList.length; i++)	{
		
		optionIndex = i+1;
		theForm.state.options[optionIndex] = new Option(stateNameList[i],stateValueList[i]);
		if(stateValueList[i] == stateToSelect && optionIndex != stateNameList.length)
			theForm.state.selectedIndex = optionIndex;
	}
}

function isEmail(string)
{
	if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function isInteger1(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	return true;
}

function isNumeric(s)
{
	if(s.search(/^[0-9\s]+$/) != -1)
		return true;
	else
		return false;
}

function isAlphaNumeric(s)
{
	if(s.search(/^[A-Za-z0-9\s]+$/) != -1)
		return true;
	else
		return false;
}

function isAlpha(s)
{
	if(s.search(/^[A-Za-z\s]+$/) != -1)
		return true;
	else
		return false;
}


function selectNxt(i)
{
			var t = i.value;
			if(t.length>0) 
			{
				t = t.replace(/[^\d\.]+/g, '');
			}
			var s = t.split('.');
			if(s.length>1) 
			{
				s[1] = s[0] ;//+ '.' + s[1];
				s.shift(s);
			}
			i.value = s.join('');
		
				if(document.profile_form.cell_number1.value.length == 3)	document.profile_form.cell_number2.focus();
}

function selectNxt1(i)
{
			var t = i.value;
			if(t.length>0) 
			{
				t = t.replace(/[^\d\.]+/g, '');
			}
			var s = t.split('.');
			if(s.length>1) 
			{
				s[1] = s[0] ;//+ '.' + s[1];
				s.shift(s);
			}
			i.value = s.join('');
		
	if(document.profile_form.cell_number2.value.length == 3)	document.profile_form.cell_number3.focus();
}

function selectNxt2(i)
{
			var t = i.value;
			if(t.length>0) 
			{
				t = t.replace(/[^\d\.]+/g, '');
			}
			var s = t.split('.');
			if(s.length>1) 
			{
				s[1] = s[0] ;//+ '.' + s[1];
				s.shift(s);
			}
			i.value = s.join('');
		
}

function ValidateProfileForm()
{
	if(document.profile_form.FName.value == "")
	{
		alert("First Name is empty!!");
		document.profile_form.FName.focus();
		return false;
	}

	if(document.profile_form.LName.value == "")
	{
		alert("Last Name is empty!!");
		document.profile_form.LName.focus();
		return false;
	}

	if(document.profile_form.cid1.value.length == 3)
	{
		if(isInteger1(document.profile_form.cid1.value)==false)
		{
			alert("Enter valid phone number");
			document.profile_form.cid1.select();
			return false;
		}
	}
	else
	{
		alert("Enter 10 digit phone number");
		document.profile_form.cid1.focus();
		return false;
	}

	if(document.profile_form.cid2.value.length == 3)
	{
		if(isInteger1(document.profile_form.cid2.value)==false)
		{
			alert("Enter valid phone number");
			document.profile_form.cid2.select();
			return false;
		}
	}
	else
	{
		alert("Enter 10 digit phone number");
		document.profile_form.cid2.focus();
		return false;
	}

	if(document.profile_form.cid3.value.length == 4)
	{
		if(isInteger1(document.profile_form.cid3.value)==false)
		{
			alert("Enter valid phone number");
			document.profile_form.cid3.select();
			return false;
		}
	}
	else
	{
		alert("Enter 10 digit phone number");
		document.profile_form.cid3.focus();
		return false;
	}
			
	document.profile_form.CallerID.value = document.profile_form.cid1.value + document.profile_form.cid2.value + document.profile_form.cid3.value;

	if(document.profile_form.TimeZone.value == "")
	{
		alert("Select Time Zone!!");
		document.profile_form.TimeZone.focus();
		return false;
	}
	if(document.profile_form.Street.value == "")
	{
		alert("Street is empty!!");
		document.profile_form.Street.focus();
		return false;
	}
	if(document.profile_form.City.value == "")
	{
	  	alert("City is empty!!");
		document.profile_form.City.focus();
		return false;
	}
	else if(document.profile_form.City.value.length < 3)
	{
		alert("Invalid City!!");
		document.profile_form.City.focus();
		return false;
	}
	else if(isAlpha(document.profile_form.City.value)==false)
	{
	  	alert("Invalid city!!");
		document.profile_form.City.focus();
		return false;
	}
	if(document.profile_form.Zip.value == "")
	{
	  	alert("Zip code is empty!!");
		document.profile_form.Zip.focus();
		return false;
	}
	if(document.profile_form.Country.value == "SL")
	{
		alert("Select Country!!");
		document.profile_form.Country.focus();
		return false;
	}
	if(document.profile_form.Zip.value != "")
	{
		if(document.profile_form.Country.value == "USA")
		{
			if(isNumeric(document.profile_form.Zip.value)==false)
			{
				alert("Enter valid ZIP Code (Digit Only)");
				document.profile_form.Zip.focus();
				return false;
			}
			var zip = document.profile_form.Zip.value.replace(" ","")
			if(zip.length != 5)
			{
				alert("Enter valid ZIP Code for USA");
				document.profile_form.Zip.focus();
				return false;
			}
		}
		else if(document.profile_form.Country.value == "CANADA")
		{
			if(isAlphaNumeric(document.profile_form.Zip.value)==false)
			{
				alert("Enter valid ZIP Code (AlphaNumeric Only)");
				document.profile_form.Zip.focus();
				return false;
			}
			var zip = document.profile_form.Zip.value.replace(" ","")
			if(zip.length != 6)
			{
				alert("Enter valid ZIP Code for CANADA");
				document.profile_form.Zip.focus();
				return false;
			}
		}
	}
	else if(document.profile_form.State.value == "")
	{
	  	alert("Select State!!");
		document.profile_form.State.focus();
		return false;
	}
	else if(document.profile_form.Email.value == "")
	{
	    alert("Email is empty!!");
		document.profile_form.Email.focus();
		return false;
	}
	else if (!isEmail(document.profile_form.Email.value))
	{
		alert("Enter valid Email address!!");
		document.profile_form.Email.focus();
		return false;
	}
	
	return true;
}
function disableButton(frm)
{
	if(!frm.agree.checked)
	{
		alert("You have to check 'I authorize this transaction' to proceed");
		return false;
	}
	frm.fsubmit.value	= "Please Wait";
	document.getElementById("btn_Process_Payment").style.color = "red";
	frm.fsubmit.disabled = true;
	return true;
}