/*
----------------------------------------------------------
Page Name	    :	CommonValidation.js
Type		    :	Javasciprt file
Purpose			:	Hols the common validations for MerlinLite
Version			:	V 1.0       
Notes			:	All common validation functions are written here.
					All common validaiton messages are declared here.
					Each function purpose and usage and inputs and output are written
					Each message varibale purpose and pages declared for are maintained.
----------------------------------------------------------
*/
//-----------------------------------------Error / Waring Message Section Starts-------------------------
/*
Start of Error / Warning Message section
Section - Error / Warning Messages Declaration
Notation - starts with msg and followed by common, pagespecific, followed message purpose text
			eg:	msg_common_required, msg_placeorder_quantity
Notes - Sub section of messages added by developer are authorized by developer name and date.
*/

var msg_common_required = "Data Required."
var msg_common_allspaces = "Invalid Entry-this field must contain at least one character."
var msg_common_invalidchars = "Invalid Entry - this field contains invalid characters < (or) >."
var msg_common_integeronly ="Invalid Entry-this field must contain integer value."
var msg_common_email = "Invalid Entry-Enter Valid E-mail format(abc@abc.com)."
var msg_common_country = "Select a country."
var msg_common_currency = "Select a currency."
var msg_common_state = "Select a state."
var msg_common_creditcardtype = "Select a Card Type."
var msg_common_creditcardexpmonth = "Select expiration month."
var msg_common_creditcardexpyear = "Select expiration year."
var msg_common_Pwdnotmatch = "Password did not match."
var msg_common_zip = "Invalid Entry-Enter valid Postal code."
var msg_common_phone = "Invalid Entry-Enter valid phone number."
var msg_common_fax = "Invalid Entry-Enter valid fax number."
var msg_accountsearch_lastname_reqiured = "Last Name Required."
var msg_accountsearch_invalid = "Invalid Entry-this field must contain at least two character."
var msg_company_businessname_number = "Business name can not start with number."
var msg_company_businessname_min = "Business name must have minimum 4 characters."
var msg_company_companyurl = "Enter valid company url.Valid url format is http://www.abc.com or www.abc.com."
var msg_company_companyurl_whitespace = "Company url shouldn't contain any white spaces."
var msg_company_bussinessoperatingcountries = "Select atleast one business operation country."
var msg_accountidentification_integer = "Invalid data.Enter integer Value."
var msg_accountidentification_accountid = "Account Id should be greater than 100."
var msg_producttype_producttype = "Select a product type."
var msg_ManageProductType_selectoneoptiondistributororcustomer = "Select one option distributor (or) customer."
var msg_product_price = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_product_price_diff = "Wholesale price should be less than Ratail price."
var msg_product_cv = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_product_cv = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_product_weight = "Invalid Entry-this field must contain a numeric value from 0.0001 to 9999.9999(maximum 4 decimal places)."
var msg_product_image_filetype = "Invalid image file type.Valid file types are jpeg,jpg,gif files."
var msg_product_impage_notfound = "Invalid image.Uploaded image is not found."
var msg_signup_signuporder = "Select SignUp Fee (or) Items (or) RecurringFee."
var msg_signup_signuporder_signupfee = "Select signup fee item."
var msg_signup_signuporder_signupitem = "Select atleast one signup item from Must Select One Item from List."
var msg_signup_signuporder_items_selectoneitem = "Select Fix Items (or) Full Items from list."
// Added by Radhika Kialru on 08/24/2006
var msg_signup_signuporder_Fixeditems_selectoneitem = "Select All Items Purchase From List (or) Must Select One Item from List."
var msg_singup_signuporder_recurringfee = "Select Monthly (or) Yearly RecurringFee."
var msg_signup_signuporder_recurringfee_month = "Select Monthly Recurring Fee item."
var msg_signup_signuporder_recurringfee_month_dayoption = "Select Signup Day (or) Fixed Day to Process Monthly Recurring Fee."
var msg_signup_signuporder_recurringfee_year = "Select Yearly Recurring Fee item."
var msg_signup_signuporder_recurringfee_year_dayoption = "Select Signup Day (or) Fixed Day to Process Yearly Recurring Fee."
var msg_signup_signuporder_recurringfee_month_day ="Select Monthly Recurring Fee Day."
var msg_signup_signuporder_recurringfee_year_day ="Select Yearly Recurring Fee Day."
var msg_tax_amount = "Invalid Entry-this field must contain a numeric value from 0.0001 to 9999.9999(maximum 4 decimal places)."
var msg_shipping_selectshippingmethod = "Select a shipping method."
var msg_shipping_amount = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_shipping_order_maxgreaterthanmin = "Maximum Order Value should be greater than Minimum Order Value."
var msg_shipping_order_maxlessthannextmin = "Maximum Order Value Should be less than"
var msg_shipping_weight_maxgreaterthanmin = "Maximum Order Weight should be greater than Minimum Order Weight."
var msg_shipping_weight_maxlessthannextmin = "Maximum Order Weight Should be less than."
var msg_autoship_day = "Select Autoship day."
var msg_commission_plan_commissionperiod = "Select commission period."
var msg_commission_plan_fixedmatrixwidth ="Fixed matrix width should be greater than 1."
var msg_commission_plan_minimumcv = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_plan_checkprocessionfee = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_plan_minimumcommisionAmount = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_rank_rule = "Select leadership rank Rule."
var msg_commission_rank_invalidchars = "Invalid data.Enter valid characters for rank name."
var msg_commission_rank_downlinerank = "Invalid data.Number of downline should be greater than 0."
var msg_commission_rank_downlinerank_select = "Select downline rank."
var msg_commission_rankrule_rankqualification = "Select atleast one qualification."
var msg_Commission_retailcommissionbasedon = "Select atleast one commission based on option."
var msg_commission_rank_minimumgroupvolume = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_common_commissionpcvalue = "Invalid Entry-this field must contain a numeric value from 0.01 to 99.99(maximum 2 decimal places)."
var msg_commission_matchingbonus_selectcommission = "Select atleast one commission."
var msg_commission_matchingbonus_matchingbonusalone = "Matching Bonus alone cannot be an option."
var msg_commission_matrix_commissionvalue = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_matrix_maximumpayablelevels = "Invalid Entry-this field must contain a numeric value from 1 to 999(Decimals are not accepted)."
var msg_commission_binarygroupvolume = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_commission_binarycommission = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_paymentgateway_selectoneprocessor = "Select atleast one payment processor."
var msg_paymentgateway_selectonecard = "Select atleast one credit card type."
var msg_reports_validid = "Enter valid ID."
var msg_reports_validsponsorid = "Enter valid sponsor ID."
var msg_reports_validautoshipid= "Enter valid autoship ID."
var msg_reports_validorderid="Enter valid order ID."
var msg_reports_validday="Enter a valid day."
var msg_reports_validmonth="Enter a valid month"
var msg_reports_grossorderamount_range = "Invalid Entry-this field must contain a numeric value from 0.01 to 99999999.99(maximum 2 decimal places)."
var msg_reports_numberrequired = "Number required."
var msg_common_DateFromGreaterDateTo="End Date must be equal to or greater than the Start Date."
var msg_common_daterequired = "Date Required."
var msg_common_invaliddate = "Invalid Date."
var msg_common_AmountToGreaterAmountFrom = "Amount From cannot be greater than Amount To."
var msg_createreturnedorder_Qty_diff = "Return quantity should be less then ordered quantity!"
var msg_searchforaccount_entertwochars="Enter atleast first 2 characters of last name."
var msg_common_birthdate="Invalid Entry-Enter Valid Date of Birth."
var msg_common_birthdatemonth="Month must be between 1 and 12."
var msg_common_birthdateday="Day must be between 1 and 31."
var msg_signup_donotstartwithnumber="Invalid Entry-Signin name cannot start with number."
var msg_signup_signinnameminimumfourcharacters ="Invalid Entry-Signin name must contain minimum four characters."
var msg_common_validssn ="Invalid Entry-Enter valid Tax Identification Number."
var msg_common_signinname ="Invalid Entry-SignIn Name contains invalid characters."
var msg_common_creditcardrequired ="Card Number Required."
var msg_common_americanexpresscardnumber = "Invalid Entry-Enter a valid American Express card number."
var msg_common_discoverycardnumber = "Invalid Entry-Enter a valid Discovery card number."
var msg_common_discoverynumber = "Invalid Entry-Enter a valid Discovery card number."
var msg_common_mastercardnumber = "Invalid Entry-Enter a valid Master card number."
var msg_common_visacardnumber = "Invalid Entry-Enter a valid Visa card number."
var msg_common_validcreditcardnumber = "Invalid Entry-Enter a valid credit card number."
var msg_selectOneCheckboxforsearch = "Select atleast one check box."
var msg_enteraltpaymentinfo_cardinvalid_forexpdate="Sorry! The expiration date you have entered would make this card invalid."
var msg_autoshipsearch_selectstatus="Select Status !"
var msg_autoshipsearch_selectautoshipday="Select Autoship Day !"
var msg_searchfororders_accountid ="Account ID should be greater than 0."
var msg_searchfororders_createdbyid ="CreatedBy ID should be greater than 0."
var msg_searchfororders_selectcriteria ="Choose atleast One Criteria."
var msg_searchfororders_selectoption ="Select One Option."
var msg_common_name="First Name Required"
// added by Ranam on 05/30/06
var msg_rank_selectonerank = "Select one rank type."
var msg_rank_selectonecommissionperiod = "Select one Commission Period. "
var msg_rank_selectoneforcommissions = "Select one of the Options - Search for ID / Search from Criteria. "
var msg_rank_selectoneforcommissionssearch = "Select Atleast One Option - Rank / Amount Range / Commission Period. "
var msg_selectoneforcommissions = "Select one of the Options - Search for ID / Search from Criteria. "
var msg_selectoneforcommissionssearch = "Select Atleast One Option. "
var msg_selectoneforvoulmeadjustment = "Select Add/Subtract. "
// added by Radhika on 08/16/06
var msg_comissionAdjustment_validId ="enter valid ID#. "
var msg_common_Hours_required = "Hours Required." 


