/*
-------------------------------------------------------------------------------------------------------------	
	Description	:	This files contains general purpose library functions. 
-------------------------------------------------------------------------------------------------------------	
*/	

	// Global constants for the error messages
	var Err_Quantity = "Please enter correct quantity."
	
	// category constants
	var Err_CategoryName = "Category Name cannot be empty.It cannot contain special characters except & and spaces."
	var Err_CategoryImage = "Please enter category image."	
	var Err_CategoryDescription = "Please enter correct category description."
	var Err_DeliveryCharges = "Please enter correct Delivery Charges."

	// Billing Address constants
	var Err_Billing_Email = "Please enter the correct format of the E-mail Address of billing information." 
	var Err_Billing_FirstName = "Please enter the correct format of billing first name. It can contain alphabets only." 
	var Err_Billing_LastName = "Please enter the correct format of last name. It can contain alphabets only." 
	var Err_Billing_Address = "Please enter the correct format of billing address." 
	var Err_Billing_City = "Please enter the correct format of billing city." 
	var Err_Billing_State = "Please enter the correct format of billing county." 
	var Err_Billing_Country = "Please enter the correct format of billing country." 
	var Err_Billing_ZipCode = "Please enter the correct format of billing zip code." 
	var Err_Billing_PhoneNumber = "Please enter the correct format of billing phone number." 
	var Err_Billing_Fax = "Please enter the correct format of billing fax." 

	// Shipping Address constants
	var Err_Shipping_Email = "Please enter the correct format of the E-mail Address of shipping information." 
	var Err_Shipping_FirstName = "Please enter the correct format of shipping first name. It can contain alphabets only." 
	var Err_Shipping_LastName = "Please enter the correct format of last name. It can contain alphabets only." 
	var Err_Shipping_Address = "Please enter the correct format of shipping address." 
	var Err_Shipping_City = "Please enter the correct format of shipping city." 
	var Err_Shipping_State = "Please enter the correct format of shipping county." 
	var Err_Shipping_Country = "Please enter the correct format of shipping country." 
	var Err_Shipping_ZipCode = "Please enter the correct format of shipping zip code." 
	var Err_Shipping_PhoneNumber = "Please enter the correct format of shipping phone number." 
	var Err_Shipping_Fax = "Please enter the correct format of shipping fax." 
	
	// Custom Product constants
	var Err_Title = "Please enter the correct format of title." 
	var Err_Description = "Please enter the correct format of description." 
	var Err_CustomProductImage  = "Please enter the custom product image." 

	var Err_FirstName = "First name can contain alphabets only. It can not be empty." 
	var Err_MiddleName = "Middle name can contain alphabets only." 
	var Err_LastName = "Last name can contain alphabets only. It can not be empty." 
	var Err_PhoneNumber = "Please enter your Phone number." 
	var Err_MobileNumber = "Mobile number can contain digits, hiphens and spaces only." 
	var Err_Fax = "Fax can contain digits, hiphens and spaces only." 
	var Err_Address = "Please enter your address." 
	var Err_City = "Please enter your city." 
	var Err_ZipCode = "Please enter your Zip/postal Code." 
	var Err_Email = "Please enter valid Email." 
	var Err_WebSite = "Invalid web site address." 	
	var Err_ShortDescription = "Invalid short description. It can't have more than 5 characters and can't be empty."
	var Err_LongDescription = "Invalid long description"
	var Err_PageHeading = "Invalid page heading."

	var Err_MenuDescription = "Invalid menu description."
	var Err_UserName = "User Name can contain alphabets, digits and underscores only. It can't have more than 50 characters and can't be empty."
	var Err_Password = "Password can contain alphabets, digits and underscores only. It can't have more than 50 characters and can't be empty."
	var Err_OldPassword = "Old password can contain alphabets, digits and underscores only. It can't have more than 50 characters and can't be empty."
	var Err_NewPassword = "New password can contain alphabets, digits and underscores only. It can't have more than 50 characters and can't be empty."
	var Err_ConfirmPassword = "Confirm password can contain alphabets, digits and underscores only. It can't have more than 50 characters and can't be empty."
	var Err_Name = "Please enter your Name."
	var Err_CompanyName = "Company Name can contain alphabets, digits, dots and spaces only."
	var Err_ImageName = "Invalid Image Name. It can't have more than 255 characters and can't be empty."

	// Contact us form constants
	var Err_YourName = "Name can contain alphabets and spaces only. It can't be empty."
	var Err_Comments = "Please enter your Comments."
		
	// Customer profile form constants
	var Err_CompanyAddress = "Invalid Company Address."
	var Err_Country = "Please enter your country."

	// product form constants
	var Err_SerialNumber = "Please enter correct serial number."
	var Err_SerialName = "Please enter a valid Name."
	var Err_UnitPrice = "Please enter a valid Unit price"
	var Err_ProductThumbImage = "Please enter thumb image"
	var Err_ProductFullImage = "Please enter full image"
    var Err_Short_Desc = "Please enter valid short description. It cann't have more than 30 characters."
    var Err_Long_Desc = "Please enter valid long description"
	var Err_Content = "Please enter the content."
	var Err_FoundryItemNo = "Please enter the FoundryItemNo."
	var Err_CategoryItemNo = "Please enter the CategoryItemNo."
	
	// Global constants for the validation petterns
	var vld_Name = /^[\s\S]*$/
	var vld_CategoryName = /^[a-zA-Z&0-9\'\"\- ]*$/
	var vld_Content = /^[a-zA-Z]*$/
	var vld_CompanyName = /^[a-zA-Z0-9.]*$/
	var vld_OtherName = /^[a-zA-Z0-9.]*$/
	var vld_FirstName = /^[a-zA-Z]*$/
	var vld_MiddleName = /^[a-zA-Z]*$/
	var vld_LastName = /^[a-zA-Z]*$/
	var vld_Description  = /^[\s\S]*$/
	var vld_City =  /^[a-zA-Z- &]*$/
	var vld_State =  /^[\s\S]*$/
	var vld_Country =  /^[\s\S]*$/
	var vld_Address =  /^[\s\S]*$/
	var vld_Title =  /^[\s\S]*$/
	var vld_RealNumber =/^([0-9]*(\.[0-9]*)?)?$/
	var vld_Integer =/^[0-9]*$/
	var vld_AlphaNumeric = /^[a-zA-Z0-9]*$/
	var vld_URL =  /^[\d\D]*$/
	var vld_FilePath =  /^[a-zA-Z]:(\\[a-zA-Z0-9_]+)+$/
	var vld_UserName =  /^[a-zA-Z0-9_]*$/
	var vld_Password =  /^[a-zA-Z0-9_]*$/
	var vld_ZipCode =  /^[\s\S]*$/
	var vld_Phone =  /^[\s\S]*$/
	var vld_Fax =  /^[\s\S]*$/
	var vld_MobileNumber = 	/^[0-9\(\)\- ]*$/
	var vld_Email =  /^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))?$/
	var vld_WebSite =  /^[\s\S]*$/
	var vld_ShortDescription = /^[\s\S]*$/
	var vld_LongDescription = /^[\s\S]*$/
	var vld_SerialNumber =  /^[\s\S]*$/
	var vld_FoundryItemNo =  /^[\s\S]*$/
	var vld_CategoryItemNo =  /^[\s\S]*$/

	var gStErrMsg = ""
