//######################################################################################################### 
//	# File Name: common.js
//	# File Version: v 1.0
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	# Last Modified By:
//	# Last modified On:
//######################################################################################################### 

//==================================================================================================== 
//  Function Name : IsEmpty 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	Last modified On:
//  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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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]+([\.\-]?\w+)*@([\w]+([\.\-]?\w+))+[a-zA-Z]{2,7}$/ ;
	var regex = /^[\w]+([\.\-]?\w+)*@([\w]+[\.\-])+[a-zA-Z]{2,7}$/ ; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==================================================================================================== 
//  Function Name : IsValidString 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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_]+[a-zA-Z0-9_]+$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==================================================================================================== 
//  Function Name : IsPassword 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	Last modified On:
// 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})?$/; 
	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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 = /^[\d-+]+$/; 

	var phone = "(" + fld1.value + ")" + fld2.value + "-" + fld3.value; 
	if(!regex.test(phone)) 
	{ 
		alert(msg); 
		fld1.focus(); 
		return false; 
	} */
return true; 
} 
//==================================================================================================== 
// Function Name : IsZip 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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]+$/; 
	
	if(!num.test(fld.value) || (fld.value.length !=5 && fld.value.length !=9)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 
//==================================================================================================== 
// Function Name : IsDate 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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 : IsFileSize 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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; 
	// var Dimensions = img.width + 'x' + img.height; 
	// var File Size = img.fileSize; 
	if(img.fileSize > 102400) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 

	return true; 
} 
//==================================================================================================== 
// Function Name : IsValidColor
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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 : IsCheckBoxChecked 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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();
	//strFormName.
	//eval("document."+strFormName+".action="+strAction);
	//eval("document."+strFormName+".submit()");
	
}
//==================================================================================================== 
//  Function Name : IsValidString 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	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#.,']+$/;
		var strPat =/^[a-zA-Z0-9\s#.,_\-\/\']+$/;
	
		if(fld.value.length>0)
		{
			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 checkZip(fld,msg) 
{ 
	var regex = /(.zip|.ZIP)$/; 
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 

function chk_date_new(strdate,message)
{
			var temp=strdate;
				
			var dt =new Date;	
			var Arrdt=temp.split("-");			
			var temp=0;
			var temp1=0;		
			var temp2=0;
			temp=Arrdt[1];
			temp1=Arrdt[2];
			temp2=Arrdt[0];
			
			var regex = /^[0-9]*$/; 
			if(!regex.test(temp) || !regex.test(temp1) || !regex.test(temp2)) 
			{ 
				alert("Please Enter Date in Numeric form"); 				
				return false; 
			}			
			if(temp>12)
			{
				alert(message);			
				return false;
			}
			if(temp==4 || temp==6 || temp==9 || temp==11)
			{
				if(temp1>30)
				{
						alert(message);
						return false;
				}
			}
			if(temp==1 || temp==3 || temp==5 || temp==7 || temp==8 || temp==10 || temp==12)
			{
				if(temp1>31)
				{
						alert(message);					
						return false;
				}
			}
			if(temp==2)
			{
				if(temp1>29 ||(temp1==29 && temp2%4!=0 ))
				{
					alert(message);					
					return false;
				}
			}
		return true;
}

function ShowMemberdiv(divname)
{
		
	if(divname=='profile')
	{
	   	document.getElementById('member_profile').className = "selected";
	   	document.getElementById('member_contact').className = "";
		document.getElementById('profile').style.display= "";
		document.getElementById('contact').style.display= "none";	
	}
	else
	{
		document.getElementById('member_contact').className = "selected";
		document.getElementById('member_profile').className = "";
		document.getElementById('contact').style.display= "";
		document.getElementById('profile').style.display= "none";	
	}
}//function 	

function getTodaysDate()
{
	var today = new Date();
	var m_names = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");

	var curr_date = today.getDate();
	if (curr_date < 10)
	{
		curr_date = "0"+curr_date;
	}
	var curr_month = today.getMonth();
	var curr_year = today.getFullYear();
	var CurrentDate = curr_year + "-" + m_names[curr_month] + "-" + curr_date;

	return(CurrentDate);
}

//==================================================================================================== 
//  Function Name : CountWords 
//	# Created By: Maulik Chandarana
//	# Created On: 20 March 2007
//	Last Modified By:
//	Last modified On:
//  Purpose : To count number of words in atext enetered
//  Parameters: this_fld : Field name to count nuber of words.
//---------------------------------------------------------------------------------------------------- 
function CountWords (this_field, show_word_count, show_char_count)
{
	if (show_word_count == null)
	{
		show_word_count = true;
	}
	if (show_char_count == null) 
	{
		show_char_count = false;
	}
	var char_count = this_field.value.length;
	var fullStr = this_field.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	if (fullStr.length <2) 
	{
		word_count = 0;
	}
	if (word_count == 1) 
	{
		wordOrWords = " word";
	}
	else
	{
		wordOrWords = " words";
	}
	if (char_count == 1) 
	{
		charOrChars = " character";
	}
	else 
	{
		charOrChars = " characters";
	}
	/*if (show_word_count & show_char_count) 
	{
		alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
	}
	else 
	{
		if (show_word_count) 
		{
			alert ("Word Count:  " + word_count + wordOrWords);
		}
		else 
		{
			if (show_char_count) 
			{
				alert ("Character Count:  " + char_count + charOrChars);
			}
		}
	}*/
	return word_count;
}

function getHTTPObject() {
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function checkSpecialCharacters(fieldName, message)
{
	exp=/^[a-zA-Z ]+$/;
	if(exp.test(fieldName.value)!=true)
	{
		alert(message);
		fieldName.focus();
		return false;;
	}
	else
	{
		return true;
	}
}

function chkSplChars(fieldName, message)
{
	exp=/^[a-zA-Z,\.\"\'\-\!\;\(\)\? ]+$/;
	if(exp.test(fieldName.value)!=true)
	{
		alert(message);
		fieldName.focus();
		return false;;
	}
	else
	{
		return true;
	}
}
function IsUrl(fld,msg) 
{ 
	//var regex = /^(http:\/\/|https:\/\/)/; 
	//var regex = /^(http:\/\/|https:\/\/)[A-Z0-9]$/; 
	var regex=/^(http:\/\/|https:\/\/)([a-zA-Z0-9:\/._])+$/;
	if(!regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
} 

function IsDisplayUrl(fld,msg) 
{ 
	//var regex = /^(http:\/\/|https:\/\/)/; 
	//var regex = /^(http:\/\/|https:\/\/)[A-Z0-9]$/; 
	var regex=/^(http:\/\/|https:\/\/)([a-zA-Z0-9:\/._])+$/;
	if(regex.test(fld.value)) 
	{ 
		alert(msg); 
		fld.focus(); 
		return false; 
	} 
	return true; 
}
function fnIsAllLower(strURL) 
{ 
	// define regular expression matching pattern 
	strPattern = "([A-Z].*)"; 

	// create object of RegExp Class 
	objRegExp = new RegExp(strPattern); 
	boolResult = objRegExp.test(strURL); // test that given string is according to pattern 
	if (boolResult)
	{
		return false; 
	}
	else
	{
		return true;
	}
} 

function checkSpecialCharacters(fieldName, message)
{
	exp=/^[a-zA-Z ]+$/;
	if(exp.test(fieldName.value)!=true)
	{
		alert(message);
		fieldName.focus();
		return false;;
	}
	else
	{
		return true;
	}
}

function chkSplChars(fieldName, message)
{
	exp=/^[a-zA-Z,\.\"\'\-\!\;\(\)\? ]+$/;
	if(exp.test(fieldName.value)!=true)
	{
		alert(message);
		fieldName.focus();
		return false;;
	}
	else
	{
		return true;
	}
}
//====================================================================================================
//	Function Name	:	fnIsFirstCharUpper()
//	Created By: Maulik Chandarana
//	Created On: 21 March 2007
//	Last Modified By:
//	Last modified On:
//  Purpose : To check whether the first character of each word is in Upper case or not
//  Parameters: fld: Field Name
//				msg: Message to display if function returns the false value
//----------------------------------------------------------------------------------------------------
function fnIsFirstCharUpper(fld, msg) 
{ 
	var str = fld.value;
	arrString = str.split(" ");
	// define regular expression matching pattern 
	strPattern = "([A-Z].*)"; 

	// create object of RegExp Class 
	objRegExp = new RegExp(strPattern); 

	for(var i=0;i<arrString.length;i++)
	{	
		charToCheckForUpper = arrString[i].substr(0, 1);
		boolResult = objRegExp.test(charToCheckForUpper); // test that given string is according to pattern 
		
		if (!boolResult)
		{
			alert(msg);
			fld.focus();
			return false;
		}
	}
	return true;
}
//==================================================================================================== 
//  Function Name : IsValidPassword 
//    # Created By: Maulik Chandarana
//    # Created On: 15 May 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : checks if field value contains any space in entered value
//  Parameters: fld : Field name to be check for password validation.
//    string msg : Message if field is not valid password.    
//---------------------------------------------------------------------------------------------------- 
function IsValidPassword(fld,msg) 
{ 
    var str = fld.value;
    for(var i=0;i<str.length;i++)
    {
        if(str.substr(i,1) == " ")
        {
            alert(msg);
            fld.focus();
            return false;
        }
    }
    return true; 
}  