// added by Ratnam 06/05/06
var msg_maxvalueforaccountinccommissionsforecast = "Length Cannot be More than 6."
// added by Ratnam 06/12/06
var msg_commission_amount_search = "Invalid Entry-this field must contain a numeric value from -99999999.99 to 99999999.99(maximum 2 decimal places)."
// End of Error / Warning Message section by Ratnam

var msg_ManageAdminAccounts_ConfirmPwd = "Your password entries donot match."
//signup order by bharath on 07/06/2006
var msg_singuporder_checkagree = "Check I AGREE."
var msg_signuporder_validquantity = "Enter Valid Quantity."
var msg_signuporder_selectroducts = "Select Product from Purchase Products."
var msg_signuporder_admin_selectpayment = "Select payment recieved for purchase option (or) Click change billing information link to provide billing information for the order."
var msg_signuporder_distributor_selectpayment = "Billing Information is not provided for the order. Click change billing information link to provide billing information."
var msg_signuporder_selectshipping = "Shipping Information is not provided for the order. Click change shipping information link to provide shipping information."

//SignupAutoship order by Srinvas on 06/13/2006
var msg_autoshiporder_validquantity = "Enter Valid Quantity."
var msg_autoshiporder_selectroducts = "Select Product from Purchase Products."
var msg_autoshiporder_admin_selectpayment = "Select payment recieved for purchase option (or) Click change billing information link to provide billing information for the order."
var msg_autoshiporder_distributor_selectpayment = "Billing Information is not provided for the order. Click change billing information link to provide billing information."

