/*
-------------------------------------------------------------------------------------------------------------	
	Description	:	This files contains all client-side error messages & validations pattern. 
-------------------------------------------------------------------------------------------------------------	
*/	

	var Err_Username = "Invalid Username."
	
	var Err_Language = "Invalid Language Name."
	var Err_Password_blank = "Invalid Password."
	var Err_Password_NoMatch = "Both Passwords do not match."
	var Err_OldPassword_blank = "Invalid Old password."
	var Err_NewPassword_blank = "Invalid New password."
	var Err_Name = "Invalid Name."
	var Err_Surname = "Invalid Surname."
	var Err_FirstName = "Invalid FirstName."
	
	var Err_Sector = "Invalid Sector Name."
	var Err_LastName = "Invalid LastName."
	var Err_Address = "Invalid Address."
	var Err_City = "Invalid City."
	var Err_State = "Invalid State."
	var Err_Zip = "Invalid Post Code."
	var Err_Phone = "Invalid Phone."
	var Err_ContactNo="Invalid Contact No."
	
	var Err_CreditCardNo = "Invalid Credit Card No."
	
	
	var Err_BankName = "Invalid Bank Name."
	
	var Err_HomePhone = "Invalid Home Phone."
	var Err_WorkPhone = "Invalid Work Phone."
	var Err_MobilePhone = "Invalid Mobile No."
	var Err_Fax = "Invalid Fax."
	var Err_Email = "Invalid Email."
	var Err_UserName = "Invalid Username."
	var Err_Password = "Invalid Password."
	var Err_ConfirmPassword = "Invalid Confirm Password."
	var Err_URL = "Invalid Website Name."
	var Err_Subject = "Invalid Subject."
	var Err_EmployerName = "Invalid Employer Name."
	var Err_CompanyName = "Invalid Company Name."
	var Err_Question = "Invalid Question."
	var Err_Salary = "Invalid Salary Range."
	var Err_Salary1 = "Invalid Current Salary."
	var Err_Salary_blank = "Salary Range cannot be blank."
	var Err_Salary1_blank = "Current Salary cannot be blank."
	var Err_StartSalary = "Invalid Start Salary."
	var Err_JobTitle = "Invalid Job Title."
	var Err_Request = "Invalid Request."
	var Err_Comments = "Invalid comments."
	var Err_Map = "Invalid Map."
	var Err_Location = "Invalid Location Name."
	var Err_Directions = "Invalid Directions."
	var Err_SubSector = "Invalid Sub Sector Name."
	var Err_Visa = "Invalid Visa Status Name."
	var Err_JobType = "Invalid Job Type Name."
	
	
	var Err_Visa_blank = "Visa Status Name cannot be blank."
	
	
	var Err_Sector_blank = "Sector Name cannot be blank."
	var Err_SubSector_blank = "Sub Sector Name cannot be blank."
	var Err_Username_blank = "Username cannot be blank."
	var Err_UserName_blank = "Username cannot be blank."
	var Err_Password_blank = "Password cannot be blank."
	var Err_OldPassword_blank = "Old password cannot be blank."
	var Err_NewPassword_blank = "New password cannot be blank."
	var Err_Name_blank = "Name cannot be blank."
	var Err_Surname_blank="Surname cannot be blank."
	var Err_FirstName_blank = "FirstName cannot be blank."
	var Err_LastName_blank = "LastName cannot be blank."
	var Err_Address_blank = "Address cannot be blank."
	var Err_City_blank = "City cannot be blank."
	var Err_State_blank = "State cannot be blank."
	var Err_Zip_blank = "Post Code cannot be blank."
	var Err_Phone_blank = "Phone cannot be blank."
	var Err_CreditCard_blank = "Credit card  number cannot be blank."
	
	var Err_StartSalary_blank="Start Salary cannot be blank."
	var Err_HomePhone_blank = "Home Phone cannot be blank."
	var Err_WorkPhone_blank = "Work Phone cannot be blank."
	var Err_MobilePhone_blank = "Mobile No cannot be blank."
	var Err_ContactNo_blank="Contact No. cannot be blank."
	var Err_EmployerName_blank = "Employer Name cannot be blank."
	var Err_CompanyName_blank = "Company Name cannot be blank."
	var Err_URL_blank = "Website Name cannot be blank."
	var Err_Language_blank = "Language Name cannot be blank."
	var Err_Fax_blank = "Fax cannot be blank."
	var Err_Email_blank = "Email cannot be blank."
	var Err_BankName_blank = "Bank Name cannot be blank."
	
	var Err_Password_blank = "Password cannot be blank."
	var Err_ConfirmPassword_blank = "Confirm Password cannot be blank."
	var Err_PasswordNoMatch = "The two passwords do not match."
	var Err_Location_blank = "Location Name cannot be blank. "
	var Err_Question_blank = "Question Title cannot be blank. "
	var Err_JobTitle_blank = "Job Title cannot be blank. "
	var Err_Subject_blank = "Subject cannot be blank."
	var Err_Comments_blank = "Comments cannot be blank."
	var Err_Request_blank = "Request cannot be blank."
	var Err_Map_blank = "Map  cannot be blank."
	var Err_Directions_blank = "Directions cannot be blank."
	var Err_JobType_blank = "Job Type Name cannot be blank."
	
	//*************************************
	var Err_WelcomeText = "Invalid Welcome Text."
	var Err_WelcomeText_blank = "Welcome Text cannot be blank."
	
	var Err_Title = "Invalid Title."
	var Err_Title_blank = "Title cannot be blank."
	
	var Err_Message = "Invalid Message."
	var Err_Message_blank = "Message cannot be blank."
	
	var Err_File = "Invalid File."
	var Err_File_blank = "File cannot be blank."
	
	var Err_Desc = "Invalid Description."
	var Err_Desc_blank = "Description cannot be blank."
	
	
	var Err_Street = "Invalid Street."
	var Err_Street_blank = "Street cannot be blank."
	
	
	var Err_FoodInfo = "Invalid Food Info."
	var Err_FoodInfo_blank = "Food Info cannot be blank."
	
	
	var Err_OtherInfo = "Invalid Other Info."
	var Err_OtherInfo_blank = "Other Info cannot be blank."
	
	
	var Err_AdditionalInfo = "Invalid Additional Info."
	var Err_AdditionalInfo_blank = "Additional Info cannot be blank."
	
	var Err_Driving = "Invalid Driving Info."
	var Err_Driving_blank = "Driving Info cannot be blank."
	
	var Err_Photo = "Invalid Photo."
	var Err_Photo_blank = "Photo cannot be blank."
	
	var Err_Acc = "Invalid Accmmodation."
	var Err_Acc_blank = "Accmmodation cannot be blank."
	
	
	var Err_Event = "Invalid Event Title."
	var Err_Event_blank = "Event Title cannot be blank."
	
	
	var Err_Budget = "Invalid Budget Amount."
	var Err_Budget_blank = "Budget Amount cannot be blank."
	
	
	var Err_Projected = "Invalid Projected Amount."
	var Err_Projected_blank = "Projected Amount cannot be blank."
	
	
	var Err_Actual = "Invalid Actual Amount."
	var Err_Actual_blank = "Actual Amount cannot be blank."
	
	
	var Err_Item = "Invalid Item Name."
	var Err_Item_blank = "Item Name cannot be blank."
	
	
	var Err_ReminderDays = "Invalid Reminder Days"
	var Err_ReminderDays_blank = "Reminder Days cannot be blank."
	
	var Err_Task = "Invalid Task Title"
	var Err_Task_blank = "Task Title cannot be blank."
	
	var Err_Album = "Invalid Album"
	var Err_Album_blank = "Album cannot be blank."
	
	var Err_People = "Invalid No of People."
	var Err_People_blank = "No of People cannot be blank."
	
	var Err_PhotoTitle = "Invalid Photo Title."
	var Err_PhotoTitle_blank = "Photo Title cannot be blank."
	
	var Err_SiteTitle = "Invalid Site Title."
	var Err_SiteTitle_blank = "Site Title cannot be blank."
	
	var Err_URL = "Invalid URL."
	var Err_URL_blank = "URL cannot be blank."
	var Err_Url1 = "Invalid URL."
	var Err_Url1_blank = "URL cannot be blank."
	
	var Err_Content = "Invalid Content."
	var Err_Content_blank = "Content cannot be blank."
	
	
	var Err_Notes = "Invalid Notes."
	var Err_Notes_blank = "Notes cannot be blank."
	
	
	var Err_People = "Invalid No of Expected People."
	var Err_People_blank = "No of Expected People cannot be blank."
	
	
	
	
	
	
    //*****************************************
	
	// Global constants for the validation patterns
	//*****************************************
	var vld_WelcomeText =/^[\s\S]*$/
	var vld_Title =/^[\s\S]*$/
	var vld_WebsiteTitle=/^[a-zA-Z0-9]*$/
	var vld_WebsiteTitle1=/^[a-zA-Z0-9\n\s\r,. ]*$/
	var vld_WebsiteTitle2=/^[a-zA-Z0-9\n\s\r, ]*$/
	var vld_Companynew=/^[a-zA-Z0-9 ]*$/
	var vld_FileName =/^[\s\S]*$/
	var vld_Desc =/^[\s\S]*$/
	var vld_Location =/^[\s\S]*$/
	
	
	var vld_Integer =/^[0-9]*$/
	//*****************************************
	
	var vld_Name = /^[a-zA-Z\.\' ]*$/
	
	var vld_Message = /^[\s\S]*$/
	var vld_Content = /^[\s\S]*$/
	
	var vld_Location =  /^[\s\S]*$/
	var vld_FirstName = /^[a-zA-Z0-9]*$/
	var vld_MiddleName = /^[\s\S]*$/
	var vld_LastName = /^[\s\S]*$/
	var vld_Address =  /^[a-zA-Z0-9\.\'\,#\&\(\)\-\\\/ ]*$/
	var vld_City =  /^[\s\S]*$/
	var vld_State =  /^[\s\S]*$/
	var vld_Country =  /^[a-zA-Z-]+[a-zA-Z- &\"\']*$/
	var vld_RealNumber =/^([0-9]*(\.[0-9]*)?)?$/
	var vld_AlphaNumeric = /^[a-zA-Z0-9]*$/
	var vld_Subject =  /^[a-zA-Z0-9\.\,#\&\(\)\-\\\/ ]*$/
	//var vld_URL =  /^[(a-zA-Z0-9)]*\.[((a-zA-Z0-9)\.\-)]*\.[a-zA-Z(\/\\)]+$/;
	var vld_URL = /^[\s\S]*$/
	

	
	var vld_FilePath =  /^[a-zA-Z]:(\\[a-zA-Z0-9_]+)+$/
	var vld_FileName =  /^[\s\S]*$/
	var vld_UserName =  /^[a-zA-Z0-9_]*$/
	var vld_Password =  /^[\s\S]*$/
	var vld_Zip =  /^[a-zA-Z0-9\-\ ]*$/
	var vld_Phone = /^[a-zA-Z0-9\-\(\)+ ]*$/
	var vld_CreditCardNo = /^([0-9]*(\.[0-9]*)?)?$/
	var vld_Fax =  /^[a-zA-Z0-9\-\(\) ]*$/
	var vld_Email =  /^(([a-zA-Z0-9\_\-\.]*)@([a-zA-Z0-9\_\-\.]*)([a-zA-Z0-9]*))$/
	
	var vld_Driving =/^[\s\S]*$/
	var gStErrMsg = ""
	var vld_String =  /^[\s\S]*$/
	
	
	var vld_Notes =  /^[\s\S]*$/
	var vld_PhoneNo_AllFormats = /^\(?d{3}\)?[\s\-]?\d{3}\-?\d{4}$/
	
/*
-------------------------------------------------------------------------------------------------------------	
	Description	:	This functions validates a value against a validation pattern. If the pattern does not 
					matches the value it appends an error message to the error message string. This function 
					is to be used for form validation.
	Parameters 	:	
					pstrPtn -- validation pattern
					pstrVal -- value to be matched against the pattern 
					pstrMsg -- Constant for the error message 
					pstrErrMsg -- Error message string 
					pblnRqd	-- Required or not 						  
					pintMaxLen -- Maximum Length
-------------------------------------------------------------------------------------------------------------	
*/	
function ValidateField(pstrPtn, pstrVal, pstrMsg, pstrblkMsg, pstrErrMsg, pblnRqd, pintMaxLen)
{

	pstrVal = trim(pstrVal);
	var lblnVldFld = true 
	// check whether the field is mandatory
	if ( pblnRqd == true && pstrVal == "" )
	{
		
		//lblnVldFld = false
		return pstrblkMsg;
	}
	// maxlength check
	if( pintMaxLen > -1 && pstrVal.length > pintMaxLen)
	{
		lblnVldFld = false	 		
	}
	// validate value against pattern
	if( eval(pstrPtn).test(pstrVal) == false )
	{
		lblnVldFld = false
	}				
	// generate error message if invalid
	if ( lblnVldFld == false )
	{
		//pstrErrMsg = pstrErrMsg + pstrMsg + "\r"
		pstrErrMsg = pstrMsg
	}
	return pstrErrMsg;
}
function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

//function for email validation
// at present as per client requirement user
// can enter any type of format for email
// but must have ' @ 'sign.
//For checking invalid E-Mail address

	function isEmail(email)
		{		
		// This function is used to validate a given e-mail 
		// address for the proper syntax		
		if (!isNaN(email.substring(0,1))){
				return false;
		}
		if (email == ""){
			return false;
		}		 
		if(email.indexOf("<",1)>0)
		{
		    return false;
		}
		if(email.indexOf(">",1)>0)
		{
		    return false;
		}
		posOfAtSign = email.indexOf("@",1)
		if (posOfAtSign == -1){
			return false;
		}
		if (email.indexOf("@",posOfAtSign+1) != -1){
			return false;
		}
		posOfPeriod = email.indexOf(".", posOfAtSign)
		if (posOfPeriod == -1){
			return false;
		}
		if (posOfPeriod+2 > email.length){
			return false;
		}
		return true
		}        
	
	function isNull(aStr)
	{		 
		var index;		
		for (index=0; index < aStr.length; index++)
			if (aStr.charAt(index) != ' ')
				return false;
		return true;
	}
	function isValidContent_new(aStr){
			var reChars = /[0-9@]/;
			var count;
			var ctotal;
			var k;
			
			
			if(reChars.test(aStr))
			{
				count=aStr.length;
				for (i=0;i<count;i++)
				{
					if (isInteger(aStr.charAt(i)))
					{
						if(aStr.charAt(i)=="1"|| aStr.charAt(i)=="2")
						{
							
							
							ctotal=0;
							for(j=i;j<count;j++)
							{
								ctotal=ctotal+1;
								if(aStr.charAt(i+1)=='')
								{
									k=1;
									break;
								}	
								k=0;
							}
							
							if(ctotal>5)
							{
								return 2;
							}
							else
							{
							return 3;
							}
						}
						else
						{
							if((i+1)<count-1)
								{
								
									if ((isInteger(aStr.charAt(i+1)))&&(isInteger(aStr.charAt(i+2))))
									{
										
										//return 1;
										
										return 2;
									}
								}
						}	
					}
				}
				return 1;		
			}
			return 0;
	}
	
	
	function isInteger(s){
	
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function isDateFormat(s){
	
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9")))
			{
			if(c!="/")
			return false;
			} 
		}
		// All characters are numbers.
		return true;
	}
	
function getLength(str)
{
    pstrVal = trim(str);

	return pstrVal.length;
	
}
function checkdate(objName) {

var datefield = objName;
if(isDateFormat(datefield.value)==false)
{
return false;
}
if (chkdate(objName) == false) {
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) 
{
err = 1;
return false;
}
else 
{
strMonth = strDateArray[0];
strDay = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strMonth = strDate.substr(0, 2);
strDay = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}


//if (strDatestyle == "US") {
//datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
//}
//else {
//datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
//}
return true;
}

function LeapYear(intYear) {
    if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
    }
    else {
    if ((intYear % 4) == 0) { return true; }
    }
    return false;
}
