function checkCountry(ddCountry){

//alert(ddCountry.value);

if (ddCountry.value == 1)

{

	document.getElementById("div_state").style.display = "inline";

	document.getElementById("div_prov").style.display = "none";

	//document.getElementById("div_ddstate").style.display = "none";

	//document.getElementById("ddstate").value = "test";

	// hide invoice me as well 

	document.getElementById("div_invoiceme").style.display = "inline";

	

}

else 

{

	

	document.getElementById("div_state").style.display = "none";

	document.getElementById("div_prov").style.display = "inline";

	document.getElementById("div_invoiceme").style.display = "none";

	

	for (i=0;i<document.form1.radiopayby.length;i++){

		//alert(document.form1.radiopayby[i].value);	

		if (document.form1.radiopayby[i].value =="ccard")

			document.form1.radiopayby[i].checked= true;

		}

	}

}



function checkPageValue(){

	//alert(document.getElementById("hfBtn").value);

	if (document.getElementById("ddcountry").value == 1 ){

			// hide invoice div 

			document.getElementById("div_invoiceme").style.display = "inline";



	}	

	else {

		document.getElementById("div_invoiceme").style.display = "none";

		document.getElementById("div_state").style.display = "none";

	}

	

	showPackageInfo(document.getElementById("ddPackage").value);

	

	

}

function showPackageInfo(val){

//alert(val);

	var dv = "div_ddPackage_" + val;

	document.getElementById("div_ddPackage_1").style.display 	= "none";

	document.getElementById("div_ddPackage_2").style.display 	= "none";

	document.getElementById("div_ddPackage_3").style.display 	= "none";

	document.getElementById("div_ddPackage_4").style.display 	= "none";

	document.getElementById("div_ddPackage_5").style.display   = "none";
	
	document.getElementById("div_ddPackage_14").style.display   = "none";

	document.getElementById(dv).style.display 				  = "inline";

	 

}

function disableInvoice(val){

	if (val == 14 )
	{
		document.form1.radiopayby[1].disabled=true;
		document.form1.radiopayby[0].checked=true;
		document.getElementById("div_invoice").style.display="none";
		document.getElementById("div_ccard").style.display="inline";
	}
	else
	{
		document.form1.radiopayby[1].disabled=false;
	}

}



function validateField(elem){

	

	if (notEmptyField(elem)){

		
 			 elem.style.border='1px solid #CCCCCC';

			 elem.style.backgroundColor ='#FFFFFF';

			 var div = "div_" + elem.id;

			 document.getElementById(div).style.display = "none";

			 return 1; 

			

		

	}else{

			 elem.style.backgroundColor ='#F5E4E0';

			 var div = "div_" + elem.id;

			 document.getElementById(div).style.display = "inline";

			 return 0;

	} 

}





function notEmptyField(elem) { 	

	if(elem.value.length == 0)	return 0;

	else						return 1;

	

}

function codename(){

	if(document.form1.checkbox.checked)

	{	

		document.form1.btnSignup.disabled=false;

	}

	else{

    	document.form1.btnSignup.disabled=true;

	}

}



function numbersonly(myfield, e, dec)

{

		var key;

		var keychar;

		

		if (window.event)

		   key = window.event.keyCode;

		else if (e)

		   key = e.which;

		else

		   return true;

		keychar = String.fromCharCode(key);

		

		// control keys

		if ((key==null) || (key==0) || (key==8) || 

			(key==9) || (key==13) || (key==27) )

		   return true;

		

		// numbers

		else if ((("0123456789").indexOf(keychar) > -1))

		   return true;

		

		// decimal point jump

		else if (dec && (keychar == "."))

		   {

		   myfield.form.elements[dec].focus();

		   return false;

		   }

		else

		   return false;

}

function checkPayBy( elem )

{

	divInv = document.getElementById("div_invoice");

	divCC = document.getElementById("div_ccard");

	

	if ( elem.value == "ccard" )

	{

		document.getElementById("div_invoice").style.display="none";

		document.getElementById("div_ccard").style.display="inline";

	}

	else 

	{

		document.getElementById("div_invoice").style.display="inline";

		document.getElementById("div_ccard").style.display="none";

	}

}

/*function GetSelectedRadioButton(frmName , rbName ) {

var chosen ="";

var len = document.form1.radiopayby.length;

//alert(len);

var rb;

for (i = 0; i <len; i++) {

rb =document.form1.radiopayby[i];

if (rb.checked) {

	return rb.value;

}

}

}
*/
   

