/*
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 checkAlphaNumeric(str)
	{
	var constraints='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var constraints_length=constraints.length;
	var str_length=str.length;
	
	for(var counter=0;counter<str_length;counter++)
		{
		var flag=false;
		var targetchar=str.charAt(counter);
		for(var pointer=0;pointer<constraints_length;pointer++)
			{
		if(targetchar==constraints.charAt(pointer))
				{
			flag=true;
			break;
				}
			}
         if(flag==false)
			{
			 return false;
			}
		}
  return true;
	}

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(cntrl,mandatory,refmsg,zeroallowed)
{
	if (isBlank(cntrl))
	{
		if (mandatory)
		{
			alert("Please enter " + refmsg + " !!!");
			return false;
		}		
	}
	else
	{
		val = cntrl.value;
		if ((!zeroallowed) && (parseFloat(val)==0))
		{
			alert("Zero is not applicable for " + refmsg);
			return false;			
		}
		
		if(parseFloat(val,10)!=(val*1))
		{
			alert("Please enter only numeric value for " + refmsg);
			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 number !") 
		obj.focus()
		return false
	}
	return true
}

//
function isPhone1(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 Country Code Number !") 
		obj.focus()
		return false
	}
	return true
}
//
function isPhone2(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 City Code Number!") 
		obj.focus()
		return false
	}
	return true
}

//
function isFax(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 Fax Number!") 
		obj.focus()
		return false
	}
	return true
}

//

function isMobile(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 Mobile Number!") 
		obj.focus()
		return false
	}
	return true
}

//

function isPin(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 Pin/Zip 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 = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    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;
}



// Amazing Frameless Popup Window - Version I
// (C) 2000 www.CodeLifter.com
// Free for all users, but leave in this  header

// set the popup window width and height

var windowW=600 // wide
var windowH=500 // high

// set the screen position where the popup should appear

var windowX = 300 // from left
var windowY = 200 // from top

// set the url of the page to show in the popup

var urlPop = "term.asp"

// set the title of the page

var title =  "This Is A Frameless Popup Window"

// set this to true if the popup should close
// upon leaving the launching page; else, false

var autoclose = true

// ============================
// do not edit below this line
// ============================

s = "width="+windowW+",height="+windowH;
var beIE = document.all?true:false

function openFrameless(){
  if (beIE){
    NFW = window.open("","","fullscreen,"+s)     
    NFW.blur()
    window.focus()       
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
    var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"+
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
    NFW.document.open();
    NFW.document.write(frameString)
    NFW.document.close()
  } else {
    NFW=window.open(urlPop,"popFrameless","scrollbars,"+s)
    NFW.blur()
    window.focus() 
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
  }   
  NFW.focus()   
  if (autoclose){
    window.onunload = function(){NFW.close()}
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flevGetDivProperty() { // v1.0
	this.opera = (window.opera); this.ns4 = (document.layers); this.ie = (document.all);
	this.ns6 = (document.getElementById && !document.all && !this.opera);
    var sV = "", sD = arguments[0], oD = MM_findObj(sD), sP = arguments[1]; if (oD == null) {return 0;}
	var sF = (sD.indexOf("?") > 0) ? sD.substring(sD.indexOf("?")+1) : "";
	if ((sF != "") && (this.ie)) {sD = "parent.frames['" + sF + "']." + sD.substring(0,sD.indexOf("?"));}
	if ((sP == "left") || (sP == "top")) {
		if (!this.ns4) {oD = oD.style;} sV = eval("oD." + sP);
		if ((this.ie) && (sV == "")) { // IE (on PC) bug with nested layers
			if (sP == "top") { sV = eval(sD + ".offsetTop");} 
			else { sV = eval(sD + ".offsetLeft");}}}
	else {if (this.opera) {oD = oD.style;
			if (sP == "height") { sV = oD.pixelHeight;} 
			else if (sP == "width") { sV = oD.pixelWidth;}}
		else if (this.ns4) {sV = eval("oD.clip." + sP);} 
		else if (this.ns6) {sV = document.defaultView.getComputedStyle(oD, "").getPropertyValue(sP);} 
	    else if (this.ie) { 
			if (sP == "width") {sV = eval(sD + ".offsetWidth");} 
			else if (sP == "height") {sV = eval(sD + ".offsetHeight");}}}
	sV = (sV == "") ? 0 : sV; if (isNaN(sV)) {if (sV.indexOf('px') > 0) { sV = sV.substring(0,sV.indexOf('px'));}} 
	return parseInt(sV); 
}

function flevMoveDiv(sD, sX, sY){ // v1.4
	var	oD = MM_findObj(sD), sS=""; if (!oD) {return;}
	if (!document.layers) {oD = oD.style;} // not NS4.x 
	if((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
	if (sX != "") {eval("oD.left = '" + sX + sS + "'");}
	if (sY != "") {eval("oD.top = '" + sY + sS + "'");}
}

function flevAutoScrollDivs() { // v1.2
	var aA = arguments, iA = aA.length, oD = MM_findObj('AutoScrollContainer'); if (!oD) {return;}
	if (oD.scrollTimeout != null) {clearTimeout(oD.scrollTimeout);}
	var sID1 = 'AutoScrollContainer', sID2 = 'AutoScrollContent';   
	var iSS = (iA > 0) ? parseInt(aA[0]) : 1, iPx = (iA > 1) ? parseInt(aA[1]) : 1;   
	var iMs = (iA > 2) ? parseInt(aA[2]) : 50;   
	var iST = (-1 * flevGetDivProperty(sID2, 'height')), iSB = flevGetDivProperty(sID1, 'height');   
	var iCX = flevGetDivProperty(sID2, 'left'), iCY = flevGetDivProperty(sID2, 'top');  
	if (iSS) {if (iCY >= iST) {flevMoveDiv(sID2, String(iCX), String(iCY-iPx));}	// Continue scrolling   
		else {flevMoveDiv(sID2, String(iCX), String(iSB));}	// Re-position scrolling layer at bottom of container  
		oD.scrollTimeout = setTimeout("flevAutoScrollDivs(" + iSS + "," + iPx + "," + iMs + ")", iMs);}   
}

