var frmObjt;
var editWind;
var popWind;
var illegalChars= /[\<\>\{\}\[\]]/;var strIllChars = "< > { } [ ]"; 
var illegalChars2= /[\"]/;var strIllChars2 = '"'; 
var daysInMon = new Array(31,28,31,30,31,30,31,31,30,31,30,31); 
var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var allowReturn = true;

var frmObjt;

function val(){ 
frmObjt = document.mailer;
trimInputValues()
if (testInput() && chkEmail()){
 frmObjt.submit();
}

}

function testInput(){ 
	if (frmObjt.firstname.value.length < 1) fail ("Please enter your first name.",frmObjt.firstname);
	else if (!chkCharacters(frmObjt.firstname.value)) fail ("Please do not use any of these characters. " + strIllChars ,frmObjt.firstname);
	else if (frmObjt.lastname.value.length < 1) fail ("Please enter your last name.",frmObjt.lastname);
	else if (!chkCharacters(frmObjt.lastname.value)) fail ("Please do not use any of these characters. " + strIllChars ,frmObjt.lastname);
	else if (frmObjt.address.value.length < 1) fail ("Please enter your address.",frmObjt.address);
	else if (frmObjt.childname1.value.length < 1) fail ("Please enter at least one childs name.",frmObjt.childname1);
	else if (frmObjt.childgender1.selectedIndex == 0) fail ("Please the gender of your child or children.",frmObjt.childgender1);
	else return true;
}

function chkEmail(){
if (frmObjt.email.value.indexOf("@")== -1)fail("Missing the '@' in E-mail address"+dropline+dropline+"Example: myname@myisp.com",frmObjt.email);
else{
var adr = frmObjt.email.value.split("@");
if (adr[0].length < 1) fail ("User address absent"+dropline+dropline+"Example: myname@myisp.com",frmObjt.email);
else if (adr[1].indexOf(".") == -1)fail("Missing Dot  ( . )"+dropline+dropline+"Example: myname@myisp.com",frmObjt.email);
else if ((adr[1].split("."))[0].length < 1)fail ("No domain entered"+dropline+dropline+"Example: myname@myisp.com",frmObjt.email);
else if ((adr[1].split("."))[1].length < 1)fail ("Missing identifier (com - co.uk etc)"+dropline+dropline+"Example: myname@myisp.com",frmObjt.email) 
else return true;
}
}


function fail(msg,fld){
alert("Error:"+ dropline +dropline +msg);
fld.focus();
return false
}
if (navigator.appVersion.lastIndexOf('Win') != -1) {
      dropline = "\r\n"  } else { dropline = "\n" }

function trimInputValues(){
	frmObjt = document.mailer;
	for (i = 0;i<frmObjt.elements.length;i++ ){
		frmObjt.elements[i].value = trimSpaces(frmObjt.elements[i].value)
	} 

}
function trimSpaces(strInput) { 
    
    while (strInput.substring(0,1) == ' ') 
        strInput = strInput.substring(1, strInput.length);

    while (strInput.substring(strInput.length-1,strInput.length) == ' ')
        strInput = strInput.substring(0, strInput.length-1);

   return strInput;
} 
function chkCharacters(thsValue){

if (thsValue.match(illegalChars))return false;
if (thsValue.match(illegalChars2))return false;

return true; 
}


function chkRet(evt){
evt = (evt) ? evt : event
  if (!allowReturn){
  if (navigator.appName == "Netscape"){
   if (evt.which == 13) {
   return false;
  }
  }
  if (navigator.appName == "Microsoft Internet Explorer"){
   	if (event.keyCode == 13){
   	return false;    
	}
	}
}
}

function sortLists(thsForm,type){
	var mnthsLeft;
	switch (type){
		 case 1:
		 	 dayElement = thsForm.childdob1;
	   		 monthElement = thsForm.childmob1;
	   		 yearElement = thsForm.childyob1;
		 break;  
		 case 2:
		 	 dayElement = thsForm.childdob2;
	   		 monthElement = thsForm.childmob2;
	   		 yearElement = thsForm.childyob2;
		 break;  
		 case 3:
		 	 dayElement = thsForm.childdob3;
	   		 monthElement = thsForm.childmob3;
	   		 yearElement = thsForm.childyob3;
		 break;  
	}
	
		
	endYr = ((yearElement.options[yearElement.selectedIndex].value)-2000) / 4;
	   	 if ((endYr.toString()).indexOf(".") == -1){
			daysInMon[1] = 29;
			}else{
			daysInMon[1] = 28;
		 	}
	 	 
		 
		 
		 monthInd = monthElement.selectedIndex;

		 for (i = 1 ;i < 32 ;i++){
				if (i <= daysInMon[monthInd]){
				   dayElement.options[i-1].text = i;
				   dayElement.options[i-1].value = i;
				 }else{
				   dayElement.options[i-1].text = "";
				   dayElement.options[i-1].value = "";
				 }
				
				
			}
			
			if (dayElement.options[dayElement.selectedIndex].value == ""){
			   while (dayElement.options[dayElement.selectedIndex].value == ""){
			     dayElement.selectedIndex -= 1;
			   }
			}	
			
		
		if (yearElement.selectedIndex < yearElement.selectedIndex){
		  yearElement.selectedIndex = yearElement.selectedIndex;
		} 	
				
}

function uploadImage(thisForm,productid,whcimage){
storeImageUploadForm = thisForm;
if (popWind)popWind.close();
popWind = window.open("images.php?productid="+productid,"","top=10,left=10,height=440,width=550,resizable,scrollbars,status")

}


document.onkeydown = chkRet;