function signupFormValidator(){

	var str = "";

	var str2 = "";

	var frmStatus = false;

	var country = document.getElementById("ddcountry").value;

	//var payMethod = GetSelectedRadioButton("radiopayby");

	//var elem_status = new Array();

	var elem_status = new Array();



	for(i=0; i < document.form1.elements.length; i++){

		var elem = document.form1.elements[i];



		if( (elem.type == "text")  && (elem.id != "txtaddress2")){

					

			if(elem.value.length == 0 )

			{	

				if (country ==1 && elem.id == "txtddstate"){ // United States 

						// donot validate txtddstate field 

						document.getElementById("div_txtddstate").style.display="none";

						elem_status[i] = 1;

				}else{

					   //if (payMethod == "invoice" && (elem.id == "txtcno" || elem.id == "txtscode" ) ){ // United States 
					   if (elem.id == "txtcno" || elem.id == "txtscode"){

					  		 //alert(elem.id + "_true");

							//frmStatus = true ;	

							elem_status[i] = 1;

					   }else{

							validateField(document.form1.elements[i]);	  // just to show error 

							//alert(elem.id + "_false");

							frmStatus = false ;	  

							elem_status[i] = 0;

					   }

				}

				

			}

			else

			{ 

			

					if(elem.id=="txtemail"){

						if (emailValidator(elem)){

							frmStatus = true;

							HideError2Div(elem);

							elem_status[i] = 1;

						}

						else{

							frmStatus = false;

							ShowError2Div(elem);// show error div 

							elem_status[i] = 0;

						}		

					}else if (elem.id=="txtpass1" ){//|| elem.id=="txtpass2"  ){

					// match both pass 

						var e1 = document.getElementById("txtpass1");

						var e2 = document.getElementById("txtpass2");

						if(compareField(e1,e2))

						{

							frmStatus = true;

							HideError2Div(e1);

							elem_status[i] = 1;

						}

						else{

							elem_status[i] = 0;

							frmStatus = false;

							

							ShowError2Div(e1);

						} 

					}else 

					elem_status[i] = 1;	

					

					//if (payMethod == "ccard" ){
					if (1){
						if ((elem.id == "txtcno")){

							if (checkMinFieldLength(elem,13,16)){

								frmStatus = true;

								HideError2Div(elem);

								elem_status[i] = 1;

							}

							else{

								frmStatus = false;

								ShowError2Div(elem);// show error div 

								elem_status[i] = 0;

							}		

						 }else if ((elem.id=="txtscode")){

							if (checkMinFieldLength(elem,3,4)){

								frmStatus =  true;

								HideError2Div(elem);

								elem_status[i] = 1;

							}

							else{

								frmStatus = false;

								ShowError2Div(elem);// show error div 

								elem_status[i] = 0;

							}	

				 	     }



			         }else 

					 	elem_status[i] = 1;

		 }

		}

		

	}

	//alert(elem_status.length);

	

	for (i=0; i<elem_status.length; i++ ){

	   if (elem_status[i] == undefined ){}

	   	else 

		{

			if( elem_status[i] == 0 ){

 		    	frmStatus =false;

				return false;

			}	

			

		}

}

	//alert(frmStatus);

	if (frmStatus) {

		frmStatus =true;

		document.getElementById("hfBtn").value = "signup";

	}else{ 

		frmStatus =false;

		document.getElementById("hfBtn").value = "";

	}

	

	//return frmStatus;

	return frmStatus;



}




function checkEmailFormat(elem){
	
  if (notEmptyField(elem))
	if (emailValidator(elem)){

							frmStatus = true;

							HideError2Div(elem);

							elem_status[i] = 1;

						}

						else{

							frmStatus = false;

							ShowError2Div(elem);// show error div 

							elem_status[i] = 0;

						}			
	
	
}
function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return 1;
	}else{
		return 0;
	}
}

function ShowError2Div(elem){
	 elem.style.backgroundColor ='#F5E4E0';
	 var div = "div_" + elem.id+"2";
	 document.getElementById(div).style.display = "inline";
}



function HideError2Div(elem){

	 elem.style.border='1px solid #CCCCCC';

	 elem.style.backgroundColor ='#FFFFFF';

	  var div = "div_" + elem.id+"2";

	 document.getElementById(div).style.display = "none";
}

function checkMinFieldLength(elem, minNum, maxNum){
	//alert(elem.value.length);
	var uInput = elem.value;
	if(uInput.length >= minNum && uInput.length <= maxNum){
		HideError2Div(elem);
		//alert("P");
		return true;}
	else if(uInput.length >0){
		ShowError2Div(elem);	
		//alert("E");
		return 0;
	}	

}



function isNumeric(elem){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))	{
	  return 1;
	}else{
		elem.value="";
		//elem.focus();
		return 0;
	}

}





function compareField(elem1,elem2){

//alert(elem1.value);



	if (elem1.value != "" && elem2.value != "")

	{

		if (elem1.value != elem2.value)

		{

           

			return 0;

	   }

		else 

		{

		return 1;

		}

	}

else

	{

		return 0;

	}

}


function btnSignupClick(){
	document.getElementById("hfBtn").value = "signup";
	document.form1.submit();
}

function btnCancelClick(){
	document.getElementById("hfBtn").value = "cancel";
	document.form1.submit();
}


function btnConfirmClick(){
	document.getElementById("hfBtn").value = "confirm";
	//alert(document.getElementById("hfBtn").value);
	document.form1.submit();
}
/*



function checkImageText(elem, helperMsg)

{

	var imgText = document.getElementById('txtImgText');

	alert(imgText.value);

	if(elem.value != imgText.value)

	{

		return 0;

	}

	else

	{

		return 1;

	}

}

*/

