//Copyright© 1998. ZYX Productions. All rights reserved.
//**Start Encode**

NN4=((parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<5)&&(navigator.appName.indexOf("Netscape")!=-1))?1:0
NN6=((parseInt(navigator.appVersion)>=5)&&(navigator.appName.indexOf("Netscape")!=-1))?1:0
MS4=((parseInt(navigator.appVersion)>=4)&&(navigator.appName.indexOf("Microsoft")!=-1))?1:0

function f_get_elem(i)
{
if(NN6)			return(document.getElementById(i));
else if(NN4)	return(document.layers[i]);
else			return(document.all[i]);
}

function f_set_elem(i,x)
{
//alert("nn4="+NN4+",nn6="+NN6+",ms4="+MS4);
//alert("i="+i+",x="+x);
if(NN6)			document.getElementById(i).childNodes[0].nodeValue = x;
else if(NN4)	document.layers[i].innerText = x;
else			document.all[i].innerText = x;
}



function trim(s) {

	while( s.charAt(0)==" " ) {
		s = s.substr(1);
		}
	while( s.charAt(s.length-1)==" " ) {
		s = s.substr(0,s.length-1);
		}
	return(s);
}


function showpane_custom(PaneLocation,PaneTitle,w,h) 
{	
window.open(PaneLocation,PaneTitle,"toolbar=no,status=no,menubar=no,location=no,resizable=no,scrollbars=no,width=" + w + ",height=" + h);
}


function f_set_bg_col(d,sCol)
{
if(NN6)			d.style.backgroundColor = sCol;
else if(NN4)	d.style.bgColor = sCol;
else			d.style.backgroundColor = sCol;
}

function f_get_list_item(sID)
{
var sVal="";
var idx;
idx = document.frmMain["" + sID].selectedIndex;
if(idx>=0) {
	sVal = document.frmMain["" + sID][idx].value;
	}
return( sVal );
}

function f_does_element_exist(sName)
{
for(a=0;a<document.frmMain.elements.length;a++) {
	if(document.frmMain.elements[a].name==sName) 
		return(1);
	}
return(0);
}

function FmtNum(n,dec_places,commas)
{
var temp;
var a;
var l1="";
var n1="",e1="",s="";
n1 = n.toString();
if(n1=='NaN') {
	s='0';
	return(s);
	}
pose = n1.indexOf("e");
if(pose>-1) {
	e1 = n1.substr(pose,n1.length-pose);
	n = n1.substr(0,pose);
	}
temp=Math.round(n*Math.pow(10,dec_places))/Math.pow(10,dec_places);

l1 = temp.toString();
if(dec_places==0) {
	if(commas==true)	l1 = AddCommas(l1);
	s = l1 + e1;
	}
else {
	posdot = l1.lastIndexOf(".");
	if((posdot==-1)) {
		l1 += ".";
		posdot = l1.lastIndexOf(".");
		}
	p1 = l1.substr(0,posdot);		//returns x  --> x.yy  
	p2 = l1.substr(posdot,l1.length-posdot);  //returns .yy
	for(a=0;a<dec_places-(l1.length-posdot)+1;a++) {
		p2 += "0";
		}			
	if(commas==true) {
		p1 = AddCommas(p1);
		}
	s = p1 + p2 + e1;
	}	
return( s );
}

function AddCommas(s)
{
var ctr=0,p2='';
for(a=s.length-1;a>=0;a--) {
	ctr++;
	if((ctr>3) && (s.substr(a,1)!='-')) {
		ctr=1;
		p2 = ',' + p2;
		}
	p2 = s.substr(a,1) + p2;
	}
return(p2);
}

function GetNumRange(n,min,max,dec_places,def,commas)
{
if((n>=min) && (n<=max))  p=FmtNum(n,dec_places,commas);
else	p = def;
return(p);
}

function f_calc_1()
{
a = document.frmMain.txtA.value;
b = document.frmMain.txtB.value;
v = a * b;
//alert(v);
v = GetNumRange(v,0,99999,3,'',false);
//c = f_get_elem("lblAB");
f_set_elem("lblAB",v);
}


function f_validate(obj,fmt)
{
if(fmt=="number") {
	if(isNaN(obj.value)) {
		obj.value = "";
		}
	}	
}



