// JScript source code

var sNameExp="^[\s]*[a-z][a-z\"\s{0,1}]*[\s]*$";
var sNumericExp = "^[\\s]*[0-9]+[\\s]*$";
//var sNumericExp = "^[\s]*[0-9]*$";
//var sAlphaNumExp = "^[\s]*[a-z][a-z|0-9|\s\"]*[\s]*$";
var sAlphaNumExp = "(\w)*";
//var sAddressExp = "^[\s]*[\s]*.*[\s]*[\s]*$";
//var sCityExp = "^[\s]*[a-z][a-z\-\"\_\s]*[a-z\-\"\_][\s]*$";
//var sEmailExp = "^[\s]*[a-z][a-z_0-9\.]*[a-z|0-9]?@[a-z|0-9|\-]+[\.][a-z_0-9\-\.]*[a-z][a-z]([a-z])?[\s]*$";
var sEmailExp = "^[\s]*[a-z][a-z_0-9\.]*[a-z|0-9]?@[a-z|0-9|\-]+[\.]([a-z][a-z][a-z]?)[\s]*$";
//var sPhoneExp = "^[\s]*\d{3}-[a-z|0-9]{3}-[a-z|0-9]{4}[\s]*$|^[\s]*\d{3}\.[a-z|0-9]{3}\.[a-z|0-9]{4}[\s]*$|^[\s]*\d{3}-[a-z|0-9]{3}-[a-z|0-9]{4}-[0-9]+[\s]*$|^[\s]*\d{3}-[a-z|0-9]{3}\.[a-z|0-9]{4}\.[0-9]+[\s]*$";
//var sPhoneExp   = "^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$";
var sAlphaExp = "^[\s]*[a-z]+[\s]*$";
//var sAmountExp = "^[\s]*[0-9]+([\.]?[0-9]+)?[\s]*$";
//var sZipExp = "^[\s]*\d{5}[\s]*$|^[\s]*\d{5}[\-\s]?\d{4}[\s]*$";
var sZipExp = "^[0-9][0-9][0-9][0-9][0-9][0-9]$";
//var sAlphaNumWithConExp = "^[\s]*[a-z][a-z|0-9|\s|_|\"]*[\s]*$";
//var sTimeExp="^(([0]?[0-9])|([1][0|1|2])):[0|1|2|3|4|5][0-9][A|P]][M]$"
//var sTimeExp = "^([0-1][0-9]:([0|1|2|3|4|5])[0-9][A|P][M])|([1][0|1|2]:([0|1|2|3|4|5])[0-9][A|P][M])$"


//***********added by shalaka -TQMS PROJ**************************************************************
var sAlphaNumWithBraketExp = "^[\s]*[a-z]+[\(|a-z\-\a-z|0-9|,|.| \)]*[a-z| ]*$"
var sCompanyNameExp = "^[\s]*[a-z]+[\(|a-z\-\a-z|0-9|,|.| \)|&|/]*[a-z| ]*$"

var sRoleNameExp = "^[\s]*[a-z]+[\(|a-z\-\a-z|0-9|.| \)|\|/]*[a-z| ]*$"
//var sRoleNameExp = "^[a-z]+[a-z\-\a-z|0-9]*[a-z]*$"
//var sRoleNameExp = "^[\s]*[a-z]+[a-z\-\a-z|0-9|.| \|/]*[a-z| ]*$"

//var sTimeWithSpaceExp = "^([0|1]?[0-9]:([0|1|2|3|4|5])[0-9][ ][A|P][M])|([1][0|1|2]:([0|1|2|3|4|5])[0-9][ ][A|P][M])$" //Changed by Sunil.
var sTimeWithSpaceExp = "^([0|1]?[0-9]:([0|1|2|3|4|5])[0-9])|([1][0|1|2]:([0|1|2|3|4|5])[0-9])$"
var sAlphaWithSpaceExp = "^[\s]*[a-z]+[a-z| ]*[\s]*$";
var sAlphaWithApostropheExp = "^[\s]*[a-z]+[a-z|']*[\s]*$";
var sAlphaWithSpaceApostropheExp = "^[\s]*[a-z]+[a-z| |']*[\s]*$";
var sAlphaNumericWithSpaceExp = "^[\s]*[a-z]+[a-z|0-9| ]*[\s]*$";
var sDescriptionFieldExp = "^[\s]*[^<>]*[\s]*$";
var sAlphaWithSpaceApostropheDotExp = "^[\s]*[a-z]+[a-z| |.|']*[\s]*$";
var sAlphaWithSpaceDotExp = "^[\s]*[a-z]+[a-z| |.]*[\s]*$";
var sChargesExp = "^[\s]*([0-9]{1,5})+([\.]?([0-9]{1,2}))?[\s]*$";
var sWorkExperienceExp = "^[\s]*([0-9]{1,2})+([\.]?([0-9]{1,2}))?[\s]*$";
//var sPostalCodeExp = "^[\s]*(([0-9]{3})([ ]{1})([0-9]{3})){1}[\s]*$";
var sPostalCodeExp = "^[\s]*(([0-9]{1,6})){1}[\s]*$";
var sEmailNameExp = "^[\s]*([a-zA-Z]*[a-z|A-Z|0-9\-\_\.])*[\s]*$";
var sAlphaNumWithHyphenUnderScoreExp = "^[\s]*([a-zA-Z]*[a-z|A-Z|0-9\-\_])*[\s]*$";
var sDepartmentExp = "^[\s]*[a-zA-Z]*[a-zA-Z\ \&\(\)\-\.\#\[0-9]+]*[\s]*$";
var sJobTitleExp = "^[\s]*[a-zA-Z]*[a-zA-Z|0-9| \&\(\)\-\.\#\,\/]*[\s]*$";
var sQuizNameExp = "^[\s]*[^<>]*[\s]*$";
var sStructureExp = "^[\s]*[^<>]*[\s]*$";

