var CrLf = String.fromCharCode(10, 13);
//***********************************************
	function setIdentity(FromBillToShip){
		var index;
		var value;
		if (document.RegistrationForm.Identity.checked == true){
			if(FromBillToShip == true){
				index = document.RegistrationForm.BillCountry.selectedIndex;
				value = document.RegistrationForm.BillCountry.options[index].value;
				document.RegistrationForm.ShipCountry.selectedIndex = index;
				document.RegistrationForm.ShipCountry.options[index].value = value;
				document.RegistrationForm.ShipCity.value = document.RegistrationForm.BillCity.value;
				document.RegistrationForm.ShipPostalCode.value = document.RegistrationForm.BillPostalCode.value;
				document.RegistrationForm.ShipAddr1.value = document.RegistrationForm.BillAddr1.value;
				document.RegistrationForm.ShipAddr2.value = document.RegistrationForm.BillAddr2.value;
			}else{
				index = document.RegistrationForm.ShipCountry.selectedIndex;
				value = document.RegistrationForm.ShipCountry.options[index].value;
				document.RegistrationForm.BillCountry.selectedIndex = index;
				document.RegistrationForm.BillCountry.options[index].value = value;
				document.RegistrationForm.BillCity.value = document.RegistrationForm.ShipCity.value;
				document.RegistrationForm.BillPostalCode.value = document.RegistrationForm.ShipPostalCode.value;
				document.RegistrationForm.BillAddr1.value = document.RegistrationForm.ShipAddr1.value;
				document.RegistrationForm.BillAddr2.value = document.RegistrationForm.ShipAddr2.value;
			}
		}
	}
//**************************************************
	function submitForm(FormEl,Arr,Prompt, LPreffix){
		var validationRes;
		validationRes = validateForm(FormEl,Arr);
		
		if (validationRes == 1)	{
			window.alert(Prompt);
			return false;
		}
		if (validationRes == 2){
			var CrLf = String.fromCharCode(10, 13);
			var qerrtxt;
			if (LPreffix == 'du'){
				qerrtxt = 'Gelieve een geldige e-mail adres in te voeren.'+ CrLf + 'Bijvoorbeeld: svetla@soft-i.com';
			}
			else if (LPreffix == 'fr'){
				qerrtxt = 'Prière d\'entrer une adresse e-mail valide.'+ CrLf + 'Par exemple: svetla@soft-i.com';
			}
			else{
				qerrtxt = 'Please enter a valid e-mail address.'+ CrLf + 'For example: svetla@soft-i.com';
			}	
			window.alert(qerrtxt);
			return false;
		}
		
		if (validationRes == 3){
			var tcerrtxt;
			if (LPreffix == 'du'){
				tcerrtxt = 'Gelieve te bevestigen dat u de Algemene Verkoopsvoorwaarden hebt gelezen en goedgekeurd';
			}
			else if (LPreffix == 'fr'){
				tcerrtxt = 'Prière de confirmer d\'avoir lu et accepté les Conditions Générales de vente';
			}
			else{
				tcerrtxt = 'Please confirm that you have read and agree to the terms and conditions of use';
			}	
			window.alert(tcerrtxt);
			return false;
		}
		
		if (validationRes == 4){
			return true;
		} 
	}  
//***********************************************
	function validateForm(FormEl,Arr){
		var i;
		for (i = 0; i < FormEl.length; i++){
			var el = FormEl[i];
			var name = el.name;
			var val = el.value;
			
			if (val != null && isEmpty(val) && !isInArr(name, Arr)){
				el.focus();
				return 1;	
			}
			if (name.search(/Email/)!=-1 && !isEmpty(val) && !isEmail(val)){	
				el.focus();
				return 2;
			}
			
			if (name.search(/AcceptTC/)!=-1 && el.type == 'checkbox' && !el.checked){
				el.focus();
				return 3;
			}
		}	
		return 4;				
	  }
//***********************************************	 
	 function isEmpty(str){
		var k;
	    for (k = 0; k < str.length; k++){
		    var chr = str.substring(k, k + 1);
			if (chr != ' '){
			  return false;
			}
	    }
	    return true;
	  }
//***********************************************	  
	  function isInArr(name, Arr){
		if (Arr == '') return false; 
		for (var j = 0; j < Arr.length; j++){
			var el1 = Arr[j];
			var name1 = el1.name;
			if (name == name1){
				return true;
			}
		}	
		return false;		
	  }
	  
	  function isEmail(strEmail){
		if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else	
			return false;
	  }  
//***********************************************  
	function ConfirmCancelation(Prompt, CancelID)
	{
		if (CancelID != '')
		{
			document.CancelForm.CancelOrderID.value = CancelID;
			Prompt = Prompt + " (id=" + CancelID + ")";
		}	
		return window.confirm(Prompt);
	}
//***********************************************