function Replace( sExpression, sFind, sReplaceWith, iStart, iCount )
{
	
	var iLengthExp 		= 0;
	var iRemoveLength 	= 0;
 	var iStartPosition 	= 0;
	var iSubstringLength 	= 0;
	var iLoop		= 0;
	var sFirstPart 		= "";
	var sThirdPart 		= "";
	var sStartSubstring 	= "";
	var sReturnValue 	= "";

	// check for nulls in required parameters	
	if (( sExpression == null ) || ( sFind == null ) || ( sReplaceWith == null )) {
		return null;
	};

	if ( sFind == sReplaceWith ) { return sExpression; }		// prevent nasty recursion later
	if (( iStart == null ) || ( iStart < 0 )) { iStart = 0; };	// parameter check, default to 0
	if (( iCount == null ) || ( iCount < 1 )) { iCount = -1; }; 	// parameter check, default to -1

	iLengthExp 	= sExpression.length;	// check length of expression
	iRemoveLength 	= sFind.length;		// check length of sFind

	// check if sExpression or sFind are empty/blank
	if (( iLengthExp < 1 ) || ( iRemoveLength < 1 )) {	
		return sExpression;			
	};

	if ( iStart > iLengthExp ) { return sExpression; };	// sanity check start vs. expression length

	if ( iStart > 0 ) {	// do this if the user specified a place to start the replacement(s)

		// extract substring left of the start position
		sLeftOfStart 	= sExpression.substring( 0, iStart );
		
		// replace sExpression with the substring to the right of the iStart specified
		sRightOfStart	= sExpression.substring( iStart, iLengthExp);	
		sExpression	= sRightOfStart;	
	};

	iStartPosition 	= sExpression.indexOf( sFind );	// check to see if sFind is in sExpression 
	
	while( iStartPosition != -1 ) {		// do this while sFind is found within sExpression

		// sExpression's length will probably change in this loop
		iLengthExp = sExpression.length;		
		
		// based on the new iStartPosition, determine where 
		// we will get sExtract from sExpression
		iSubstringLength = iStartPosition + iRemoveLength;

		// get everything to the left of the substring being removed
		sFirstPart = sExpression.substring( 0, iStartPosition );
		
		// get everything to the right of the substring being removed
		sThirdPart = sExpression.substring( iSubstringLength, iLengthExp );

		// reform sExpression with the left substring, the replacement 
		// substring, and the right substring
		sExpression = sFirstPart + sReplaceWith + sThirdPart;

		// check to see if there is another instance of the sFind 
		// substring left in sExpression
		iStartPosition = sThirdPart.indexOf( sFind );

		// if substring still remains in the string, move the cursor up
		// to prevent any nasty recursion
		if ( iStartPosition > -1 ) {
			iStartPosition = sFirstPart.length + sReplaceWith.length + iStartPosition;
		};
		
		iLoop++;	

		// if the user specified a count, only do as many replacements as specified
		if (( iCount > -1 ) && ( iLoop == iCount )) { iStartPosition = -1; };

	};		// end while( iStartPosition != -1 )
	
	// if user specified start point, put the substring from before the start point back 
	// with the substring that had the replacement(s) performed on it
	if ( iStart > 0 ) { 					
		sExpression = sLeftOfStart + sExpression;
	};
	sReturnValue = sExpression;

	return sReturnValue;

// end Replace()
}


function parseVal(s)
{
var ctr=0;
do {
	c = s.substr(0,1);
	if(c=='0')  s=s.substr(1,s.length-1);
	if(s.length<=1) break;
	ctr++;
	} while(ctr<50);
return(parseInt(s));
}

function f_elements(s,sep)
{
var ctr=1;
for(a=0;a<s.length;a++) {
	if(s.substr(a,1)==sep) ctr++;
	}
return(ctr);
}


function f_element(s,num,sep)
{
var pos1,pos2;
var sTemp='';
s+=sep;
pos1=-1;
for(a=0;a<num;a++) {
	pos1 = s.indexOf(sep,pos1+1);
	}
pos2 = s.indexOf(sep,pos1+1);
if(pos2>pos1)	
	sTemp = s.substr(pos1+1,pos2-pos1-1);
return(sTemp);
}

function f_pad_zeros(s,len)
{
while(s.length<len) {
	s = "0" + s;
	}
}


function f_fmt_date(s)
{
var dd;
dd = new Date();

ctr = f_elements(s,"/");
if(ctr==3) {
	m = f_element(s,0,"/");
	d = f_element(s,1,"/");
	y = f_element(s,2,"/");
	//alert(ctr + ':' + m + ',' + d + ',' + y);
	s = m + "/" + d + "/" + y;
	}
else if(ctr==2) {
	m = f_element(s,0,"/");
	d = f_element(s,1,"/");
	y = dd.getFullYear();
	//alert(ctr + ':' + m + ',' + d + ',' + y);
	s = m + "/" + d + "/" + y;
	}
else {
	s = "";
	}
if(!isNaN(m) && (m>=1) && (m<=12) && !isNaN(d) && (d>=1) && (d<=31) && !isNaN(y) ) {}
else s="";	
return(s);
}

function f_datediff_today(dd1)
{
var d;
d = new Date();
m1 = parseInt(f_element(dd1,0,"/"))-1;
d1 = parseInt(f_element(dd1,1,"/"));
y1 = parseInt(f_element(dd1,2,"/"));
dd_1 = new Date(y1,m1,d1);
diff = (dd_1 - d) / 86400000;
i = Math.ceil(diff);
return(i);
}


function f_validate_date(obj)
{
var today=new Date();
v=obj.value;
p=v.split("/");
if(p.length==1) {
	obj.value="";
	return(0);
	}
else if(p.length==2) { 
	m=p[0];
	d=p[1];
	y=today.getFullYear();
	}
else if(p.length==3) {
	m=p[0];
	d=p[1];
	y=parseInt(p[2]);
	if(y<=99) { y+=2000; }
	}
if(isNaN(m) || isNaN(d) || isNaN(y)) {
	obj.value="";
	return(0);
	}
else if(m<1 || m>12 || d<1 || d>31 || y<0) {
	obj.value="";
	return(0);
	}
s=m+"/"+d+"/"+y;
obj.value = s;
}


function test()
{
alert("123");
}