//summary message added by Bharath 0n 06/18/2006
var msg_order_summary_selectpayment = "Billing Information is not provided for the order. Click change billing information link to provide billing information."
var msg_order_summary_selectshipping = "Shipping Information is not provided for the order. Click change shipping information link to provide shipping information."

//process ready to ship order page added by bharath on 06/30/2006
var msg_processreadytoshiporders_selectdaterange = "Select Date Range Checkbox option to search with in a Date range."
var msg_processreadytoshiporders_recordnotselected = "No Reord is selected to update shipping.Select at least one record."
var msg_processreadytoshiporders_invalidshipdate = "Ship date for the order should be greater than processed date."


//process Pending order page added by Radhika Kilaru on 08/01/2006
var msg_processPendingorders_selectdaterange = "Select Date Range Checkbox option to search with in a Date range."
var msg_processPendingorders_recordnotselected = "No Record is selected to update Pending orders.Select at least one record."
var msg_ProcessPendingorders_SelectProcessOrFail = "Select either Processed checkbox or failed checkbox."

//Downline Tree - Added by Bharath Reddy on 09/09/2006
var msg_downlinetree_validclientid = "Client ID can not be more than 6 digit number."

// Binary Commissions Wizard msgs -- added by Ratnam 01/16/07
var msg_binary_flushing_or_nonflushing_option = "Select Flushing (or) Non Flushing."
var msg_binary_flushing_admin_or_auto_option = "Select Flushing by Admin (or) Auto."

//Flush Commissions page msgs -- added on 01/30/2007
var msg_flushCommmissions ='Do you want to Flush the Commissions ?';
 
/*
End of Error / Warning Message section
*/

//-----------------------------------------Error / Waring Message Section Ends-------------------------

//-----------------------------------------Global Variables declaration Section Starts------------------
/*
Start of Global Variables section
Section - Global Variables Declaration
Notes - regular expression variables,global variables used in functions are declared in this section
*/

