//function to set the focus on the selected menu item
	function mfnHilight(s)
	{
		var linklength=document.all.tags("A");
		for (i=0; i<linklength.length;i++)
		{
			if (linklength[i].name.substring(0,1)=="L")
			{				
			  if (linklength[i].name=='L'+s) linklength[i].className='MenuBarSel';				
			  else linklength[i].className='MenuBar';
			}
		}
	}
//

/*
Purpose : Returns a copy of a string without leading and trailing spaces.
Parameters :
	1.	String that needs to be trim
Returns : String without leading and trailing spaces.
*/
function trim(st)
{
	if(st.length > 0)
	{
		re = / +$/g; 
		newval = st.replace(re,"")
		re = /^ +/g;
		newvala = newval.replace(re,"")
		return newvala;
	}
	return ""
}

/*
Purpose : To check whether the control is blank or not.
Parameters :
	1.	Object Refernce to the control.
Returns : Boolean Variable.
*/
function isBlank(cntrl)
{
	cntrl.value = trim(cntrl.value);
	if (cntrl.value=="")
		return true;
	else
		return false;
}

/*
Purpose : To check the length for textarea cntrl.
Parameters :
	1.	Object Refernce to the control.
	2.	Boolean value to insure that field is mandatory.
	3.	Numeric value for maxlength allowed.
	4.	String message for the control i.e., "Mailing address".
Returns : Boolean Variable.
*/
function isProperLength(cntrl,mandatory,maxlength,refmsg)
{
	if (isBlank(cntrl))
	{
		if (mandatory)
		{
			alert("Please enter " + refmsg + " !!!");
			return false;
		}		
	}
	else if(cntrl.value.length > maxlength)
	{
		alert("Please enter maximum of " + maxlength + " characters in " + refmsg);
		return false;
	}
	return true;
}

/*
Purpose : To check the whether the object contains numeric value or not.
Parameters :
	1.	Object Refernce to the control.
	2.	Boolean value to insure that field is mandatory.
	3.	String message for the control i.e., "Salary Expected".
Returns : Boolean Variable after throughing a proper message.
*/
function isNumeric(val)
{
	if (parseFloat(val,10)==0)
	{
		alert("Please enter only numeric value !!!");
		return false;			
	}
	
	if(parseFloat(val,10)!=(val*1))
	{
		alert("Please enter only numeric value !!!" );
		return false;
	}
	return true;
}