// Added by Satish
// Date: 21 Jun 2005
// Remarks: for Checking the Notification Message in NoticationTemplate Module
// modification by satish starts here
var sDescriptionFieldExpForNotificationTemplate = "^[\s]*[^<>]*[\s]*$";
// modification by satish ends here
//*********End********************************************************************************************


sNameExp = sAlphaNumExp; //a suggestion. 

//**********************************************

var s_Message = " is invalid"

//**********************************************

var sName_Message = s_Message + ". It should contain only alphabets without any space.";
var sEmail_Message = s_Message +". It should be in the format: username@domainname.xyz";
var sNumeric_Message = s_Message + ". It should contain only numbers.";
var sAlpha_Message = s_Message + ". It should contain only alphabets.";
var sAlphaNum_Message = sName_Message;

//var sAddress_Message = s_Message;
//var sCity_Message = s_Message;
//var sPhone_Message = s_Message +". It should be in the following format: 111-111-1111";
//var sAmount_Message = s_Message + ". It should contain only number with a maximum of two decimal places.";
var sZip_Message = s_Message +". It should be numeric and six digits.";
//var sAlphaNumWithCon_Message = sName_Message;
//var sTime_Message = s_Message + ". It should be in the following format: HH:MM AM or HH:MM PM.";

//***********added by shalaka -TQMS PROJ**************************************************************
var sInitials_Message =" are invalid" +  ". It should contain only alphabets.";
var sAlphaNumWithBraket_Message = s_Message +". It should be a combination of alphabets, numbers, -, dot(.), comma, (, ) and should start with an alphabet.";

var sCompanyName_Message = s_Message +". It should be a combination of alphabets, numbers, -, dot(.), comma(,), &, / and should start with an alphabet.";
var sRoleName_Message = s_Message + ". It should be a combination of alphabets, numbers, -, and should start with an alphabet.";
var sTimeWithSpace_Message = s_Message + ". It should be in the format: HH:MM AM or HH:MM PM.";
var sAlphaWithSpace_Message =  s_Message + ". It should contain only alphabets and space and should start with an alphabet.";
var sAlphaWithApostrophe_Message = s_Message + ". It should contain only alphabets and apostrophe and should start with  an alphabet.";
var sAlphaWithSpaceApostrophe_Message = s_Message + ". It should contain only alphabets, space and apostrophe and should start with an alphabet." ;
var sAlphaNumericWithSpace_Message = s_Message + ". It should contain only alphabets, numbers and space and should start with an alphabet.";
var sDescriptionField_Message = s_Message + ". It should not contain '< , >' these letters.";
var sAlphaWithSpaceApostropheDot_Message =  s_Message + ". It should contain only alphabets, space, dot and apostrophe and should start with an alphabet." ;
var sAlphaWithSpaceDot_Message =  " are invalid" + ". It should contain only alphabets, space and dot and should start with an alphabet." ;
var sCharges_Message = ". It should be in the format 'XXXXX.XX'" ;
var sWorkExperience_Message = s_Message + ". It should contain number in the format of 'YY.MM'."  ;
var sPostalCode_Message = s_Message + ". It should contain only numbers and maximum of six digits.";
var sEmailName_Message = s_Message + ".  It should be a combination of alphabets, integers, -, _ , dot(.) and should start with an alphabet."; 
var sAlphaNumWithHyphenUnderScore_Message=s_Message + ".  It should be a combination of alphabets, integers,hyphen(-),underscore(_) and should start with an alphabet."; 
var sDepartment_Message = s_Message + ". It should be a combination of alphabets, space, -, &, dot(.),(, ), # and should start with an alphabet.";
var sJobTitle_Message = s_Message + ". It should be a combination of alphabets, numbers, space, -, &, dot(.),comma, (, ), #, / and should start with an alphabet.";
var sQuizName_Message = s_Message + ". It should not contain '< , >' these letters.";
var sStructure_Message = s_Message + ". It should not contain '< , >' these letters.";