var regExpEmail = /^([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 regExpLoginName = /^([a-zA-Z0-9_.-]{4,100})$/
var urlRegxp =	/^(((ht|f)tp(s?))\:\/\/)?(www\.|www[0-9]\.)([a-zA-Z0-9\-]+\.([a-zA-Z]+))$/
var invalidChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"
// regExpDoB added by Leela on 04/22/2006  used in "ProcessReadyToShipOrders.aspx"
var regExpDOB=/^((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))$/
// regExpExtRange for Page "CreateReturnedOrder.aspx" 
var regExpExtRange = /^(\d{1,3})$/
var regExpSSN = /^\d{9}$/



/*
End of of Global Variables section
*/


//-----------------------------------------Global Variables declaration Section Ends------------------				
	
//-----------------------------------------Common Functions Section Starts Here-------------------------	
/*
Start of Common Functions Section
Section - Common Functions
Notation - starts with small letters. if output is boolean value, function name starts with is. functions 
			have meaningful name.
			eg: isValidQuantity, isValidUSPhoneNumber, OpenCalender
Notes - functions added by developer are authorized by developer name and date.
*/

/* 
function name	:	ShowDescript
input			:	string
ouput			:	
Purpose			:	to popup description.
created by		:	Bharath	
*/



function fillMessage(lblToFill,msgToFill)
{
	if (navigator.userAgent.indexOf("Firefox")!=-1)			
		lblToFill.textContent = msgToFill;			
	else if (navigator.appName == "Microsoft Internet Explorer")
		lblToFill.innerText = msgToFill;					
}//end function fillMessage()

function ShowDescript(url) 
	{
		var winhand = window.open(url,'Description','width=650,height=600,resizeable=no,scrollbars=no,toolbar=no');
	}

/* 
function name	:	isValidQuantity
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the quantity is valid
created by		:	Bharath	
*/

function isValidQuantity(s)
			{
			var i;
				
				for (i = 0; i < s.length; i++) {
				var c = s.charAt(i);
				if (!isValidQuantityDigit(c)) return false;
				}
				return true;
			
			}
			
		function isValidQuantityDigit (c)
			{
				return ((c >= "0") && (c <= "9"))
			}// end of isValidQuantity

/* 
function name	:	isURLhaswhitespace
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the url provided has white space
created by		:	Srinivas	
*/	
function isURLhaswhitespace(url)
	{
		for (var i=0;i<url.length;i++)
			 	{
			 		if (url.charAt(i) == " ")
			 			{
			 			return true
			 			}
			 	}
			 	return false;
	}//end of isAlphabetic
//---------------------------------------------------------------------------
/* 
function name	:	isAlphabetic
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided contains alphabets
created by		:	Srinivas	
*/	
function isAlphabetic(val)
	{
		if (val.match(/^[a-zA-Z]+$/))
			{
				return true;
			}
		else
			{
				return false;
			}   
	}//end of isAlphabetic
	
//---------------------------------------------------------------------------	
/* 
function name	:	isValidScriptChars
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided contains script tags
created by		:	Srinivas	
Altered By		:	Bharath
Comments		:	Changed function name from isInvalidScriptChars to isValidScriptChars to make meaning ful while validating.

*/	
	
function isValidScriptChars(val)	
{
	if (val.indexOf('<')==-1 && val.indexOf('>') == -1)
		return true;
	else
		return false;
}
//--------------------------------------------------------------------------	
/* 
function name	:	isEmptyAfterTrim
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is of all white spaces/tabs.
created by		:	Srinivas	
*/
function isEmptyAfterTrim(s)
	{
		if (Trim(s) == "")
			return true;
			return false;
	}//end of isEmptyAfterTrim
/* 
function name	:	isEmpty
input			:	Character
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is not assigned a value or empty
created by		:	Srinivas	
*/
function isEmpty(s)
	{
		if ((s == "") || (s == null))
			return true;
			return false;
	}//end of isEmpty

/* 
function name	:	isInteger
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is integer
created by		:	Srinivas	
*/

function isInteger(s) 
	{

		var i;
		
		for (i = 0; i < s.length; i++)
		 {
			var c = s.charAt(i);
			if (isIntegerDigit(c)==false) return false;
		}
			return true;
	}//end of isInteger

function isIntegerDigit(c)
	{
		return ((c >= "0") && (c <= "9"))
	}  //end of isIntegerDigit	
	
/* 
function name	:	isDecimalNumber(isNumeric)
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is Decimal Number
created by		:	Srinivas	
*/

function isDecimalNumber(s) 
	{
		var i;
		
		for (i = 0; i < s.length; i++)
		 {
			var c = s.charAt(i);
			if (isDecimalDigit(c)==false) return false;
		}
			return true;
	}// end of isDecimalNumber

function isDecimalDigit(c)
	{
		if ((c >= "0") && (c <= "9") || (c == "."))
		{
		return true;
		}
		else
		{
		return false;
		}
	}   //end of isDecimalDigit
	
	
	function isDigit(c){
	return ((c >= "0") && (c <= "9"))
    }//end func isDigit()      


		function isNumber(s)
		{
			var i;			
			for (i = 0; i < s.length; i++) {
			var c = s.charAt(i);
			if (!isDigit(c)) return false;
			}
			return true;
		} //end func isNumber()



	/* 
function name	:	isDecimalNumberWithNegative(isNumeric)
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is Decimal Number for +ve & -ve values
created by		:	Ratnam	
created on		:	06/12/2006
*/


	function isDecimalNumberWithNegative(s) 
	{
		var i;
		if (s.substring(0,1) == "-")
		{
			s = s.substring(1,s.length)
		}
		
		for (i = 0; i < s.length; i++)
		 {
			var c = s.charAt(i);
			if (isDecimalDigit(c)==false) return false;
		}
			return true;
	}// end of isDecimalNumberWithNegative
	
	/* 
function name	:	isValidSearchAmount(isNumeric)
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is Decimal Number for +ve & -ve values with two decimal places
created by		:	Ratnam	
created on		:	06/12/2006
*/

	function isValidSearchAmount(price)
			{
				
				var textafterdecimal;
				if (price.lastIndexOf('.') == -1)
				{
					price += ".";
				}
				textafterdecimal = price.substring(price.indexOf('.')+1, price.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				
				var textbeforedecimal;				
			
					textbeforedecimal = price.substring(0,price.indexOf('.'));
					if (textbeforedecimal.substring(0,1) == "-")
						{
							textbeforedecimal = textbeforedecimal.substring(1,textbeforedecimal.length)
						}
					if (textbeforedecimal.length > 8)
					{			
					return false;
					}
							
				return true;
			}	//end of isValidProductPrice
			

/* 
function name	:	isProductPrice(ProductPrice)
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for the price of the product accepts only two decimal places
created by		:	Srinivas	
*/

function isValidProductPrice(price)
			{
				
				var textafterdecimal;
				if (price.lastIndexOf('.') == -1)
				{
					price += ".";
				}
				textafterdecimal = price.substring(price.indexOf('.')+1, price.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				
				var textbeforedecimal;				
			
					textbeforedecimal = price.substring(0,price.indexOf('.'));
					if (textbeforedecimal.length > 8)
					{			
					return false;
					}
							
				return true;
			}	//end of isValidProductPrice
			
/* 
function name	:	isValidProductWeight
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for the weight of the product accepts only four decimal places
created by		:	Srinivas	
*/
	
function isValidProductWeight(weight)
			{
				
				var textafterdecimal;
				if (weight.lastIndexOf('.') == -1)
				{
					weight += ".";
				}
				textafterdecimal = weight.substring(weight.indexOf('.')+1, weight.length);
				
				if (textafterdecimal.length > 4)
				{
					return false;
				}
				var textbeforedecimal;			
	
				textbeforedecimal = weight.substring(0,weight.indexOf('.'));
				if (textbeforedecimal.length > 4)
				{			
				return false;
				}
				return true;
			}	//end of isProductWeight			
			
/* 
function name	:	isValidProductCV
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for the cv of the product accepts only two decimal places
created by		:	Srinivas	
*/

function isValidProductCV(cv)
			{
				
				var textafterdecimal;
				if (cv.lastIndexOf('.') == -1)
				{
					cv += ".";
				}
				textafterdecimal = cv.substring(cv.indexOf('.')+1, cv.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				
				var textbeforedecimal;			
	
				textbeforedecimal = cv.substring(0,cv.indexOf('.'));
				if (textbeforedecimal.length > 8)
				{			
				return false;
				}
							
				return true;
			}	//end of isValidProductCV

/* 
function name	:	isValidTaxAmount
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for the tax amount of the states is of 5,4 format.
created by		:	Srinivas	
*/

function isValidTaxAmount(tax)
			{
				
				var textafterdecimal;
				if (tax.lastIndexOf('.') == -1)
				{
					tax += ".";
				}
				textafterdecimal = tax.substring(tax.indexOf('.')+1, tax.length);
				
				if (textafterdecimal.length > 4)
				{
					return false;
				}				
				var textbeforedecimal;			
	
				textbeforedecimal = tax.substring(0,tax.indexOf('.'));
				if (textbeforedecimal.length > 5)
				{			
				return false;
				}							
				return true;
			}	//end of isValidTaxAmount			
	


/* 
function name	:	isValidShippingAndHandlingAmount
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for the shipping amount is of 8,2 format.
created by		:	Srinivas	
*/

function isValidShippingAndHandlingAmount(shippinghandlingamount)
			{				
				var textafterdecimal;
				if (shippinghandlingamount.lastIndexOf('.') == -1)
				{
					shippinghandlingamount += ".";
				}
				textafterdecimal = shippinghandlingamount.substring(shippinghandlingamount.indexOf('.')+1, shippinghandlingamount.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				
				var textbeforedecimal;			
	
				textbeforedecimal = shippinghandlingamount.substring(0,shippinghandlingamount.indexOf('.'));
				if (textbeforedecimal.length > 8)
				{			
				return false;
				}
							
				return true;
			}	//end of isValidShippingAndHandlingAmount	
			

/* 
function name	:	isValidMinimumCV
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for minimum CV is of 8,2 format.
created by		:	Srinivas	
*/		
			
function isValidMinimumCV(CV)
			{				
				var textafterdecimal;
				if (CV.lastIndexOf('.') == -1) 
				{
				CV += ".";
				}
				textafterdecimal = CV.substring(CV.indexOf('.')+1, CV.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;			
				textbeforedecimal = CV.substring(0,CV.indexOf('.'));
				if (textbeforedecimal.length > 8)
				{			
				return false;
				}
				return true;
			}//end of isValidMinimumCV
			
/* 
function name	:	isValidCheckProcessingFee
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for check processing fee is of 5,2 format.
created by		:	Srinivas	
*/	
				
function isValidCheckProcessingFee(fee)
			{
				
				var textafterdecimal;
				if (fee.lastIndexOf('.') == -1)
				{
					fee += ".";
				}
				textafterdecimal = fee.substring(fee.indexOf('.')+1, fee.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;
				textbeforedecimal = fee.substring(0,fee.indexOf('.'));
				if (textbeforedecimal.length > 5)
				{			
				return false;
				}
				return true;
			}//end of isValidCheckProcessingFee
			
/* 
function name	:	isValidMinimumCommissionAmount
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for minimum commission amount is of 5,2 format.
created by		:	Srinivas	
*/	
				
			
function isValidMinimumCommissionAmount(commission)
			{
				
				var textafterdecimal;
				if (commission.lastIndexOf('.') == -1)
				{
					commission += ".";
				}
				textafterdecimal = commission.substring(commission.indexOf('.')+1, commission.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;
			
				textbeforedecimal = commission.substring(0,commission.indexOf('.'));
				if (textbeforedecimal.length > 5)
				{			
				return false;
				}
				return true;
			}				
			
/* 
function name	:	isValidCommissionPCValue
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for minimum commission amount is of 2,2 format.
created by		:	Srinivas	
*/	
		
		
function isValidCommissionPCValue(CV)
		{
			
			var textafterdecimal;
			if (CV.lastIndexOf('.') == -1)
			{
				CV += ".";
			}
			textafterdecimal = CV.substring(CV.indexOf('.')+1, CV.length);
			
			if (textafterdecimal.length > 2)
			{
				return false;
			}
			var textbeforedecimal;
		
			textbeforedecimal = CV.substring(0,CV.indexOf('.'));
			if (textbeforedecimal.length > 2)
			{			
			return false;
			}
			return true;
		}//end of isValidCommissionPCValue
		
/* 
function name	:	isValidBinaryCommissionGroupVolume
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for group volueme amount is of 8,2 format.
created by		:	Srinivas	
*/	
		

function isValidBinaryCommissionGroupVolume(GV)
			{
				
				var textafterdecimal;
				if (GV.lastIndexOf('.') == -1)
				{
					GV += ".";
				}
				textafterdecimal = GV.substring(GV.indexOf('.')+1, GV.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;
			
				textbeforedecimal = GV.substring(0,GV.indexOf('.'));
				if (textbeforedecimal.length > 8)
				{			
				return false;
				}
				return true;
			}	//end of isValidBinaryCommissionGroupVolume					
		
/* 
function name	:	isValidBinaryCommissionValue
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for binary commission is of 8,2 format.
created by		:	Srinivas	
*/	
		

function isValidBinaryCommissionValue(GV)
			{
				
				var textafterdecimal;
				if (GV.lastIndexOf('.') == -1)
				{
					GV += ".";
				}
				textafterdecimal = GV.substring(GV.indexOf('.')+1, GV.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;
			
				textbeforedecimal = GV.substring(0,GV.indexOf('.'));
				if (textbeforedecimal.length > 8)
				{			
				return false;
				}
				return true;
			}	//end of isValidBinaryCommissionValue		
/* 
function name	:	isValidRankGroupVolume
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for rank group volume is of 8,2 format.
created by		:	Srinivas	
*/				
			
			
function isValidRankGroupVolume(GV)
			{
				
				var textafterdecimal;
				if (GV.lastIndexOf('.') == -1)
				{
					GV += ".";
				}
				textafterdecimal = GV.substring(GV.indexOf('.')+1, GV.length);
				
				if (textafterdecimal.length > 2)
				{
					return false;
				}
				var textbeforedecimal;
			
				textbeforedecimal = GV.substring(0,GV.indexOf('.'));
				if (textbeforedecimal.length > 8)
					{			
					return false;
					}
				return true;
			}	//end of isValidRankGroupVolume

/* 
function name	:	isValidMatrixCommissionValue
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to Check for matrix commission value is of 6,2 format.
created by		:	Srinivas	
*/	

function isValidMatrixCommissionValue(CV)
		{
			
			var textafterdecimal;
			if (CV.lastIndexOf('.') == -1)
			{
				CV += ".";
			}
			textafterdecimal = CV.substring(CV.indexOf('.')+1, CV.length);
			
			if (textafterdecimal.length > 2)
			{
				return false;
			}
			var textbeforedecimal;
		
			textbeforedecimal = CV.substring(0,CV.indexOf('.'));
			if (textbeforedecimal.length > 8)
			{			
			return false;
			}
			return true;
		}	//end of isValidMatrixCommissionValue
	

/* 


function name	:	Trim
input			:	string
ouput			:	string
Purpose			:	Trims all spaces to the left and right of a specific string by calling RTim and LTrim
created by		:	Srinivas	
*/	

// Trims all spaces to the left and right of a specific string by calling RTim and LTrim
function Trim(str){
	return RTrim(LTrim(str));
}//end function "Trim"

// Trims all spaces to the left of a specific string
function LTrim(str)	{
	var whitespace = new String(" \t\n\r "); 
	// last space character is not a space, but alt+0160, 
	// another invisible char. 
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		// We have a string with leading blank(s)...
		var j=0, i = s.length;
		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = s.substring(j, i);
	}//end if
	return s;
}//end function "LTrim"
		
// Trims all spaces to the right of a specific string
function RTrim(str){
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in whitespace
	var whitespace = new String(" \t\n\r "); 
	// last space character is not a space, but alt+0160,
	// another invisible char. 
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		// We have a string with trailing blank(s)...
		var i = s.length - 1;       // Get length of string
		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		// Get the substring from the front of the string to
		// where the last non-whitespace character is...
		s = s.substring(0, i+1);
	}//end if
	return s;
}//end function "RTrim"
		
	

/*
function doesImageExists(imagepath)
	{
		var objImage = new Image();
		objImage.onLoad=imageExists();
		objImage.onError=imageDoesnotExist();
		objImage.src=imagepath;
	}

function imageExists() 
	{
    return true;
	}

function imageDoesnotExist() 
	{
    return false;
	}
*/


		
/* 
function name	:	isValidUSZIP
input			:	string
ouput			:	boolean(true/false)
Purpose			:	check whether the ZIP code is valid
created by		:	Srinivas	
*/	
function isValidUSZIP(field) 
	{
			var valid = "0123456789-";
			var hyphencount = 0;

			if (field.length!=5 && field.length!=10) {			
			return false;
			}
			for (var i=0; i < field.length; i++) {
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {			
			return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {			
			return false;
			}
			}	
			return true;
	}//end of isValidUSZIP

// US Phone validation
/* 
function name	:	isValidUSPhone
input			:	string
ouput			:	boolean(true/false)
Purpose			:	check whether the Phone Number is valid
created by		:	Srinivas	
*/
function isValidUSPhone(value) 
	{	
	        //var reg = /^(([0-9\s-()]*){0,25})$/
			var reg = /^\([0-9]{3}\)\s?[0-9]{3}(-|\s)?[0-9]{4}$|^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$/
			return reg.test(value);		
				//var reg = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/				
			//return reg.test(value);					
	}//end of isValidUSPhone
function isValidUSPhone1(value) 
	{	
	        var reg = /^(([0-9\s-()]*){0,25})$/
			//var reg = /^([(]*\d{3}[-)]\s*\d{3}(\-)\d{4}$)|(\d{10}$)$/
			return reg.test(value);		
				//var reg = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/				
			//return reg.test(value);					
	}//end of isValidUSPhone
	
function isValidUSZIP1(value) 
	{	
			var reg = /^(([A-Za-z0-9\s-]*){0,25})$/;
			return reg.test(value);		
				//var reg = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/				
			//return reg.test(value);					
	}//end of isValidUSPhone
	
			
			
//Functions for Date Pick-up from Calender Control.

var calendar = null;
var last_date = null;

function selected(cal, date, eventTarget) {
	last_date = cal.date;	
	var el = document.getElementById(eventTarget);
	el.style.background="#fff";
	el.value = date;
}//end function

function closeHandler(cal) {
	last_date = cal.date;		
	cal.destroy();
	calendar = null;
}//end function

/*
function testCal(eventTarget) 
	{
		if (calendar) return;
		var sel = document.getElementById(eventTarget);				
		var cal = new Calendar(true, last_date, selected, closeHandler, eventTarget);
		calendar = cal;
		cal.setRange(1900, 2070);
		var el = cal.element;
		el.style.left = sel.offsetLeft + 200 + "px";
		//el.style.top = sel.offsetTop + 1 + sel.offsetHeight + "px";
		el.style.top = sel.offsetTop + 400 + "px";
		el.style.visibility = "visible";
	}
//End Functions		
*/
	
function OpenCalender(eventTarget,lef,top) {
	if (calendar) return;
	var sel = document.getElementById(eventTarget);				
	var cal = new Calendar(true, last_date, selected, closeHandler, eventTarget);
	calendar = cal;
	cal.setRange(1900, 2070);
	var el = cal.element;
	el.style.left = sel.offsetLeft + lef + "px";
	//el.style.top = sel.offsetTop + 1 + sel.offsetHeight + "px";
	el.style.top = sel.offsetTop + top + "px";
	el.style.visibility = "visible";
}//End Functions		
 
/* 
function name	:	isGrossOrderAmountMaxLength {checkNumberBinaryGroupValueMaxLength}
input			:	string
ouput			:	boolean(true/false)
Purpose			:	checks the GrossOrderAmount Max length
created by		:	Prasad	
*/
function isGrossOrderAmountMaxLength(strValue){
	var mainText							
	if (strValue.lastIndexOf('.') == -1){
		strValue += ".";
	}//end if
	mainText = strValue.substring(0,strValue.indexOf('.'));
	if (mainText.length > 8){			
		return false;
	}//end if
	return true;
}//end function
		
/* 
function name	:	isGrossOrderAmountTwoDecimals {BinaryCommissionGroupVolume}
input			:	string
ouput			:	boolean(true/false)
Purpose			:	checks the GrossOrderAmount for two decimals
created by		:	Prasad	
*/
function isGrossOrderAmountTwoDecimals(CV){
	var textafterdecimal;
	if (CV.lastIndexOf('.') == -1){
		CV += ".";
	}//end if
	textafterdecimal = CV.substring(CV.indexOf('.')+1, CV.length);
	if (textafterdecimal.length > 2){
		return false;
	}//end if
	return true;
}//end function
			
		
//************************Date Validation Javascript****************************		
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2001;
var maxYear=2050;

function ismyInteger(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;
	}//end for-loop
	// All characters are numbers.
	return true;
}//ismyInteger

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}//end for-loop
	return returnString;
}//stripCharsInBag

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 );
}//daysInFebruary

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	}//end for-loop
	return this
}//DaysArray

function ismyDate(dtStr,lbltxt){		
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}//end for-loop
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	var datenull = Trim(dtStr) != "";
	if ((pos1==-1 || pos2==-1) && (datenull==true)){				
		lbltxt.innerText = msg_common_invaliddate;
		return false
	}//end if
	if ((strMonth.length<1 || month<1 || month>12) && (datenull==true)){				
		lbltxt.innerText = msg_reports_validmonth;
		return false;
	}//end if
	if ((strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]) && (datenull==true)){				
		lbltxt.innerText = msg_reports_validday;
		return false;
	}//end if
	if ((strYear.length != 4 || year==0 || year<minYear || year>maxYear) && (datenull==true)){								
		lbltxt.innerText = msg_common_invaliddate;
		return false;
	}//end if
	if ((dtStr.indexOf(dtCh,pos2+1)!=-1 || ismyInteger(stripCharsInBag(dtStr, dtCh))==false) && (datenull==true)){			
		lbltxt.innerText = msg_common_invaliddate;
		return false;
	}//end if
	return true
}//end function "ismyDate"

// Funcation For Validating Date of Birth

/* 
function name	:	isValidBirthDate
input			:	dateStr,ErrorBirthDateControlID
ouput			:	boolean(true/false)
Purpose			:	check whether the Date of Birth is valid
created by		:	Srinivas	
*/
		
function isValidBirthDate(dateStr,ErrorBirthDateControlID) 
	{
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
		// Also separates date into month, day, and year variables
		
		var mydate= new Date();
		var theyear=mydate.getFullYear();
		var minYear = (theyear - 120);
		
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

		// To require a 4 digit year entry, use this line instead:
		// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) 
		{
			//alert("Date is not in a valid format.")
			ErrorBirthDateControlID.innerText = msg_common_birthdate;
			return false;
		}
			month = matchArray[1]; // parse date into variables
			day = matchArray[3];
			year = matchArray[4];
		if (month < 1 || month > 12) 
		{ // check month range
			//alert("Month must be between 1 and 12.");
			ErrorBirthDateControlID.innerText = msg_common_birthdatemonth;
			return false;
		}
		if (day < 1 || day > 31) 
		{
			//alert("Day must be between 1 and 31.");
			ErrorBirthDateControlID.innerText = "Day must be between 1 and 31.";
			return false;
		}
		if (year < minYear )
		{
			ErrorBirthDateControlID.innerText = "Year in invalid.";
			return false;
		}
		
		if (year > theyear)
		{
			ErrorBirthDateControlID.innerText = "Year in invalid.";
			return false;
		}
		
		if ((month==4 || month==6 || month==9 || month==11) && day==31) 
		{
			if (month == 4)
			{
				month = "April";
			}
			else if (month==6)
			{
				month = "June";
			}
			else if (month==9)
			{
				month = "September";
			}
			else if (month==9)
			{
				month = "November";
			}
			ErrorBirthDateControlID.innerText = "Month " + month + " doesn't have 31 days!";
			return false;
		}
		if (month == 2) 
		{ // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) 
			{
				//alert("February " + year + " doesn't have " + day + " days!");
				ErrorBirthDateControlID.innerText = "February " + year + " doesn't have " + day + " days!";
				return false;
			}
		}
		else
		return true;  // date is valid
	}
//  End of Date of Birth Function-->

// Credit Card Validation

/*  ================================================================
	FUNCTION	: validateCard()
	 
	INPUT		: cardNumber,cardType,cardMonth,cardYear.ErrorConrolid

	RETURNS		: true, if CreditCard is valid. false, otherwise
	    
	DESCRIPTION	: Causes validation on four major credit cards like
				  visa, master, amex, discover and validates the
				  respective card numbers and expiry date.
				  expiry date shouldn't be less than the current month.
					 
	================================================================ */
    
		function validateCard(cardNumber,cardType,cardMonth,cardYear,IdErrorLabel,IdCreditCard,IdYear,IdYearErrorLabel) 
		{
        	/*if( cardNumber.length == 0 ) 
        	{						//most of these checks are self explanitory
        		alert("Please enter a valid card number.");
        		return false;				
        	}*/
        	/*
        	
        	1	Visa
			2	Master Card
			3	Amex
			4	Discover
		*/
        	
        	for( var i = 0; i < cardNumber.length; ++i ) 
        	{		// make sure the number is all digits.. (by design)
        		var c = cardNumber.charAt(i);


            		if( c < '0' || c > '9' ) 
            		{
            			IdErrorLabel.innerText = msg_common_integeronly;
            			IdCreditCard.select();
            			IdCreditCard.focus();
            			return false;
            		}
            }
            	var length = cardNumber.length;			//perform card specific length and prefix tests


                	switch( cardType )
                	 {
                		case '3'://American Express


                    			if( length != 15 )
                    			{
                    				IdErrorLabel.innerText = msg_common_americanexpresscardnumber;
                    				IdCreditCard.select();
            						IdCreditCard.focus();
                    				return;
                    			}
                    			var prefix = parseInt( cardNumber.substring(0,2));


                        			if( prefix != 34 && prefix != 37 ) 
                        			{
                        				IdErrorLabel.innerText = msg_common_americanexpresscardnumber;
                    					IdCreditCard.select();
            							IdCreditCard.focus();
                        				return;
                        			}
                        			break;
                        		case '4'://Discovery 


                            			if( length != 16 ) 
                            			{
                            				IdErrorLabel.innerText = msg_common_discoverynumber;
                            				IdCreditCard.select();
            								IdCreditCard.focus();
                            				return;
                            			}
                            			var prefix = parseInt( cardNumber.substring(0,4));


                                			if( prefix != 6011 ) 
                                			{
                                				IdErrorLabel.innerText = msg_common_discoverynumber;
                            					IdCreditCard.select();
            									IdCreditCard.focus();
                                				return;
                                			}
                                			break;
                                		case '2'://Master card


                                    			if( length != 16 ) 
                                    			{
                                    				IdErrorLabel.innerText = msg_common_mastercardnumber;
                                    				IdCreditCard.select();
            										IdCreditCard.focus();
                                    				return;
                                    			}
                                    			var prefix = parseInt( cardNumber.substring(0,2));


                                        			if( prefix < 51 || prefix > 55) 
                                        			{
                                        				IdErrorLabel.innerText = msg_common_mastercardnumber;
                                        				IdCreditCard.select();
            											IdCreditCard.focus();
                                        				return;
                                        			}
                                        			break;
                                        		case '1'://visa


                                            			if( length != 16 && length != 13 ) {
                                            				IdErrorLabel.innerText = msg_common_visacardnumber;
                                            				IdCreditCard.select();
            												IdCreditCard.focus();
                                            				return;
                                            			}
                                            			var prefix = parseInt( cardNumber.substring(0,1));


                                                			if( prefix != 4 ) {
                                                				IdErrorLabel.innerText = msg_common_visacardnumber;
                                            					IdCreditCard.select();
            													IdCreditCard.focus();
                                                				return;
                                                			}
                                                			break;
                                                	}
                                                	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
                                                		IdErrorLabel.innerText = msg_common_validcreditcardnumber;
                                            			IdCreditCard.select();
            											IdCreditCard.focus();
                                                		return false;
                                                	}
                                                	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
                                                		IdYearErrorLabel.innerText = "Sorry! The expiration date you have entered would make this card invalid.";
                                                		IdYear.focus();
                                                		return false;
                                                	}
                                                	
                                                	return true; // at this point card has not been proven to be invalid
                                            }
                                            
  /*  ================================================================
    FUNCTION	:  expired()
 
    INPUT		:  month, year

    RETURNS		:  true, if expiry date is valid. false, otherwise
    
    DESCRIPTION	: Causes validation on the Expiry month and year.
				  Expiry month and year shouldnt be less than the current.
	Created By	: Srinivas	
    ================================================================ */
    
	function expired( month, year )
		 {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
        	//  expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
        	if( now.getTime() < expiresIn.getTime() ) return false;
        	return true;									// then we get the miliseconds, and do a long integer comparison
		 }     
		 
		 
