﻿
//Function to truncate the string
function trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}

//Numeric values are allowed
function NumericQuantityTextBox(txtCntrl)
{
    var txtCntrl = document.getElementById(txtCntrl).value;

    //txtCntrl.length = 3 is used so that user can enter not more than 999 quantity.
    // 46 for Delete Key and 8 for Back Key
    // 144 for Nums Lock Key
    // ((event.keyCode>95) &&  (event.keyCode<106)) for 0-9 when Nums Lock is Pressed
    // ((event.keyCode>47) &&  (event.keyCode<58)) for 0-9 
    // 39 Right Array Key, 37 left Arrow Key
    if ((((event.keyCode>47) &&  (event.keyCode<58)) || ((event.keyCode>95) &&  (event.keyCode<106)) || (event.keyCode==8) || (event.keyCode==39) || (event.keyCode==37) || (event.keyCode==144)  || (event.keyCode==46)) && (txtCntrl.length<3)|| (event.keyCode==8) || (event.keyCode==46)) // With Max Length 3, Delete and Back is allowed
        return true;
    else
        return false;
}

//sending the Top Position of Calendar popup, when height of the image (company Logo) is changed
function Calendar(eleId)
{
    if(self.gfPop)
        gfPop.fPopCalendar(document.getElementById(eleId),0)
}

function ValidatorEnableBulkNSubmit(ValidatorNames, EnableDisable)
{
	for (var t = 0; t < Page_Validators.length; t++) 
	{ 
		if(Page_Validators[t]!=null && Page_Validators[t] != "undefined" )
		{
			var newArray = ValidatorNames.split(",");
			for (var j=0;j<newArray.length;j++)
			{
				if (newArray[j]!="")
				{
					if (Page_Validators[t].id == newArray[j])
						ValidatorEnable(Page_Validators[t],EnableDisable);		
				}
			}
		}
	}
	return Page_ClientValidate();
}

function EnableValidatorNSubmit(enableValidator)
{
    if(Page_Validators!=null && Page_Validators != "undefined")
    {
	    for (i = 0; i < Page_Validators.length; i++) 
	    { 
		    if(Page_Validators[i]!=null)
		    {
			    ValidatorEnable(Page_Validators[i],enableValidator);		
    			
		    }
	    }
	    return Page_ClientValidate();
	}
}

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 VisibleControl(controlID1, controlID2)
{
	if ((document.getElementById(controlID1)!=null) && (document.getElementById(controlID2)!=null))
	{
		document.getElementById(controlID1).style.display='';
		document.getElementById(controlID2).style.display='';
	}

}

function InVisibleControl(controlID1, controlID2)
{
	if ((document.getElementById(controlID1)!=null) && (document.getElementById(controlID2)!=null))
	{

	document.getElementById(controlID1).style.display='none';
	document.getElementById(controlID2).style.display='none';
	}
}


function IsDate(dateStr)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) 
		return false;
	
	day = matchArray[1]; // p@rse date into variables
	month = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) // check month range
		return false;

	if (day < 1 || day > 31) 
		return false;

	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
		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)) 
		{
			return false;
		}
	}
	return true; // date is valid
}


function OpenHelpPageforReschedule()
{
	window.open('../Help/RescheduleOrder.htm','Help','height=650,width=810,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
}
function OpenRescheduleHelpPage()
{
	window.open('../Help/RescheduleHelp.htm','Help','height=650,width=810,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
}
function OpenHelpPageforAgentReschedule()
{
	window.open('../Help/AgentReschedule.htm','Help','height=650,width=810,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
}
function OpenAgentRescheduleHelp()
{
	window.open('../Help/AgentRescheduleHelp.htm','Help','height=650,width=810,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
}