/*
Purpose : To check the email structure.
Parameters :
	1.	Object Refernce to the control.
	2.	Boolean value to insure that field is mandatory.
Returns : Boolean Variable after throughing a proper message.
*/
function isEmail(cntrl,mandatory)
{
	if (isBlank(cntrl))
	{
		if (mandatory)
		{
			alert("Please enter E-mail Address !!!");
			return false;
		}
	}
	else
	{
		emailid = cntrl.value;
		if (emailid.indexOf(' ') > 0)
		{
			alert("Space is not allowed in Email Address !!!");
			return false;
		}
		if ((emailid.indexOf('@') == 0) || (emailid.indexOf('.') == 0))
		{
			alert("'.' or '@'  not allowed as first character in Email Address !!!");
			return false;		
		}
		if ((emailid.indexOf('@') == -1) || (emailid.indexOf('.') == -1))
		{
			alert("Please enter valid E-mail Address");
			return false;
		}
		var Dot= emailid.split('.');
		var Atr= emailid.split('@');
		if (Atr.length>2)
		{
			alert("Invalid Position Of '@' in E-mail Address");
			return false;
		}
		var AtPos=emailid.indexOf('@');
		var DotPos=emailid.indexOf('.');
		var DotLPos=emailid.lastIndexOf('.');

		if (Dot.length>2)
		{
			if (emailid.indexOf('@')>emailid.lastIndexOf('.'))
			{
				alert("Invalid Position Of '.' in E-mail Address");
				return false;
			}
			if (AtPos>DotPos) //---------- .@
			{
				if ((AtPos-DotPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			else
			{
				if ((DotPos-AtPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			if ((DotLPos-AtPos)<2)
			{
				alert("Invalid Position Of '.' in E-mail Address");
				return false;
			}
		}
		else
		{
			if (AtPos>DotPos) //---------- .@
			{
				if ((AtPos-DotPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			else
			{
				if ((DotPos-AtPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}				
		}
		if (DotLPos>(emailid.length-3))
		{
			alert("Invalid Length after '.'  !!!");
			return false;
		}
	}
	return true;
}
//Phone

function isPhone(obj)
{
	var loopIndex=0
	var mFlag = false
	var mChar=0
	for(loopIndex=0;loopIndex<obj.value.length && !mFlag;loopIndex++){
		mChar = obj.value.charCodeAt(loopIndex)
		if( (mChar>=48 && mChar <=57) || (mChar==44) || (mChar==45) || (mChar==43)  || (mChar==40)  || (mChar==41))
				mFlag=false
		else
				mFlag = true
	}
	if(mFlag)
	{	//return error code
		alert("Invalid Phone/Fax Number !")
		obj.focus()
		return false
	}
	return true
}
// selected count 
function checkedListCountEx(mListRef,chkboxName)
{
		 var i=0;
		 var mCount=0;
		 var mLength=0;
		 for (i=0; i<mListRef.elements.length; i++)
		 {
			if ((mListRef.elements[i].type=="checkbox") && (chkboxName==mListRef.elements[i].name))
			{					
				if (mListRef.elements[i].checked==true)
				{
					mCount++;					
				}				
			}			
		 }		 
		 return(mCount);		 
}
//Selected check box value
function GetValcheckedList(mListRef,chkboxName)
{
		 var i=0;
		 var mCount=0;
		 var mLength=0;
		 for (i=0; i<mListRef.elements.length; i++)
		 {
			if ((mListRef.elements[i].type=="checkbox") && (chkboxName==mListRef.elements[i].name))
			{					
				if (mListRef.elements[i].checked==true)
				{
					
					mCount=mListRef.elements[i].value;
					break;
				}				
			}			
		 }		 
		 return(mCount);		 
}

//WEB
function isWEB(cntrl)
{
		var Web= cntrl.value.toUpperCase();
		var mFlag;
		for(loopIndex=0;loopIndex<Web.length && !mFlag;loopIndex++)
		{
			mChar = Web.charCodeAt(loopIndex);
			if( (mChar>=65 && mChar <=90) || (mChar>=48 && mChar <=57) || mChar==46 || mChar==45 || mChar==47)
				mFlag=false
			else
				mFlag = true
		}
		if(mFlag)
		{	//return error code
			alert("Invalid characters in URL Value!")
			cntrl.focus()
			return false
		}
		var Dot=Web.split('.');
		if (Dot.length<3)
		{alert('Invalid URL !!!');return false }
	return true;
}
//mm/dd/yyyy format
function isDate(dateStr) {
    var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;// pattern
    var matchArray = dateStr.match(datePat); // is the format ok?
	mDt=new Date(dateStr);

    if (matchArray == null) {
        alert("Please Enter Date as \'mm/dd/yyyy\'");
        return false;
    }

    month = parseInt(matchArray[1],10); // parse date into variables
    day = parseInt(matchArray[3],10);
    year = parseInt(matchArray[5],10);

    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12.");
        return false;
    }

    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Month "+getMonth(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!");
            return false;
        }
    }

	if ((year<1753) || (year>9999))
	{
		alert('Year must be between 1754 to 99999');
		return false;
	}
	/*
		var nDate=new Date();
		var nowTime = nDate.getTime();  // current time (UTC)
		var thenTime = Date.UTC(year, month-1, day);  // specified time (UTC)
		if(nowTime<=thenTime)
		{
			alert('Transaction Date cannot be a Future date..');return false
		}
	*/	
    return true; 
}

function getMonth(intMonth)
{
	var mName;
	switch(intMonth-1)
	{
		case 0:mName='January';break;
		case 1:mName='February';break;
		case 2:mName='March';break;
		case 3:mName='April';break;
		case 4:mName='May';break;
		case 5:mName='June';break;
		case 6:mName='July';break;
		case 7:mName='August';break;
		case 8:mName='September';break;
		case 9:mName='October';break;
		case 10:mName='November';break;
		case 11:mName='December';break;
	}
	return mName;
}
// function to show help
function ShowHelp(mAnch)
{
	var w=520;
	var h=300;	
	var t=0;
	var l=0;
	var mfName;
	l=(screen.width/2)-(w/2);
	t=(screen.height/2)-(h/2);
	mfName='adm-help.asp';
	var N=window.open ('adm-help.asp#'+mAnch,'AdminHelp','resizable=no,status=no,toolbars=no,scrollbars=yes,height='+h+',width='+w+',left='+l+',top='+t+'');
	N.focus();
}

//function to redirect 
function Redirect() 
{
	window.location.href='uc.asp';
}
//Redirect();

// function to New Window
function ShowWin(ww,hh,url)
{
	var t=0;
	var l=0;
	var mfName;
	l=(screen.width/2)-(ww/2);
	t=(screen.height/2)-(hh/2);
	mfName=url;
	var NW=window.open (mfName,'NewWin','resizable=no,status=no,toolbars=no,scrollbars=yes,height='+hh+',width='+ww+',left='+l+',top='+t+'');
	NW.focus();
}
// high light for top user menu
function menuHilight(s)
{
	var linklength=document.all.tags("A");
	for (i=0; i<linklength.length;i++)
	{
		if (linklength[i].name.substring(0,1)=="L")
		{				
		  if (linklength[i].name=='L'+s) linklength[i].className='textWhitetopS';				
		  else linklength[i].className='textWhitetop';
		}
	}
}

function isDecimal(fValue,fDecimal,fMandatory) {
	if (fDecimal==null)decallowed = 2; // default decimal place
	else decallowed = fDecimal;


	if (isNaN(fValue))
	{
		alert("Please Enter a Valid Number !!!");
		return false;
	}
	if (fMandatory)
	{
		if (parseFloat(fValue,10)<=0)
		{
			alert('Please enter some value !!!')
			return false;
		}
	}

	if (fValue.indexOf('.') == -1) fValue += ".";
	dectext = fValue.substring(fValue.indexOf('.')+1, fValue.length);
	if (dectext.length > decallowed)
	{
		alert ("Please enter a number with up to " + decallowed + " decimal places !!!");
		return false;
	}

   return true;
}
function isSmaller(sValue,fValue)
{
    var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;// pattern
    var sArray = sValue.match(datePat); 
	var fArray = fValue.match(datePat); 

	sMonth = parseInt(sArray[3],10); // parse date into variables
    sDay = parseInt(sArray[1],10);
    sYear = parseInt(sArray[5],10);


    fMonth = parseInt(fArray[3],10); // parse date into variables
    fDay = parseInt(fArray[1],10);
    fYear = parseInt(fArray[5],10);
	var sTime = Date.UTC(sYear, sMonth-1, sDay);
	var fTime = Date.UTC(fYear, fMonth-1, fDay);

	if(sTime<fTime)
	{
		return false
	}
	return true;
}