/*  ================================================================
    FUNCTION: mod10()
 
    INPUT	   : month, year

    RETURNS	   : true, if cardNumber length and mod 10 is divisible and returns 0,
				 false, otherwise
    
    DESCRIPTION: Causes validation on the Credit Card Number using
				 LUHN Formula for validation of credit card numbers
				 Expiry month and year shouldnt be less than the current.
	Created By : Srinivas
    ================================================================ */
		
		function mod10( cardNumber ) 
		{ 
			// LUHN Formula for validation of credit card numbers.
			var ar = new Array( cardNumber.length );
			var i = 0,sum = 0;

	    	for( i = 0; i < cardNumber.length; ++i ) 
	    	{
    			ar[i] = parseInt(cardNumber.charAt(i));
    		}
    		
    		for( i = ar.length -2; i >= 0; i-=2 ) 
    		{ 
    		// you have to start from the right, and work back.
    		ar[i] *= 2;			
    		
    		// every second digit starting with the right most (check digit)
    		// will be doubled, and summed with the skipped digits.
    		// if the double digit is > 9, ADD those individual digits together 
    		
    		if( ar[i] > 9 ) ar[i]-=9;
    		}
    	
        	for( i = 0; i < ar.length; ++i ) 
        	{
        		sum += ar[i];		 // if the sum is divisible by 10 mod10 succeeds
        	}
        	return (((sum%10)==0)?true:false);	 	
		 }	
		 
