//#####################################################################################
//	# File Name: commonFunctions.js
//	# File Version: v 1.0
//	# Created By: Ashish shinde
//	# Created On: 
//	# Last Modified By: Ashish shinde
//	# Last modified On: 
//#####################################################################################

//=====================================================================================
//  Function Name : IsEmpty 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks whether a field has value or is blank, it returns false if a field 
//  is empty otherwise true. 
//  Parameters: fld : Field name to be check for blank.
//	string msg : Message if field is blank.	
//----------------------------------------------------------------------------------------
function IsEmpty(fld,msg) 
{ 
	fld.value = Trim(fld.value);
	if((fld.value == "" || fld.value.length == 0) && (msg == '')) 
	{ 
		return false; 
	} 
	if(fld.value == "" || fld.value.length == 0) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//===========================================================================================
//  Function Name : IsEmptyImage 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks whether a image field has value or is blank, it returns false if a field 
//  is empty otherwise true. 
//  Parameters: fld : Field name to be check for blank.
//	string msg : Message if field is blank.	
//-------------------------------------------------------------------------------------------
function IsEmptyImage(fld,msg) 
{ 
	if((fld.value == "" || fld.value.length == 0) && (msg=='')) 
	{ 	
		return false; 
	} 
	if(fld.value == "" || fld.value.length == 0) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==============================================================================================
//  Function Name : validateTextArea 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks whether a text field has crossed maxlimit of characters specified in maxlimit 
//  parameter
//  Parameters: fld : Field name to be check for validation.
//	maxlimit : specify maxlimit character in field to be allow.
//	string msg : Message if field is crosses define limit.	
//-----------------------------------------------------------------------------------------------
function validateTextArea(fld,maxlimit,msg)
{
	if(fld.value.length > maxlimit) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	}
	return true; 	
}
//==============================================================================================
//  Function Name : Trim 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 21 Sep 2005
//  Purpose : Removes leading and trailing spaces from field values. 
//  Parameters: fld : Field name to be Trim.
//----------------------------------------------------------------------------------------------
function Trim(fld)
{
	while(''+fld.charAt(0)==' ')
		fld=fld.substring(1,fld.length);
	while(''+fld.charAt(fld.length-1)==' ')
		fld=fld.substring(0,fld.length-1);
	while(''+fld.charCodeAt(0)==13 || ''+fld.charCodeAt(0)==10)
		fld=fld.substring(1,fld.length);
	while(''+fld.charCodeAt(fld.length-1)==13 || ''+fld.charCodeAt(fld.length-1)==10)
		fld=fld.substring(0,fld.length-1);
	return fld;
}
//=============================================================================================
//  Function Name : IsSelected 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks whether a option is selected, it returns false if a option 
//  is selected otherwise true. 
//  Parameters: fld : Field name to be check for selection.
//	string msg : Message if field is selection.	
//---------------------------------------------------------------------------------------------
function IsSelected(fld,msg) 
{ 
	if(fld.value == "" || fld.value == "0" || fld.value.length == 0) 
	{ 
		alert(msg); 
		return false; 
	} 
	return true; 
} 
//=============================================================================================
//  Function Name : IsEmail 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks Email validity. Email must have character @ followed by one or more 
//  dots. It returns flase if Email is invalid otherwise true. 
//  Parameters: fld : Field name to be check for email.
//	string msg : Message if field is not valid email.	
//---------------------------------------------------------------------------------------------
function IsEmail(fld,msg) 
{ 
	fld.value = Trim(fld.value);
	var regex = /^[\w]+(\.)*([a-z0-9A-Z_])+@([a-z0-9A-Z_\-]+\.)+[a-zA-Z]{2,7}(\.[a-zA-Z]){0,10}$/ ; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//=============================================================================================
//  Function Name : IsValidString 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks if field value contains only alphanumeric and '_' charactes. Also checks 
//  that alphabetical chars. and '_' must have to be come first and followed by 
//  numbers. It returns false if above conditions will not satisfy otherwise true. 
//  Parameters: fld : Field name to be check for validation.
//	string msg : Message if field is not valid.	
//---------------------------------------------------------------------------------------------
function IsValidString(fld,msg) 
{ 
	var regex = /^[_]*[a-zA-Z_0-9]+[a-zA-Z0-9_]+$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==============================================================================================
//  Function Name : IsPassword 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks if field value contains only alphanumeric and '_' charactes. Also checks 
//  that alphabetical chars. and '_' must have to be come first and followed by 
//  numbers. It returns false if above conditions will not satisfy otherwise true. 
//  Parameters: fld : Field name to be check for password validation.
//	string msg : Message if field is not valid password.	
//----------------------------------------------------------------------------------------------
function IsPassword(fld,msg) 
{ 
    fld.value = Trim(fld.value);
	var regex = /^[_]*[a-zA-Z]+[0-9]+[a-zA-Z0-9]*$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==============================================================================================
// Function Name : IsLen 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks if field value has number of characters between two specified limits. 
// It returns false if no. of chars. is < min. length or > max. length 
// otherwise true. 
// Parameters: fld : Field name to be check for length validation.
// minlen : Minimum required  field length.
// maxlen : Maximum required  field length.
// string msg : Message if field is not valid password.	
//----------------------------------------------------------------------------------------------
function IsLen(fld, minlen, maxlen, msg) 
{ 
	if(fld.value.length < minlen || fld.value.length > maxlen) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==============================================================================================
// Function Name : IsCurrency 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 26 Sep 2005
// Purpose : checks if Currency value is in proper format i.e. ',' must be after 1(at first place) 
// or 3 digits also dot '.' must be followed by ',' . '$' is optinal as a first char. 
// It returns false if above condition will not satisfy otherwise true. 
// Parameters: fld : Field name to be check for currency validation.
// string msg : Message if field is not valid currency.	
//---------------------------------------------------------------------------------------------
function IsCurrency(fld,msg) 
{ 
	fld.value = Trim(fld.value);
	val = fld.value.replace(/\s/g, ""); 
	regex = /^\d{1,3}(,?\d{3})*(\.\d{1,2})?$/; 

	if(!regex.test(val))
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//=============================================================================================
// Function Name : IsPhone 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks if phone field has following characters : 0-9, '-', '+', '(' , ')' . 
// It returns false if there are other than above characters otherwise true . 
// Parameters : fld1 - area code to be checked 
// : fld2 - city code to be checked 
// : fld3 - actual phone no to be checked 
// msg - error message to be displayed 
//--------------------------------------------------------------------------------------------
function IsPhone(fld1,fld2,fld3,msg) 
{ 
    var regex = /^[0-9]{3}([-. ])[0-9]{3}\1[0-9]{4}$/;
    var phone =  fld1.value + "-" + fld2.value + "-" + fld3.value; 

    if(!regex.test(phone)) 
    { 
        alert(msg); 
        fld1.focus(); 
        return false; 
    } 
    return true; 
} 
function validatePhoneNumber(elementValue)
{  
	var phoneNumberPattern = /^\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})$/;  
	if(!phoneNumberPattern.test(elementValue))
		return false;
	else
		return true;
}

function checkInternationalPhone(strPhone){
    var regex = /^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*([\s-./\\])?([0-9]*)([\s-./\\])?([0-9]*)$/;
    //alert(strPhone.match(regex));
    if (strPhone.match(regex)) {
        return true;
    } else {
        return false;
    }
}
 
//============================================================================================
// Function Name : IsZip 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks if zip field value is of length 5 or 9 . (for U.S. zip code). 
// It returns false if it contains alphabetic chars. or length is not as 
// specified. 
// Parameters: fld : Field name to be check for zipcode validation.
// string msg : Message if field is not valid zipcode.	
//---------------------------------------------------------------------------------------------
function IsZip(fld,msg) 
{ 
	var num = /^[\d]{5}$/;
	
	if(!num.test(fld.value) || (fld.value.length !=5 && fld.value.length !=9)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 

//============================================================================================
// Function Name : isValidZip 
// Created By: Sonali Kasture
// Created On: 20 July
//	Last Modified By: 
//	Last modified On: 
// Purpose : checks if zip field value is of length 5 or 9 . (for U.S. and canadian zip code). 
// It returns false if it contains alphabetic chars. or length is not as 
// specified. 
// Parameters: fld : Field name to be check for zipcode validation.
// string msg : Message if field is not valid zipcode.	
//---------------------------------------------------------------------------------------------
function isValidZip(fld,msg)
{
	var zip=fld.value;
	
	var ZIPCodeDelimiters=" -";
	var lwr="abcdefghijklmnopqrstuvwxyz";
	var upr="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var digits="0123456789";
	var validZIPCodeChars=digits + ZIPCodeDelimiters + lwr+ upr;
	
	var res = isValid(zip,validZIPCodeChars);
	if (res==false)
	{
		alert(msg); 
		fld.focus(); 
		return false;
	}
	return true;
	
	
	/*if (zip.match(/^[0-9]{5}$/)) 
	{
		return true;
	}
	zip=zip.toUpperCase();
	if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) 
	{
		return true;
	}
	if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) 
	{
		return true;
	}*/
}

// checkes all the digits, letters in both the case and the allowed symols in zip code.
function isValid(parm,val)
{
	if(parm=="")return true;
	var cnt=0;
	for(i=0;i<parm.length;i++)
	{
		if(val.indexOf(parm.charAt(i),0)==-1)
		{
			return false;
		}
		else
		{ // checks that the value entered should have atleast one digit.
			if (!allDigits(parm.charAt(i)))
			cnt++;
		}
	}
	if (parm.length == cnt)
	return false;
	if (cnt==0 && parm.length > 5)
	return false;
	return true;
}



//=============================================================================================
// Function Name : IsDate 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks if date is valid according to month selected. 
// i.e. Feb must have 28 or 29 days and also April, June, Sept. and Nov. have 
// 30 days. It returns false if above condition will not satisfy otherwise true. 
// Parameters : m - month field 
// d - day field 
// y - year field 
// msg - error message to be displayed 
//---------------------------------------------------------------------------------------------
function IsDate(m,d,y,msg) 
{ 
	var val1= m.value; 
	var val2= d.value; 
	var val3= y.value; 
	if(val2 > daysInFebruary(val3) && val1 == 02) 
	{ 
		alert(msg); 
		d.focus(); 
		return false; 
	} 
	if((val1 == '04' || val1 == '06' || val1 == '09' || val1 == '11' ) && (val2 > '30')) 
	{ 
		alert(msg); 
		d.focus(); 
		return false; 
	} 
	dt= val1 + '/' + val2 + '/' + val3; 
	return true; 
} 
//=============================================================================================
// Function Name : allDigits 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks if string contains only digits or not. 
// Parameters: fld : Field name to be check for digit validation.
//---------------------------------------------------------------------------------------------
function allDigits(str) 
{ 
	return inValidCharSet(str,"0123456789"); 
} 
//=============================================================================================
// Function Name : inValidCharSet 
// Created By: Ashish shinde
// Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
// Purpose : checks Given string contais only character within Specified chartacter set. 
// Parameters: fld : Field name to be check for character set validation.
// charset : specified character set which need to be checked.	
//---------------------------------------------------------------------------------------------
function inValidCharSet(str,charset) 
{ 
	var result = true; 
	for (var i=0;i< str.length;i++) 
	if (charset.indexOf(str.substr(i,1))<0) 
	{ 
		result = false; 
		break; 
	} 
	return result; 
} 
//=============================================================================================
// Function Name : daysInFebruary 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : To check days in Feb 
// Parameters: fld : Year in which february day count need to check.
//---------------------------------------------------------------------------------------------
function daysInFebruary (year) 
{ 
	// February has 29 days in any year evenly divisible by four, 
	// EXCEPT for centurial years which are not also divisible by 400. 
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); 
} 
//=============================================================================================
// Function Name : checkExpDate 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : Also it checks whether card is expired or not. It returns false if card is 
// expired otherwise true. 
// Parameters: fldMonth : Month field of credit card which need to check.
// fldyear : Year field of credit card which need to check.	
// string msg : Message if expDate is not valid .	
//---------------------------------------------------------------------------------------------
function checkExpDate(fldmonth,fldyear,msg) 
{ 
	var result = true; 
	var expired = false; 
	if (result) 
	{ 
		var month = fldmonth.value; 
		var year = fldyear.value; 
		var now = new Date(); 
		var nowMonth = now.getMonth() + 1; 
		var nowYear = now.getFullYear(); 
		expired = (nowYear > year) || ((nowYear == year ) && (nowMonth > month)); 
	} 
	if (expired) 
	{ 
		result = false; 
		fldmonth.focus(); 
		alert(msg); 
	} 

	return result; 
} 
//============================================================================================
// Function Name : checkFileType 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It checks the file type. It must be either doc or pdf. 
// You can add your customize file extension here for checking 
// Parameters: fld : file extension which need to check.
// string msg : Message if file type is not valid .	
//--------------------------------------------------------------------------------------------
function checkFileType(fld,msg) 
{ 
	var regex = /(.doc|.pdf)$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//============================================================================================
// Function Name : checkImageType 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It checks the image type. It must be either jpg or gif. 
// Parameters: fld : file which need to check.
// string msg : Message if file type is not valid .	
//-------------------------------------------------------------------------------------------
function checkImageType(fld,msg) 
{ 
	var regex = /(.jpg|.jpeg|.JPG|JPEG|.gif|.GIF)$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//===========================================================================================
// Function Name : checkBannerType 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It checks the image type. It must be either jpg or gif. 
// Parameters: fld : file which need to check.
// string msg : Message if file type is not valid .	
//--------------------------------------------------------------------------------------------
function checkBannerType(fld,msg) 
{ 
	var regex = /(.jpg|.jpeg|.JPG|JPEG|.gif|.GIF)$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//============================================================================================
// Function Name : IsUrl 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It check that if url starts with either http:// or https:// 
// Parameters: fld : field which need to check for url validation.
// string msg : Message if url is not valid .	
//---------------------------------------------------------------------------------------------
function IsUrl(fld,msg) 
{ 
	var regex=/^(http:\/\/|https:\/\/)([a-zA-Z0-9:\/._])+$/;
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 




//=============================================================================================
// Function Name : IsFileSize 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It ckecks the size of the image file. 
// YOU CAN CHECK either in terms of width and height of image or size of image in bytes. 
// Parameters: fld : image which need to check.
// string msg : Message if filesize is not valid .	
//--------------------------------------------------------------------------------------------
function IsFileSize(fld,msg) 
{ 
	var img = new Image(); 
	img.src = fld.value; 
	if(img.fileSize > 102400) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//============================================================================================
// Function Name : IsValidColor
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : checks if field value contains only alphanumeric(a to f & 0 to 9). 
// It returns false if above conditions will not satisfy otherwise true. 
// Parameters: fld : field which need to check for color validation.
// string msg : Message if color is not valid .	
//---------------------------------------------------------------------------------------------
function IsValidColor(fld,msg) 
{ 
	var regex = /[a-fA-F0-9]+[a-fA-F0-9]*$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//============================================================================================
// Function Name : IsRadioBtnChecked 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : checks atleast one radion button is selected from array of radio button. 
// Parameters: fld : field which need to check for radio button validation.
// string msg : Message if no radio button is checked .	
//--------------------------------------------------------------------------------------------
function IsRadioBtnChecked(fld,msg) 
{ 
	if(fld.length) 
	{ 
		for(var i=0 ; i<fld.length ; i++ ) 
			if(fld[i].checked) 
				return true; 
		alert(msg); 
		return false; 
	} 
	else 
	{ 
		if(fld.checked) 
			return true; 
		alert(msg); 
		return false; 
	} 
} 

//============================================================================================
// Function Name : IsRadioBtnChecked 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : checks atleast one radion button is selected from array of radio button. 
// Parameters: fld : field which need to check for radio button validation.
// string msg : Message if no radio button is checked .	
//--------------------------------------------------------------------------------------------
/*function IsRadioBtnCheckedNoAlert(fld) 
{ 
	if(fld.length) 
	{ 
		for(var i=0 ; i<fld.length ; i++ ) 
			if(fld[i].checked) 
				var radioSelected = fld[i].value; 
	} 
	else 
	{ 
		if(fld.checked) 
			var radioSelected fld.value; 
	} 
	if (radioSelected!='NO' && radioSelected!='YES') return false;
	return radioSelected;
} */
//===========================================================================================
// Function Name : IsCheckBoxChecked 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : checks atleast one checkbox is checked from array of checkbox.
// Parameters: fld : field which need to check for checkbox validation.
// string msg : Message if no checkbox is checked .	
//-------------------------------------------------------------------------------------------
function IsCheckBoxChecked(fld,msg) 
{ 
	if(fld.length) 
	{ 
		for(var i=0 ; i<fld.length ; i++ ) 
			if(fld[i].checked) 
				return true; 
		alert(msg); 
		return false; 
	} 
	else 
	{ 
		if(fld.checked) 
			return true; 
		alert(msg); 
		return false; 
	} 
} 
//=========================================================================================
// Function Name : getcheckFieldLength 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : returns length of check field 
// Parameters: fld : field which need to check for checked length.
//-----------------------------------------------------------------------------------------
function getcheckFieldLength(fld) 
{ 
	var counter = 0; 
	if(fld.length) 
	{ 
		for(i=0 ; i<fld.length ; i++ ) 
			if(fld[i].checked) 
				counter++; 
		} 
		else 
		{ 
			if(fld.checked) 
				counter++; 
		} 
	return counter; 
} 
//===========================================================================================
// Function Name : unCheckAll 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : uncheck all elements of given field 
// Parameters: fld : field which need to uncheck.
//-------------------------------------------------------------------------------------------
function unCheckAll(fld) 
{ 
	if(fld.length) 
	{ 
		for(i=0 ; i<fld.length ; i++ ) 
			if(fld[i].checked) 
				fld[i].checked = false; 
	} 
	else 
	{ 
		if(fld.checked) 
			fld.checked = false; 
	} 
	return true; 
} 
//===========================================================================================
// Function Name : Clear_CheckboxSelection() 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : uncheck all checkbox field from given form. 
// Parameters: frm : form name whose all checkbox need to uncheck.
//--------------------------------------------------------------------------------------------
function Clear_CheckboxSelection(frm) 
{ 
	with(frm) 
	{ 
		for(var i=0;i<frm.elements.length;i++) 
		{ 
			if(frm.elements[i].type == 'checkbox') 
				frm.elements[i].checked = false; 
		} 
	} 
} 
//============================================================================================
// Function Name : IsPriorDate 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : check given date against current date if date is prior than current date, it will give error. 
// Parameters: fld : date which need to check for prior date validation.
// string msg : Message if no checkbox is checked .	
//---------------------------------------------------------------------------------------------
function IsPriorDate(fld,msg) 
{ 
	today = new Date(); 
	date = today.getDate(); 
	month = today.getMonth() + 1; 
	year = today.getFullYear(); 
	if(date < 10) 
		date = '0'+date; 
	if(month < 10) 
		month = '0'+month; 
	
	var checkdate = ''; 
	checkdate = year+'-'+month+'-'+date; 
	
	if(fld.value < checkdate) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==============================================================================================
// Function Name : IsSubsequentDate 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : check given date against current date if date is successive than current date, it will give error. 
// Parameters: fld : date which need to check for prior date validation.
// string msg : Message if no checkbox is checked .	
//----------------------------------------------------------------------------------------------
function IsSubsequentDate(fld,msg) 
{ 
	today = new Date(); 
	date = today.getDate(); 
	month = today.getMonth() + 1; 
	year = today.getFullYear(); 
	if(date < 10) 
		date = '0'+date; 
	if(month < 10) 
		month = '0'+month; 
	
	var checkdate = ''; 
	checkdate = year+'-'+month+'-'+date; 
	if(fld.value > checkdate) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//============================================================================================
// Function Name : DateAdd 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : This function gives new date by adding supplied days, months and year to supplied date. 
// Parameters: startDate : date in which days,months and year need to add.
// numDays : no of days need to add in given date.
// numMonths : no of months need to add in given date.
// numYears : no of years need to add in given date.
//--------------------------------------------------------------------------------------------
function DateAdd(startDate, numDays, numMonths, numYears) 
{ 
	var returnDate = new Date(startDate.getTime()); 
	var yearsToAdd = numYears; 
	var month = returnDate.getMonth() + numMonths; 
	if (month > 11) 
	{ 
		yearsToAdd = Math.floor((month+1)/12); 
		month -= 12*yearsToAdd; 
		yearsToAdd += numYears; 
	} 
	returnDate.setMonth(month); 
	returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd); 
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays); 
	return returnDate; 
} 
//===========================================================================================
// Function Name : roundAccuracy 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : round no to given accuracy 
// Parameters: num : num which need to round off.
// accuracy : decimal point to which given no need to be round off.
//-------------------------------------------------------------------------------------------
function roundAccuracy(num, accuracy) 
{ 
	var factor=Math.pow(10,accuracy); 
	return Math.round(num*factor)/factor; 
} 
//===========================================================================================
// Function Name : popupWindowURL 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : To open pop window
// Parameters : 
// url = url to be open in the new window 
// winname = winname is the window name for the reference of that window 
// w is the width 
// h is the height 
// menu is the parameter, if you want menubar to be enabled on the window 
// resize if you wanna resize the window 
// scroll if you needed 
// x and y are the co-ordinates where you wld like to show the window on the screen 
// Return : true or false 
//----------------------------------------------------------------------------------------------
function popupWindowURL(url, winname, w, h, menu, resize, scroll, x, y) { 
	if (winname == null) winname = "newWindow"; 
	if (w == null) w = 600; 
	if (h == null) h = 600; 
	if (resize == null) resize = 1; 

	menutype = "nomenubar"; 
	resizetype = "noresizable"; 
	scrolltype = "noscrollbars"; 
	if (menu) menutype = "menubar"; 
	if (resize) resizetype = "resizable"; 
	if (scroll) scrolltype = "scrollbars"; 

	if (x == null || y == null) { 
		cwin=window.open(url,winname,"status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h); 
	} 
	else 
	{ 
		cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h); 
	} 
	if (!cwin.opener) cwin.opener=self; 
		cwin.focus(); 

	return true; 
}

function fnCompare(fld1,fld2,msg)
{
	if(fld1.value != fld2.value)
	{
		alert(msg);
		return false;
	}
	else
		return true;
}
//============================================================================================
// Function Name : autoTab 
// Created By: Ashish shinde
// Created On: 
// Last Modified By: Ashish shinde
// Last modified On: 
// Purpose : It ckecks the size of the image file. 
// YOU CAN CHECK either in terms of width and height of image or size of image in bytes. 
// Parameters: fld : image which need to check.
// string msg : Message if filesize is not valid .	
//--------------------------------------------------------------------------------------------
function autoTab(input, e) 
{
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	if(keyCode=='9' || keyCode=='0') 
	{
		return true;
	}
	return false;
}
function fnGetConfirmation(strMsg,strUrl)
{
	if(confirm(strMsg))
	{
		location.href=strUrl;
	}
}
function fnSubmission(strFormName,strAction)
{
	strFormName.action=strAction;
	strFormName.submit();
}
//============================================================================================
//  Function Name : IsValidString 
//	Created By: Ashish shinde
//	Created On: 
//	Last Modified By: Ashish shinde
//	Last modified On: 
//  Purpose : checks if field value contains only alphanumeric and '_' charactes. Also checks 
//  that alphabetical chars. and '_' must have to be come first and followed by 
//  numbers. It returns false if above conditions will not satisfy otherwise true. 
//  Parameters: fld : Field name to be check for validation.
//	string msg : Message if field is not valid.	
//--------------------------------------------------------------------------------------------
function chkSplChar(fld,msg)
{
	var strParam=fld.value;
	var strPat =/^[a-zA-Z0-9\s#.,_\-']+$/;	
	if(strParam.match(strPat)==null)
	{
		alert(msg+" can't contain Special Characters.");
		fld.focus(); 	
		return false;
	}
	return true;
}
function checkResumeType(fld,msg) 
{ 
	var regex = /(.doc)$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
function fnChkLength(fld,intLength,msg)
{
	if(fld.value.length < intLength)
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}
function fnDateCompare(date1,date2,msg1,msg2)
{
	var dt1=new Date;
	var dt2=new Date;
	var temp1=0;
	var Arrdt=date1.split("-");
	temp1=Arrdt[1]-1;
	dt1.setDate(Arrdt[2]);
	dt1.setMonth(temp1);
	dt1.setFullYear(Arrdt[0]);
	var Arrdt=date2.split("-");
	temp1=Arrdt[1]-1;
	dt2.setDate(Arrdt[2]);
	dt2.setMonth(temp1);
	dt2.setFullYear(Arrdt[0]);
	
	if(dt2<=dt1)
	{
		alert(msg2+" should be greater than "+msg1);
		return false;
	}
	return true;
}
function Isnumber(fld,msg) 
{ 
    fld.value = Trim(fld.value);
	var regex = /^[0-9]*$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 


function FindKeyCode(e)  
{  
	if(e.which)  
	{  
		keycode=e.which;  //Netscape  
	}  
	else  
	{  
		keycode=e.keyCode; //Internet Explorer  
	}   
	return keycode;  
}

/*==========================================================================================
# Function Name:            fngrow()
# Created By:                Sonali Kasture
# Created On:                
# Last Modified By:          Kalim Shaikh   
# Last modified On:          25 Jul 07  
# Purpose:                   To increase height of textarea based on its contents.
#==========================================================================================*/
  
function fngrow(object,e)
{
	if (object.scrollHeight > object.clientHeight && !window.opera)
	{
		object.rows += 1;
       
       while(object.scrollHeight > object.clientHeight)
       {
             object.rows += 1;
        }        
	}
	var vEventKeyCode = FindKeyCode(e); 
    //Copy&Paste content
    if(vEventKeyCode==86)
    {
      
       while(object.scrollHeight > object.clientHeight)
       {
		 	object.rows += 1;
        }
     }
    //Cut content	
     if(vEventKeyCode==88)
     {
		while(object.scrollHeight < object.clientHeight)
        {
 	    	object.rows -= 1;
        }
     }	

     if((vEventKeyCode==8)||(vEventKeyCode==127)||(vEventKeyCode==46))
     {
        if (object.scrollHeight < object.clientHeight && !window.opera)
        {
            while(object.scrollHeight < object.clientHeight)
            {
                object.rows -= 1;
            }
        }
    } 
} 


// function for the object creation for AJAX
function GetXmlHttpObject()
{ 
	var xmlHttp=null;

    try
     {
     // Firefox, Opera 8.0+, Safari
     //xmlHttp=new XMLHttpRequest();
     
        //var httpRequest;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            xmlHttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) { // IE
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
     
     
     
     }
    catch (e)
     {
     // Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    
    return xmlHttp;
}
/**********************************************************************************
	Function Name : form_selected
	Params:
		@obj : field name to validate
	Returns       :  flase if no any option is selected
	Desc: This function is used to check whether any option is selected in the <select> or not
************************************************************************************/
function form_selected(obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj.options[i].value != '' && obj.options[i].selected) return obj.options[i].value;
	}
	return false;
}
function form_isEntered(obj) 
{
    var whitespace = " \t\n\r";
	var s = obj.value;
    if (s.length == 0) {
        // empty field!
        return false;
    } else {
        // check for whitespace now!
        for (var z = 0; z < s.length; z++) {
            // Check that current character isn't whitespace.
            var c = s.charAt(z);
            if (whitespace.indexOf(c) == -1) return true;
        }
        return false;
    }
}
function getCheckedValue(obj)
{
	var user_input = '';
	for (i=0;i<obj.length;i++) {
		if (obj[i].checked) {
			user_input = obj[i].value;
		}
	}
	return user_input;
}
function form_checked(obj)
{
	var tot_checkboxes;
	tot_checkboxes=obj.length;
	flagChk=0;
	for (i=0;i<tot_checkboxes;i++)
	{
		if(obj[i].checked)
		{
			flagChk=1;
			break;
		}
	}
	return flagChk;
}
function fnDateCompare(date1,date2)
{
	var dt1=new Date;
	var dt2=new Date;
	var temp1=0;
	var Arrdt=date1.split("-");
	temp1=Arrdt[1]-1;
	dt1.setDate(Arrdt[2]);
	dt1.setMonth(temp1);
	dt1.setFullYear(Arrdt[0]);
	var Arrdt=date2.split("-");
	temp1=Arrdt[1]-1;
	dt2.setDate(Arrdt[2]);
	dt2.setMonth(temp1);
	dt2.setFullYear(Arrdt[0]);
	if(dt2<dt1)
	{
		return false;
	}
	return true;
}
// This function will allow to type only numbers.
function fnNumbersOnly(event)
{
	if(window.event) 
	{ 
		// if browser is Internet explorer
		key = event.keyCode; 
		if(key == 8 || key ==9 || key == 46)
			return true;
		if(key<48||key>57)
		{
		   return false;
		}	
	}
	else if(event.which)
	{	// if browser is Netscape or mozilla
		key = event.which; 			
		if(key == 8 || key ==9 || key == 46)
			return true;
		if(key <48||key>57)
		{
			alert("Please enter only numeric value");
			return false;	
		}
	}
	else
    {
		// no event, so pass through
		return true;
	}
}
function fnSetAttribute()
{
	var inputs = document.getElementsByTagName("INPUT");
    for(var i=0; i<inputs.length; i++) 
	{
    	inputs[i].setAttribute('autocomplete', 'off');
    }
}

//opens a new popup window containing the image from parameter:
var newWinImg;
function OpenImage(imgFile){
    if (new String(newWinImg)!="undefined" && newWinImg!=null) if (!newWinImg.closed) newWinImg.close();
    var newWinImg=window.open("","ProjectNewWindowImage","width=100,height=100,top=100,left=100,location=no,directories=no,hotkeys=no,copyhistory=no,resizable=no,menubar=no,status=no,toolbar=no,scrollbars=no,z-lock=yes");
    newWinImg.document.write('<html><head><title>Mei Kitchens :: View Photo</title></head><body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" bgcolor="#ffffff" onload="window.resizeTo(parseInt(document.images[\'img\'].width)+10,parseInt(document.images[\'img\'].height)+60)"><img src="' + imgFile + '" name="img" /></body></html>');
    newWinImg.document.close();
    newWinImg.focus();
}

function Trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//Checks for valid name format
function IsValidName(fld,msg) 
{ 
    var regex = /^[a-zA-Z .]+$/; 
    if(!regex.test(fld.value) || Trim(fld.value) == "") 
    { 
        alert(msg); 
        fld.focus(); 
        return false; 
    } 
    return true; 
}



