/*

	checks if an array of fields has been entered or not

	the array is of the format

		0 -> field object

		1 -> field name

		2 -> field object

		3 -> field name

		.

		.

		i -> field object

		i + 1 -> field name

*/

function CheckFieldsEntered(fieldList)

{

	var result = true;

	for(i = 0; i < fieldList.length && result; i += 2)	

	{

		field = fieldList[i];

		if (field.type == "text" || field.type == "textarea")

			result = IsEntered(field, fieldList[i+1]);

		else

			result = IsSelectEntered(field, fieldList[i+1]);

	}

	return result;

}



function IsEntered(field, name)

{

	if (field.value == "")

	{

		alert("Please enter a value for the field '" + name + "'");

		field.focus();

		return false;

	}

	

	return true;

}



function IsValidEmail(fieldObject,fieldName)

{

	var value;

	value = fieldObject.value;

	var wrongTestRE = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(^\s)/;

	var correctTestRE = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

	if (!wrongTestRE.test(value) && correctTestRE.test(value)) 

	{

		return true;

	}



	alert('You have not entered a valid email in : "' + fieldName + '"');



	fieldObject.focus();

	fieldObject.select();



	return false;

}



function IsFieldComplete(field,fieldName)

{

	if(field.value.length < 6 )

	{

		alert(fieldName + " Must be 6 or more characters long");

		field.focus();

		return false;

	}

return true;

}





function IsSelectEntered(fieldObject, fieldName){

 if ( (fieldObject.selectedIndex == -1) || (fieldObject[fieldObject.selectedIndex].value == "") || (fieldObject[fieldObject.selectedIndex].value == 0)){

   	alert("Please select a value for " + fieldName);
	fieldObject.focus();

   	return false;

 }

	

 return true;

}





function IsValidMonth( month ){

	return ( (month > 0 ) && ( month <= 12 ));

}



function IsValidDay( day, month, year){

	var totalDays;

	

	if ( month == 2 )

		totalDays =  28 + ( ( year % 4 == 0 ) && ( ( year % 100 != 0 ) || ( year % 400 == 0 ) ) );

	else

		totalDays = 30 + ( ( month % 2 == 0 ) ^ ( month <= 7 ) );

	

	//alert(day + month + year + totalDays);

	if ( ( day > 0 ) && ( day <= totalDays ) )

		return true;

	

	

	return false;

}



function CheckMonthYearIsValid(fieldObject, fieldName){

	var value;

	value = fieldObject.value;

	

	// check if the field has been mm/dd/yy or mm/yy

	var mmddRE = /(\d{1,2})[\/-](\d{2}|\d{4})$/;

	if ( mmddRE.test( value ) ){

		var dummy;

		dummy = mmddRE.exec(value);



		var month;

		var year;

		

		month = dummy[1];

		year = dummy[2];



		if ( isValidMonth( month )) 

			return true;

	}

	

	alert("Date entered in " + fieldName + " is not valid!");

	fieldObject.focus();

	fieldObject.select();

	return false;

}



function CheckFullDateIsValid(fieldObject, fieldName){

	var value;

	value = fieldObject.value;

	

	// check if the field has been mm/dd/yy or mm/yy

	var mmddyyRE = /(\d{1,2})[\/-](\d{1,2})[\/-](\d{4})$/;

	if ( mmddyyRE.test( value ) ){

		var dummy;

		dummy = mmddyyRE.exec(value);



		var month;

		var year;

		var day;

		

		month = dummy[1];

		day = dummy[2];

		year = dummy[3];



		if ( (isValidMonth( month )) && (isValidDay( day, month, year ) ) )

			return true;

	}



	alert("Date entered in " + fieldName + " is not valid!");

	fieldObject.focus();

	fieldObject.select();

	return false;

}



function IsIntegerField(field, name)

{

	if ( isNaN(field.value) )

	{

		alert("Please enter a valid integer value for " + name);

		field.focus();

		field.select();

		return false;

	}

	

	return true;

}



function IsString(field, name)

{

	if ( isNaN(field.value) )

	{

		return true;

	}

	else

	{

		alert("Please enter a valid string value for " + name);

		field.focus();

		field.select();

		return false;

	}

}



function FieldMatch(src, target, desc)

{

	if (src.value != target.value)

	{

		alert("Values entered in " + desc + " do not match");

		src.focus();

		return false;

	}

		

	return true;

}



function FieldMatch2(src, target, desc)

{

	if (src.value == target.value)

	{

		alert("Values entered in " + desc + " should not match");

		src.focus();

		return false;

	}

		

	return true;

}



// validate alphanumeric characters

function AlphaNumeric(alphane,desc)

{

	

	var numaric = alphane.value;

	//alert(numaric);

	for(var j=0; j<numaric.length; j++)

		{

		  var alphaa = numaric.charAt(j);

		  var hh = alphaa.charCodeAt(0);

		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))

		  {

			  



		  }

		else	{

			alert("Values entered in " + desc + " should be alphanumeric");

			alphane.focus();

			 return false;

		  }

		}

		

		 return true;

}



// validate string length

function LengthValidator(src,vlength,desc)

{

	if(src.value.length<vlength || src.value.length>vlength)

	{

		alert("Values entered in " + desc + " should be "+vlength+" characters long");

		src.focus();

		return false;

	}

	

		 return true;

}






//Ajax Code
//By Intikha alam