// End of Credit Card Validation		 	                                      
	 function ismyDate(dtStr,lbltxt)
        {		
	       
	        var daysInMonth = DaysArray(12)
	        var pos1=dtStr.indexOf(dtCh)
	        var pos2=dtStr.indexOf(dtCh,pos1+1)
	        var strMonth=dtStr.substring(0,pos1)
	        var strDay=dtStr.substring(pos1+1,pos2)
	        var strYear=dtStr.substring(pos2+1)
	        strYr=strYear
	        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	        for (var i = 1; i <= 3; i++) 
	        {
		        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	        }
	        month=parseInt(strMonth)
	        day=parseInt(strDay)
	        year=parseInt(strYr)
        	
	        var datenull = Trim(dtStr) != "";
	        if ((pos1==-1 || pos2==-1) && (datenull==true))
	        {				
		        //lbltxt.innerText = msg_common_invaliddate;
		        alert(msg_common_invaliddate);
		        return false
	        }

	        if ((strMonth.length<1 || month<1 || month>12) && (datenull==true))
	        {				
		        //lbltxt.innerText = msg_reports_validmonth;
		        alert(msg_reports_validmonth);
		        return false;
	        }
	        if ((strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]) && (datenull==true))
	        {				
		        //lbltxt.innerText = msg_reports_validday;
		        alert(msg_reports_validday);
		        return false;
	        }
	        if ((strYear.length != 4 || year==0 || year<minYear || year>maxYear) && (datenull==true))
	        {								
		        //lbltxt.innerText = msg_common_invaliddate;
		        alert(msg_common_invaliddate);
		        return false;
	        }
	        if ((dtStr.indexOf(dtCh,pos2+1)!=-1 || ismyInteger(stripCharsInBag(dtStr, dtCh))==false) && (datenull==true))
	        {			
		        //lbltxt.innerText = msg_common_invaliddate;
		        alert(msg_common_invaliddate);
		        return false;
	        }
	        return true
        }	
/*
End of Common Functions Section
*/

//-----------------------------------------Common Functions Section Ends-------------------------

	