/*
-------------------------------------------------------------------------------------------------------------	
	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, pstrErrMsg, pblnRqd, pintMaxLen)
	{
		var lblnVldFld = true 
		// check whether the field is mandatory
		if ( pblnRqd == true && pstrVal == "" )
		{
			lblnVldFld = false
		}
		// 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"  
		}
		return pstrErrMsg;
	}
// This function is to select/deselect check boxes
function checkAll(pobjFrm, pobjchkAll, pstrChkBox)
{
	var lintLopCnt
	for ( lintLopCnt = 0; lintLopCnt < pobjFrm.elements.length; lintLopCnt++)
	{
		if(pobjFrm.elements[lintLopCnt].type == "checkbox" && pobjFrm.elements[lintLopCnt].name == pstrChkBox)
		{
			pobjFrm.elements[lintLopCnt].checked = pobjchkAll.checked			
		}
	}
}

// This function checks whether a check box is selected before submitting the form 
function IsChecked(pobjFrm, pstrChkBox)
{
	var lintLopCnt
	var lblnchk
	lblnchk = false
	for ( lintLopCnt = 0; lintLopCnt < pobjFrm.elements.length; lintLopCnt++)
	{
		if(pobjFrm.elements[lintLopCnt].type == "checkbox" && pobjFrm.elements[lintLopCnt].name == pstrChkBox && pobjFrm.elements[lintLopCnt].checked == true )
		{
			lblnchk = true
		}
	}
	return lblnchk
}