// Added by Satish
// Date: 21 Jun 2005
// Remarks: for Checking the Notification Message in NoticationTemplate Module
// modification by satish starts here
var sDescriptionFieldExpForNotificationTemplate_Message = s_Message + ". It should not contain '< , >' these letters.";
// modification by satish ends here

//****************************************************************************************************


var sAlphaNum_Message = sName_Message;
//****************************************************************************************************
var startdate;
var enddate;
var startday;
var startmonth;
var startyear;
var duration = 0;	

var starthr;
var startmin;
var startam;
var endhr;
var endmin;
var endam;
			

function _isInteger(val){var digits="1234567890";for(var i=0;i < val.length;i++){if(digits.indexOf(val.charAt(i))==-1){return false;}}return true;}

function _getInt(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length < minlength){return null;}if(_isInteger(token)){return token;}}return null;}

function getDateFromFormat(val,format){val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var now=new Date();var year=now.getYear();var month=now.getMonth()+1;var date=1;var hh=now.getHours();var mm=now.getMinutes();var ss=now.getSeconds();var ampm="";while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(token=="yyyy" || token=="yy" || token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=_getInt(val,i_val,x,y);if(year==null){return 0;}i_val += year.length;if(year.length==2){if(year > 70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM"||token=="NNN"){month=0;for(var i=0;i<MONTH_NAMES.length;i++){var month_name=MONTH_NAMES[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){if(token=="MMM"||(token=="NNN"&&i>11)){month=i+1;if(month>12){month -= 12;}i_val += month_name.length;break;}}}if((month < 1)||(month>12)){return 0;}}else if(token=="EE"||token=="E"){for(var i=0;i<DAY_NAMES.length;i++){var day_name=DAY_NAMES[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val += day_name.length;break;}}}else if(token=="MM"||token=="M"){month=_getInt(val,i_val,token.length,2);if(month==null||(month<1)||(month>12)){return 0;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=_getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return 0;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return 0;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23)){return 0;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return 0;}i_val+=hh.length;}else if(token=="kk"||token=="k"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return 0;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=_getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return 0;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=_getInt(val,i_val,token.length,2);if(ss==null||(ss<0)||(ss>59)){return 0;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return 0;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return 0;}else{i_val+=token.length;}}}if(i_val != val.length){return 0;}if(month==2){if( ((year%4==0)&&(year%100 != 0) ) ||(year%400==0) ){if(date > 29){return 0;}}else{if(date > 28){return 0;}}}if((month==4)||(month==6)||(month==9)||(month==11)){if(date > 30){return 0;}}if(hh<12 && ampm=="PM"){hh=hh-0+12;}else if(hh>11 && ampm=="AM"){hh-=12;}var newdate=new Date(year,month-1,date,hh,mm,ss);return newdate.getTime();}

function compareDates(date1,dateformat1,date2,dateformat2){var d1=getDateFromFormat(date1,dateformat1);var d2=getDateFromFormat(date2,dateformat2);if(d1==0 || d2==0){return -1;}else if(d1 > d2){return 1;}return 0;}

function GetDateConvertedInMilliseconds(date1,dateformat1)
{
	var dateInMilliseconds = getDateFromFormat(date1,dateformat1);
	return dateInMilliseconds;
}
//*************************************************** Time Comparison Function Starts Here. **************
// Developer should give call to CompareTimes() function to compare 2 times.
// formElementDuration specifies special condition if there is time comparison considered for more than 1 day.
// This function accepts i/p Date in DD/MM/YYYY Format & computes end date in DD/MM/YYYY Format
// and assign to the form control passed in formal parameter End Date.

			function TimeCheck(formElementStartTime,strStartTime,formElementDuration,strEndTime)
			{
				var fStart;
				var fEnd;
				var bErrorFlag=false;
				
				starttime = strStartTime;
				endtime = strEndTime;
				
				startam = starttime.substring(starttime.indexOf(" ")+1,starttime.length);
				endam = endtime.substring(endtime.indexOf(" ")+1,endtime.length);
								
				if((startam.toUpperCase() == "PM") && (endam.toUpperCase() == "AM"))
				{
					bErrorFlag=true;
				}
				else if(((startam.toUpperCase() == "AM") && (endam.toUpperCase() == "AM")) || ((startam.toUpperCase() == "PM") && (endam.toUpperCase() == "PM")))
				{
					if(starttime.indexOf(":") != -1)
					{
						starttime = strStartTime.replace(":",".");
					}
					fStart = parseFloat(starttime);
					
					if(endtime.indexOf(":") != -1)
					{
						endtime = strEndTime.replace(":",".");
					}
					fEnd = parseFloat(endtime)
					
					if(fStart >= fEnd)
					{
						bErrorFlag=true;
					}
				}
				
				if(bErrorFlag)
				{
					alert("'Start Time' should always be less than 'End Time'.");
					formElementStartTime.focus();		
					return false;
				}
				else
				{
					return true;
				}
				
				//parsing starttime 				
				/*
				startlen = starttime.length;
				
				while(startlen > 0)
				{
					starthr = parseInt(starttime.substring(0,starttime.indexOf(":")), 10);
					startmin = parseInt(starttime.substring(starttime.indexOf(":")+1,starttime.indexOf(" ")), 10);
					startam = starttime.substring(starttime.indexOf(" ")+1,starttime.length);
					startlen = startlen - 1;
				}
							
				//parsing endtime 				
				endlen = endtime.length;
				
				while(endlen > 0)
				{
					endhr = parseInt(endtime.substring(0,endtime.indexOf(":")), 10);
					endmin = parseInt(endtime.substring(endtime.indexOf(":")+1,endtime.indexOf(" ")), 10);
					endam = endtime.substring(endtime.indexOf(" ")+1,endtime.length);
					endlen = endlen - 1;
				}
				
				//chking validity				
				if((startam.toUpperCase()) == "AM")
				{
					if((endam.toUpperCase()) == "AM")
					{
						if(ValidateTime(formElementStartTime))
							return true;
						else 
							return false;
					}
				}
				else
				if((startam.toUpperCase()) == "PM")
				{
					if((endam.toUpperCase()) == "AM")
					{
						if(parseInt(formElementDuration.value) == 1)
						{
							alert("Since 'Start Date' and 'End Date' is same, 'Start Time' should always be less than 'End Time'.");
							formElementStartTime.focus();
							return false;
						}	
					}
					else
					if((endam.toUpperCase()) == "PM")
					{
						if(ValidateTime(formElementStartTime))
							return true;
						else 
							return false;
					}
				}					
				return true;
				*/
			}	

			function ValidateTime(formElementStartTime)
			{
				if(starthr > endhr)
				{
					if((startam == "AM" && starthr == 12))
					{
						return true;
					}
					if (startam != "PM" && endam !="PM")
					{
							alert("'Start Time' should always be less than 'End Time'.");
							formElementStartTime.focus();		
							return false;
					}
				}
				else if(starthr == endhr)
				{
					if(startmin >= endmin)
					{
						alert("'Start Time' should always be less than 'End Time'");
						formElementStartTime.focus();		
						return false;
					}
				}				
				return true;
			}

//*************************************************** Time Comparison Function Ends Here. **************

//*************************************************** Date Computation Function Starts Here. ************

// Developer should give call to NextDate()function to get Start Date + Duration = End Date.
// This function accepts i/p Date in DD/MM/YYYY Format & computes end date in DD/MM/YYYY Format
// and assign to the form control passed in formal parameter End Date.	
			
/*
			function NextDate(formElementStartDate,formElementDuration,formElementEndDate)
			{
				ParseStartDate(formElementStartDate,formElementDuration);
				startday = startday + duration -1;
				CalculateNextDate(formElementEndDate);
			}

			function ParseStartDate(formElementStartDate,formElementDuration)
			{
			
				startdate = formElementStartDate.value;
				startlen = startdate.length;
				while(startlen > 0)
				{
					startday = parseInt(startdate.substring(0,startdate.indexOf("/")),10);
					startmonth = parseInt(startdate.substring(startdate.lastIndexOf("/",startdate.length), startdate.indexOf("/") + 1),10);
					startyear = parseInt(startdate.substring(startdate.lastIndexOf("/",startdate.length) + 1,startdate.length),10);
					startlen = startlen - 1;
				}
				duration = parseInt(formElementDuration.value);
			}	

*/		
			function NextDate(StartDate,formElementDuration,formElementEndDate)
			{
				ParseStartDate(StartDate,formElementDuration);
				startday = startday + duration -1;
				CalculateNextDate(formElementEndDate);
			}

			function ParseStartDate(startdate,formElementDuration)
			{
				startlen = startdate.length;
				while(startlen > 0)
				{
					startday = parseInt(startdate.substring(0,startdate.indexOf("/")),10);
					startmonth = parseInt(startdate.substring(startdate.lastIndexOf("/",startdate.length), startdate.indexOf("/") + 1),10);
					startyear = parseInt(startdate.substring(startdate.lastIndexOf("/",startdate.length) + 1,startdate.length),10);
					startlen = startlen - 1;
				}
				duration = parseInt(formElementDuration.value);
			}	
			
			
			function CalculateNextDate(formElementEndDate)
			{
				if((startmonth > 2 && startmonth <= 7) || startmonth == 1 )
				{
					if((startmonth % 2) == 0  )
					{
						CallDays(30,formElementEndDate);		
					}
					else
					if((startmonth % 2) != 0)
					{
						CallDays(31,formElementEndDate);
					}
				}
				else
				if(startmonth > 7 && startmonth <= 12)
				{
					if((startmonth % 2) == 0  )
					{
				 		CallDays(31,formElementEndDate);
					}
					else
					if((startmonth % 2) != 0)
					{
						CallDays(30,formElementEndDate);
					}
				}
				else
				if(startmonth == 2)
				{
					if((((startyear % 4 ) == 0) || ((startyear % 400 ) == 0)) && (((startyear % 100 ) != 0)))
					{
						CallDays(29,formElementEndDate)
					}
					else
					if((startyear % 4 ) != 0)
					{
						CallDays(28,formElementEndDate)
						
					}
				}
			}			
			
			function CallDays(iDay,formElementEndDate)
			{
				if(startday <= iDay)
				{	
					formElementEndDate.value = startday.toString() + "/" + startmonth.toString() + "/" + startyear.toString();
				}
				else
					CalculateDays(iDay,formElementEndDate);
			}	
			
			function CalculateDays(iDay,formElementEndDate)
			{
				if(startday >= iDay)
				{
					startday = startday - iDay;
					startmonth = startmonth + 1;
					if(startmonth > 12)
					{
						startmonth = 1;
						startyear = startyear + 1;
					}
					if(startday >= iDay  || startmonth == 2)
					{
						CalculateNextDate(formElementEndDate);
					}
					else
						formElementEndDate.value = startday.toString() + "/" + startmonth.toString() + "/" + startyear.toString();
				}
			}
			
//*************************************************** Date Computation Function Ends Here. ************

function bValidate(formElement, validationType, isMandatory, alertName)
{
	switch(validationType){
			case "Alpha":
				if(bCheck(formElement, sAlphaExp, isMandatory, alertName, sAlpha_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			
			case "Numeric":
				if(bCheck(formElement, sNumericExp, isMandatory, alertName, sNumeric_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaNum":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is invalid format.Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumExp , isMandatory, alertName, sAlphaNum_Message)==false){
					formElement.focus();
					return false;
				}
			break;				
			
		  case "":
				if(isMandatory == "True"){		
					if (formElement.value==""){
						alert(alertName + " cannot be blank.");
						formElement.focus();
						return false;
					}
				}
			break;	
			/*
			case "Time":

				//Hack added to add a 0 if time is not in a proper format
				if(objForm.elements[iCount].value.substring(0,objForm.elements[iCount].value.indexOf(':')).length == 1){
					objForm.elements[iCount].value='0'+objForm.elements[iCount].value;
				}				
				//End of Hack 

				if(bCheck(objForm.elements[iCount],sTimeExp,sTime_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}
			
			break;  	*/
			//***********added by shalaka -TQMS PROJ**************************************************************
			
			case "Initials":
				if(bCheck(formElement, sAlphaExp, isMandatory, alertName, sInitials_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "DescriptionField":
				if(bCheck(formElement, sDescriptionFieldExp, isMandatory, alertName, sDescriptionField_Message)==false){
				formElement.focus(); 
				return false;}
				
				if(formElement.value.length > 255 ) {
						alert(alertName + " should not contain more than 255 characters.");
						formElement.focus();
						return false;
					}
				
			break;
			

			case "DescriptionFieldWithoutNumberofCharacterRestriction":
				if(bCheck(formElement, sDescriptionFieldExp, isMandatory, alertName, sDescriptionField_Message)==false){
				formElement.focus(); 
				return false;}
			break;

			// Added by Satish
			// Date: 21 Jun 2005
			// Remarks: for Checking the Notification Message in NoticationTemplate Module
			// modification by satish starts here
			case "DescriptionFieldExpForNotificationTemplate":
				if(bCheck(formElement, sDescriptionFieldExpForNotificationTemplate, isMandatory, alertName, sDescriptionFieldExpForNotificationTemplate_Message)==false){
				formElement.focus(); 
				return false;}
			break;
			// modification by satish ends here
			
			case "QuizName":
				if(bCheck(formElement, sQuizNameExp, isMandatory, alertName, sQuizName_Message)==false){
				formElement.focus(); 
				return false;}
				
				if(formElement.value.length > 100 ) {
						alert(alertName + " should not contain more than 100 characters.");
						formElement.focus();
						return false;
					}
				
			break;
			case "Structure":
				if(bCheck(formElement, sStructureExp, isMandatory, alertName, sStructure_Message)==false){
				formElement.focus(); 
				return false;}
				
				if(formElement.value.length > 50 ) {
						alert(alertName + " should not contain more than 50 characters.");
						formElement.focus();
						return false;
					}
				
			break;
	
				
			case "CompanyName":
				if(formElement.value.indexOf("  ")>0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sCompanyNameExp, isMandatory, alertName, sCompanyName_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaNumWithBraket":
				if(formElement.value.indexOf("  ")>0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumWithBraketExp, isMandatory, alertName, sAlphaNumWithBraket_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			
			case "RoleName":
				if(formElement.value.indexOf("  ")>0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sRoleNameExp, isMandatory, alertName, sRoleName_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			
			case "AlphaWithApostrophe":
				if(formElement.value.indexOf("''") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive apostrophe are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithApostropheExp, isMandatory, alertName, sAlphaWithApostrophe_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaWithSpaceApostrophe":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("''") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive apostrophe are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithSpaceApostropheExp, isMandatory, alertName, sAlphaWithSpaceApostrophe_Message)==false){
					formElement.focus();
					return false;
				}
			break;

			case "AlphaWithSpace":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithSpaceExp, isMandatory, alertName, sAlphaWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "TimeWithSpaceExp":
				if(bCheck(formElement, sTimeWithSpaceExp, isMandatory, alertName, sTimeWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaNumericWithSpace":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumericWithSpaceExp, isMandatory, alertName, sAlphaNumericWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaWithSpaceApostropheDot":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..") > 0)
				{
					alert(alertName + " is invalid format. Consecutive dots are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("''") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive apostrophe are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithSpaceApostropheDotExp, isMandatory, alertName, sAlphaWithSpaceApostropheDot_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaWithSpaceDot":
				if(formElement.value.indexOf("  ") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive spaces are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..") > 0)
				{
					alert(alertName + " is invalid format. Consecutive dots are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithSpaceDotExp, isMandatory, alertName, sAlphaWithSpaceDot_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "EmailName":
			//alert("hello email");	
			if(formElement.value.indexOf("..") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive dots are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("__")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sEmailNameExp, isMandatory, alertName, sEmailName_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaNumWithHyphenUnderScore":
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphens are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("__")>0)
				{
					alert(alertName + " is in invalid format. Consecutive underscores are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumWithHyphenUnderScoreExp, isMandatory, alertName, sAlphaNumWithHyphenUnderScore_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "Department":
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive dots are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("##") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive hash are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sDepartmentExp, isMandatory, alertName, sDepartment_Message)==false){
					formElement.focus();
					return false;
				}
			break;			
			
			case "JobTitle":
				if(formElement.value.indexOf("--")>0)
				{
					alert(alertName + " is in invalid format. Consecutive hyphen are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("..") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive dots are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("##") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive hash are not allowed.");
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf(",,") > 0)
				{
					alert(alertName + " is in invalid format. Consecutive commas are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sJobTitleExp, isMandatory, alertName, sJobTitle_Message)==false){
					formElement.focus();
					return false;
				}
			break;			
				
			case "PostalCode":
				if(bCheck(formElement, sPostalCodeExp, isMandatory, alertName, sPostalCode_Message)==false || 
					formElement.value.length > 6){
					formElement.focus();
					return false;
				}
			break;
			
			case "Charges":
				if(bCheck(formElement, sChargesExp, isMandatory, alertName, sCharges_Message + " and should contain only numbers.")==false){
					formElement.focus();
					return false;
				}
				var strCharge = formElement.value;
				if((strCharge.indexOf(".")) != -1)
				{
					strCharge = strCharge.substring(strCharge.indexOf(".") + 1 ,strCharge.length);
					if(strCharge.length > 2)
					{
						
						alert(alertName + sCharges_Message + ". Please enter charges only upto 2 decimal places.");
						formElement.focus();	
						return false; 
					} 
				}
				else
				{	
					if(strCharge.length > 5)
					{
						alert(alertName + sCharges_Message + ". Maximum length should be Five.");
						formElement.focus();	
						return false; 
					}
				}
								
			break;
			
			case "WorkExperience" :
				if(bCheck(formElement, sWorkExperienceExp, isMandatory, alertName, sWorkExperience_Message)==false){
					formElement.focus();	
					return false; 
				}
							
				var strYear = formElement.value;
				var strMonth = "";
									
				if(strYear.indexOf(".") != -1)
				{
					strMonth = strYear.substring(strYear.indexOf(".") + 1 ,strYear.length);
				
					if(strMonth > 11 && strMonth.length >= 2)
					{
						alert(alertName + sWorkExperience_Message + " Month Should be less than 12.");
						formElement.focus();	
						return false; 
					}
					if(strMonth.length > 2)
					{
						alert(alertName + sWorkExperience_Message + " Month Should be less than Two.");
						formElement.focus();	
						return false; 
					} 
					
					strYear = strYear.substring(0,strYear.indexOf("."));
					if(strYear.length > 2)
					{ 
						alert(alertName + sWorkExperience_Message + " Maximum length should be Two.");
						formElement.focus();	
						return false; 
					}
				
				}
				else
				{
					if(formElement.value.length > 2)
					{ 
						//alert(alertName + sWorkExperience_Message + " Maximum length should be Two.");
						alert(alertName + sWorkExperience_Message);
						formElement.focus();	
						return false; 
					}
					if(formElement.value > 50)
					{ 
						alert(alertName + sWorkExperience_Message + " Maximum year should be less than or equal to 50.");
						formElement.focus();	
						return false; 
					}
				}
			break;
			//*******************************End********************************************************************
			/*
			case "Address":
				if(bCheck(formElement,sAddressExp,sAddress_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}			
			break;*/
			case "Zip":
				//Call to bCheck modified by Satish as old call was 
				//bCheck(formElement, sZipExp, sZip_Message) which is not giveing proper error message
				if(bCheck(formElement, sZipExp, isMandatory, alertName, sZip_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			/*
			case "Amount":
				if(bCheck(formElement,sAmountExp ,isMandatory, alertName,sAmount_Message)==false){
					formElement.focus();
					return false;
				}
			break;*/
			//***********added by satish for checking empty DropDownList control-TQMS PROJ
			//Check on basis of selectedIndex=0 which is must be either blank or some "---select item---" header
			case "DropDownList":
				if(isMandatory == "True"){
					if(formElement.selectedIndex == 0){
							alert("Please select " + alertName + ".");
							formElement.focus();
							return false;
						}	
				}
			break;
			
			case "Email":
				if(isMandatory == "True"){
					if(formElement.value == ""){
						alert(alertName + " cannot be blank");
						formElement.focus();
						return false;
					}
					else{
						if(emailCheck(formElement.value) == false){
							alert(alertName + sEmail_Message);
							formElement.focus();
							return false;
						}
					}
				}
				else{
					if(formElement.value != ""){
						if(emailCheck(formElement.value) == false){
							alert(alertName + sEmail_Message);
							formElement.focus();
							return false;
						}
					}
				}
			break;
			//****************************************************************************************************
			
			/*case "Name":
				if(bCheck(objForm.elements[iCount],sNameExp,sName_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}
			break;
			case "Email":
				if(objForm.elements[iCount].IsMandatory == 'True'){
					if(objForm.elements[iCount].value=""){
						alert(objForm.elements[iCount].AlertName + " can not be blank");
						return false;
					}
					else{
						if(emailCheck(objForm.elements[iCount].value) == false){
							alert(objForm.elements[iCount].AlertName + sEmail_Message);
							return false;
						}
					}
				}
				else{
					if(objForm.elements[iCount].value!=""){
						if(emailCheck(objForm.elements[iCount].value) == false){
							alert(objForm.elements[iCount].AlertName + sEmail_Message);
							return false;
						}
					}
				}
			break;
			
			
			case "Phone":
				if(bCheck(objForm.elements[iCount],sPhoneExp ,sPhone_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}
			break;
			case "AlphaNumWithCon":
				if(bCheck(objForm.elements[iCount],sAlphaNumExp,sAlphaNum_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}
			break;
			case "City":
				if(bCheck(objForm.elements[iCount],sCityExp ,sCity_Message)==false){
					objForm.elements[iCount].focus();
					return false;
				}
			
			break;
			
			*/
			//Author : Satish - TQMS Team
			//Case for validating Date selected by Day, Month and Year dropdowns
			//formElement is an string contaning date like "1/2/3005" not actual control
			case "DropDownDate":
				if(isMandatory == "True"){
					if(formElement!= ""){
						if(validateDate(formElement)== false){
							alert(alertName + " is in invalid format. It should be in DD/MM/YYYY format.");
							return false;
						}
					}
					else{
						alert(" Please enter " + alertName);
						return false;
					}
				}
				else if(isMandatory == "False" && formElement!= ""){
					if(validateDate(formElement)== false){
							//alert(alertName + " is in invalid format. It should be in DD/MM/YYYY format.");
							alert("Date is invalid. Please check the date.")
							return false;
					}
				}
				break;
			
			case "Date":
				if(isMandatory == "True"){
					if(formElement.value != ""){
						if(validateDate(formElement.value)== false){
							alert(alertName + " is in invalid format. It should be in DD/MM/YYYY format.");
							formElement.focus();
							return false;
						}
					}
					else{
						alert(" Please enter " + alertName);
						formElement.focus();
						return false;
					}
				}
				else if(isMandatory == "False" && formElement.value != ""){
					if(validateDate(formElement.value)== false){
							alert(alertName + " is in invalid format. It should be in DD/MM/YYYY format.");
							formElement.focus();
							return false;
					}
				}
				break;
		}
		
	return true;
}

function bCheck(formElement, sExp, isMandatory, alertName, msg){

	objRegExp = new RegExp(sExp, 'gi');
	
	if(isMandatory == 'True'){
		if(formElement.value !=""){
			if(objRegExp.test(formElement.value)==false){
				alert(alertName+msg);
				return false;
			}
		}
		else{
			//Changed by Nikhil ---- 19th Jan, 2005 ---- 7.20 PM
			//alert(alertName + " cannot be blank.");
			alert("Please enter the " + alertName + ".");
			return false;
		}
	}
	else{
		if(formElement.value!=""){
			if(objRegExp.test(formElement.value)==false){
				alert(alertName+msg);
				return false;
			}
		}
	}
	
	return true;
}



/*
 * Validates date strings.
 *
 * Parameter: field    - field containing the date string
 * Internal Calls: isInteger() and isNotBlank()
 * Returns:   true (valid date) or false (not valid) boolean
 */
function bIsDate(sValue) {

    var valid = true;
    //var sDate = field.value;
    var sDate = sValue
    
    var Slash1Pos = sDate.indexOf("/",0);
    var Slash2Pos = sDate.indexOf("/",Slash1Pos + 1);
    var mm = sDate.substring(0,Slash1Pos);
    var dd = sDate.substring(Slash1Pos + 1,Slash2Pos);
    var yyyy = sDate.substring(Slash2Pos + 1,sDate.length);

    // Validate date
    if (bIsInteger(mm) == false || bIsInteger(dd) == false || bIsInteger(yyyy) == false)
        valid = false;

    if (yyyy.length != 4)
        valid = false;
    if(yyyy < 2000 )
		valid = false;
	if(yyyy > 2080)
		valid = false;
    else if (mm < 1 || mm > 12)
        valid = false;
    else if (dd < 1 || dd > 31)
        valid = false;
    else if (mm == 2) {
        if (dd > 29)
            valid = false ;
        else if (dd == 29) {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
                valid = false;
            else if (yyyy % 4 != 0)
                valid = false;
        }
    } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
        if (dd > 30)
            valid = false;
    }

    if (valid == false) {
        //alert("Data Entry Error:\n\nInvalid date entered.\nPlease enter the date in MM/DD/YYYY format.");
        //field.focus();
        //field.select();
    }

    return valid;
}

function bIsInteger(sInteger) {

    var isInt = true;
    inputStr = sInteger.toString(); // in case not a string already
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9") {
            isInt = false;
            i = inputStr.length; // break out of loop when bad char found
        }
    } return isInt;
}

//added on 12sept.2K2 to make email validation more perfect.
function emailCheck (emailStr) {
	//alert("fsadfsd");
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		return false
	}

	//if domain is ip address.
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

/*
 * Created by TQMS team - satish
 * Validates date strings.
 * Parameter: field as string  - field containing the date string
 * Internal Calls: isInteger() 
 * Returns:   true (valid date) or false (not valid) boolean
 */
function validateDate(sValue) {

    var valid = true;
    //var sDate = field.value; 
    var sDate = sValue

    var Slash1Pos = sDate.indexOf("/",0);
    var Slash2Pos = sDate.indexOf("/",Slash1Pos + 1);
    var dd = sDate.substring(0,Slash1Pos);
    var mm = sDate.substring(Slash1Pos + 1,Slash2Pos);
    var yyyy = sDate.substring(Slash2Pos + 1,sDate.length);
		

    // Validate date
    if (bIsInteger(mm) == false || bIsInteger(dd) == false || bIsInteger(yyyy) == false)
        valid = false;

    if (yyyy.length != 4)
        valid = false;
    //if(yyyy < 2000 )
	//	valid = false;
	//if(yyyy > 2080)
	//	valid = false;
    else if (mm < 1 || mm > 12)
        valid = false;
    else if (dd < 1 || dd > 31)
        valid = false;
    else if (mm == 2) {
        if (dd > 29)
            valid = false ;
        else if (dd == 29) {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
                valid = false;
            else if (yyyy % 4 != 0)
                valid = false;
        }
    } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
        if (dd > 30)
            valid = false;
    }
    
    //if(valid == false)
    //{
	//	alert("Date is in invalid format.\nPlease enter the date in DD/MM/YYYY format.");
    //}

    return valid;
}
//Used in validateDate for checking dd/mm/yyyy for integer
function bIsInteger(sInteger) {

    var isInt = true;
    inputStr = sInteger.toString(); // in case not a string already
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9") {
            isInt = false;
            i = inputStr.length; // break out of loop when bad char found
        }
    } return isInt;
}


function checkserform ()
{
   if (document.form.Search.value == "")
	   {
		    alert("Please enter your Search Term");
		    document.form.Search.focus();
			return false;
	   }
   else
	   {
		    window.location.href="http://www.123deals.com/s/"+document.getElementById('textfield').value;
		    return false;
	   }
}

function validateForm(id)
{

	//alert("hello"+id);
	var returnStatus = 1;

	if (document.testform.store.selectedIndex == 0)
	{
		alert("Please select a store");
		returnStatus = 0;
	}

	if (returnStatus)
	{
		window.location.href="http://www.123deals.com/a/"+id;
	}
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
}
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}