function validateUploadInfo(f) {

	if (f.File1.value == "") {
        	alert("Please click the browse button and select a picture to upload!");
           	f.File1.focus();
      		return false;
	}

	var iLen = String(f.File1.value).length;
    var subs = String(f.File1.value).substring(iLen, iLen - 4);
	if ((subs != ".jpg") && (subs != ".JPG"))
	{
        	alert("Only .jpg format allowed!");
           	f.File1.focus();
      		return false;
	}

	if (f.name.value == "") {
        	alert("Please enter your pet's name!");
           	f.name.focus();
      		return false;
	}

	if (!checkName(f.name.value)) {
		alert("Please enter only letters!");
		f.name.value = ""
		f.name.focus();	           	
		return false;
	}

	if (f.sex.value == "") {
        	alert("Please enter your pet's gender!");
           	f.sex.focus();
      		return false;
	}

	if (f.whelped.value == "") {
        	alert("Please enter when your pet was born! example: 1/1/2005");
           	f.whelped.focus();
      		return false;
	}

	sStr = f.whelped.value;
	if (isDate(sStr) == false){
           	f.whelped.focus();
      		return false;
	}

	if (isPastDate(sStr) == false){
           	f.whelped.focus();
      		return false;
	}

	if (f.city.value == "") {
        	alert("Please enter the city you live in!");
           	f.city.focus();
      		return false;
	}

	if ((f.state.value == "") && (f.country.value == "")) {
        	alert("Please select the state or enter the country you live in!");
           	f.state.focus();
      		return false;
	}

	if (f.country.value == "") {
        	alert("Please enter the country you live in!");
           	f.country.focus();
      		return false;
	}


	if (!checkEmail(f.email.value)) {
        alert("Please enter a valid e-mail address!");
        f.email.focus();
		f.email.select();
		return false;
      }
	if (f.terms.checked == false) {
        alert("Please agree to the terms and conditions!");
      	return false;
	}
}

function checkName(checkSyntax) {

	var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
	var flag
   
	for (i=0; i<checkSyntax.length; i++) 
	{
		loginchar = checkSyntax.charAt(i)
		flag = false
		for (j=0; j<validChars.length; j++) 
		{
			if (loginchar == validChars.charAt(j) ) 
				flag = true
		}
		if (flag == false) 
			return false
	}

     return true
}

function checkEmail(checkSyntax) {

	var invalidChars = " /:,;"
        
	if (checkSyntax == "") 
      	{ return false }
   
   	for (i=0; i<invalidChars.length; i++) {
      		badChar = invalidChars.charAt(i)
      		if (checkSyntax.indexOf(badChar,0) > -1) 
         		{ return false }
   	}
   
   	var atPos = checkSyntax.indexOf("@",1)
      	if (atPos == -1) 
     	 { return false }

   	if (checkSyntax.indexOf("@",atPos+1) > -1) 
      	{ return false }
      
   	var periodPos = checkSyntax.indexOf(".",atPos)
      	if (periodPos == -1) 
         	{ return false }
         
      	if (periodPos+3 > checkSyntax.length) 
         	{ return false }
       
     	return true
}


function isPastDate(dateStr) {

	var curdate = new Date()
	var dob = new Date(dateStr)

	if (curdate < dob)
	{
		alert("Date of Birth occurs in the future!");
		return false;
	}


	return true; // date is valid
}

function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
	alert("Please enter date as mm/dd/yyyy");
	return false;
	}

	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}

	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31.");
	return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn`t have 31 days!")
	return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn`t have " + day + " days!");
			return false;
		}
	}

return true; // date is valid
}


