function openwin(url1,heit,widt){
	var winname='editrep'+Math.round(Math.random()*10000);
	var opstr='width='+widt+',height='+heit+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,screenx=10,screeny=10,left=10,top=10,copyhistory=no,resizable=yes' ;
	window.open(url1,winname,opstr);
	return false;
	}

function openwincc(url1,heit,widt,xcoor,ycoor){
	var winname='editrep'+Math.round(Math.random()*10000);
	var opstr='width='+widt+',height='+heit+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,screenx='+xcoor+',screeny='+ycoor+',left=10,top=10,copyhistory=no,resizable=yes' ;
	window.open(url1,winname,opstr);
	return false;
	}

function openwincc(url1,heit,widt,xcoor,ycoor){
	var winname='editrep'+Math.round(Math.random()*10000);
	var opstr='width='+widt+',height='+heit+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,screenx='+xcoor+',screeny='+ycoor+',left=10,top=10,copyhistory=no,resizable=yes' ;
	window.open(url1,winname,opstr);
	return false;
	}

function openwinnoscroll(url1,heit,widt){
	var winname='editrep'+Math.round(Math.random()*10000);
	var opstr='width='+widt+',height='+heit+',toolbar=yes,location=yes,directories=yes,status=yes,menubar=no,scrollbars=yes,screenx=10,screeny=10,left=10,top=10,copyhistory=no,resizable=yes' ;
	window.open(url1,winname,opstr);
	return false;
	}

function valid(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	//test first char for minus or num or period
	//idx=strtest.substr(ctr,0);
	//while ( idx != "-" && idx > "9"  && idx < "0" && idx != "." ) { ctr=ctr*1 + 1; warn="1";  }
	//out=out + idx; 
	//if (idx == "." ) { per="done"; }
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if ( idx == "-" && out.length == 0 ) { out=out + idx; } 
		else if (  idx <= "9"  && idx >= "0" ) { out=out + idx; }
		else if ( idx == "." && per != "done" ) { out=out  + idx; per="done"; }
		else { warn="1"; }
		}
	if ( warn == "1" ) { alert("Please enter a valid number"); }
	ctrl.value=out;
	//alert(out);
	return ;
	}
function padzero (intno) {
	return intno=(intno<10)?"0"+intno:intno
	}

function gen_replace(search,replace,input_string) {
	var aa = input_string ;
	var ii = 0 ;
	ii = aa.indexOf(search) ;
	while( ii > 0 ) {
		var bb = aa ;
		aa = bb.substr(0,ii)+replace+bb.substr(parseInt(ii)+parseInt(search.length)) ;
		//alert(aa+"====="+bb) ;
		ii = aa.indexOf(search) ;
		}
	return aa ;
	}

function valid_int_nosign(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if (  idx <= "9"  && idx >= "0" ) { out=out + idx; }
		else { warn="1"; }
		}
	//if ( warn == "1" ) { alert("The number just input had invalid characters.\nIt will be changed to " + out); }
	if ( warn == "1" ) { alert("Please enter a valid number"); }
	ctrl.value=out;
	return ;
	}
function valid_short_phone(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if (  idx <= "9"  && idx >= "0" ) { out=out + idx; }
		}
	if ( out.length < 7 ) { return false ; }
	//ctrl.value=out;
	return true ;
	}

function valid_phone(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if (  idx <= "9"  && idx >= "0" ) { out=out + idx; }
		}
	if ( out.length != 10 ) { alert("The phone number must be 10 digits!"); return false ; }
	ctrl.value=out;
	return true ;
	}
function valid_email( email ) {
	var input_email = email.value ;
	if ( input_email.length < 2 ) { return false; }
	if (input_email.length > 0 ) {
		//check the email, they put something in
		var atpos=input_email.indexOf("@") ;
		if ( atpos == "undefined" || atpos < 2 ) { return false ; }
		var perpos=input_email.split("@") ;
		var out = perpos[1].indexOf(".") ;
		if ( out == "undefined" || out < 2 ) { return false ; }
		}
	return true;
	}
function valid_int_space(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if ( ( idx <= "9"  && idx >= "0" ) || idx == " " ) { out=out + idx; }
		else { warn="1"; }
		}
	if ( warn == "1" ) { alert("The number just input had invalid characters.\nIt will be changed to " + out); }
	ctrl.value=out;
	return ;
	}
function is_alphabet(ctrl) {
	strtest=ctrl.value;
	ctr=0; warn= "0"; per=""; out ="";
	for (u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if ( ( idx <= "9"  && idx >= "0" ) || ( idx <= "Z"  && idx >= "A" ) || ( idx <= "z"  && idx >= "a" ) ) { 
			out=out + idx; }
		else { warn="1"; }
		}
	if ( warn == "1" ) { return false ; }
	return true ;
	}
function valid_datetime(inp) {
	var err = "" ;
	var input_date = inp.value ;
	if ( input_date.length > 0 ) {
		// break the string into two parts based upon a blank in the middle
		list = explode(input_date," ") ;
		if ( list[0].length < 1 ) { alert("No date. Please fix.") ; return false; }
		if ( list[1]==null ) { alert("No time. Please fix.") ; return false; }
		if ( list[1].length < 1 ) { alert("No time. Please fix.") ; return false; }
		//check the date, they put something in
		if ( list[0].indexOf("/") > 0 ) { listd=explode(list[0],"/",false) ; }
		if ( list[0].indexOf("-") > 0 ) { listd=explode(list[0],"-",false) ; }
		if ( list[0].indexOf(".") > 0 ) { listd=explode(list[0],".",false) ; }
		if ( list[0].indexOf(",") > 0 ) { listd=explode(list[0],",",false) ; }
		var yy = listd[2] ; var dy = listd[1] ; var mo = listd[0] ;
		if ( yy < 20  ) { yy =Math.round(yy*100)/100 + Math.round(cent*100) ; }
		if ( yy >= 20 && yy < 100 ) { yy =Math.round(yy*100)/100 + Math.round(cent*100)-100 ; }
		var test = new Date(yy,mo-1,dy);
		if (  yy == test.getFullYear() && mo-1 == test.getMonth() && dy == test.getDate() ) {
			}
		      else {
			err += "Valid format but an invalid date\n"; 
			}
		listt=explode(list[1],":",false) ;
		var hh = listt[0] ; var mm = listt[1] ; var ss = listt[2] ;
		if (hh==null ) { hh = 0 ; alert("No time. Please fix.") ; return false; }
		if (ss==null ) { ss = 0 ; }
		if (mm==null ) { mm = 0 ; }
		if ( hh<0 || hh > 23 ) { err +="bad hours\n"; }
		if ( mm < 0  || mm > 59 ) { err +="bad minutes\n"; }
		if (  ss > 59 || ss < 0 ) { err +="bad seconds\n"; }

		if ( err.length < 1  ) {
			// prep for output
			inp.value= formatNumber(mo,"00")+"/"+formatNumber(dy,"00")+"/"+formatNumber(yy,"0000")+" "+formatNumber(hh,"00")+":"+formatNumber(mm,"00")+":"+formatNumber(ss,"00") ; 
			return true ;
			}
		    else {
			alert(err+"/nProper format is 'mm/dd/yyyy hh:mm:ss'") ;
			return false ;
			}
		}
	}

function out_valid_datetime(inp) {
	var err = "" ;
	var input_date = inp.value ;
	if ( input_date.length > 0 ) {
		// break the string into two parts based upon a blank in the middle
		list = explode(input_date," ") ;
		if ( list[0].length < 1 ) { alert("No date. Please fix.") ; return false; }
		if ( list[1]==null ) { alert("No time. Please fix.") ; return false; }
		if ( list[1].length < 1 ) { alert("No time. Please fix.") ; return false; }
		//check the date, they put something in
		if ( list[0].indexOf("/") > 0 ) { listd=explode(list[0],"/",false) ; }
		if ( list[0].indexOf("-") > 0 ) { listd=explode(list[0],"-",false) ; }
		if ( list[0].indexOf(".") > 0 ) { listd=explode(list[0],".",false) ; }
		if ( list[0].indexOf(",") > 0 ) { listd=explode(list[0],",",false) ; }
		var yy = listd[2] ; var dy = listd[1] ; var mo = listd[0] ;
		if ( yy < 20  ) { yy =Math.round(yy*100)/100 + Math.round(cent*100) ; }
		if ( yy >= 20 && yy < 100 ) { yy =Math.round(yy*100)/100 + Math.round(cent*100)-100 ; }
		var test = new Date(yy,mo-1,dy);
		if (  yy == test.getFullYear() && mo-1 == test.getMonth() && dy == test.getDate() ) {
			}
		      else {
			err += "Valid format but an invalid date\n"; 
			}
		listt=explode(list[1],":",false) ;
		var hh = listt[0] ; var mm = listt[1] ; var ss = listt[2] ;
		if (hh==null ) { hh = 0 ; alert("No time. Please fix.") ; return false; }
		if (ss==null ) { ss = 0 ; }
		if (mm==null ) { mm = 0 ; }
		if ( hh<0 || hh > 23 ) { err +="bad hours\n"; }
		if ( mm < 0  || mm > 59 ) { err +="bad minutes\n"; }
		if (  ss > 59 || ss < 0 ) { err +="bad seconds\n"; }

		if ( err.length < 1  ) {
			// prep for output
			inp.value= formatNumber(yy,"0000")+"-"+formatNumber(mo,"00")+"-"+formatNumber(dy,"00")+" "+formatNumber(hh,"00")+":"+formatNumber(mm,"00")+":"+formatNumber(ss,"00") ; 
			//alert(inp.value+'  '+mm) ;
			return true ;
			}
		    else {
			alert(err+"/nProper format is 'mm/dd/yyyy hh:mm:ss'") ;
			return false ;
			}

		}
	}
function valid_date(inp) {
	var err = "" ;
	var input_date = inp.value ;
	if ( input_date.length > 0 ) {
		//check the date, they put something in
		if ( input_date.indexOf("/") > 0 ) { listd=explode(input_date,"/",false) ; }
		if ( input_date.indexOf("-") > 0 ) { listd=explode(input_date,"-",false) ; }
		if ( input_date.indexOf(".") > 0 ) { listd=explode(input_date,".",false) ; }
		if ( input_date.indexOf(",") > 0 ) { listd=explode(input_date,",",false) ; }
		var yy = listd[2] ; var dy = listd[1] ; var mo = listd[0] ;
		if ( yy < 20  ) { yy =Math.round(yy*100)/100 + Math.round(cent*100) ; }
		if ( yy >= 20 && yy < 100 ) { yy =Math.round(yy*100)/100 + Math.round(cent*100)-100 ; }
		var test = new Date(yy,mo-1,dy);
		if (  yy == test.getFullYear() && mo-1 == test.getMonth() && dy == test.getDate() ) {
			}
		      else {
			err += "Valid format but an invalid date\n"; 
			}
		if ( err.length < 1  ) {
			// prep for output
			inp.value= formatNumber(mo,"00")+"/"+formatNumber(dy,"00")+"/"+formatNumber(yy,"0000") ; 
			return true ;
			}
		    else {
			alert(err+"/nProper format is 'mm/dd/yyyy'") ;
			return false ;
			}
		}
	}
function format_number(pnumber,decimals) { 
	if (isNaN(pnumber)) { return 0}; 
	if (pnumber=='') { return 0}; 
  
	var IsNegative=(parseInt(pnumber)<0);
	if(IsNegative)pnumber=-pnumber;
	var snum=new String(pnumber); 
	var sec=snum.split('.'); 
	var whole=parseInt(sec[0]); 
	var result=''; 
	if(sec.length > 1){  var dec=new String(sec[1]);  }
	      else { var dec = "" ; }
	var last = parseInt(decimals)+parseInt(1) ;
	while ( dec.length < last ) { dec = dec + "0" ; }
	var out = "" ;
	var carry = 0 ; var tt ;
	if(parseInt(dec.charAt(decimals)) > 4 ) { carry = 1; }
	for ( k=parseInt(decimals)-1; k> -1; k-- ) {
		if ( carry > 1 ) {
			if(parseInt(dec.charAt(k)) > 8 ) {
				out = "0" + out ;
				carry = 1 ;
				}
			    else {
				tt = parseInt(dec.charAt(k)) + parseInt(1)  ;
				out = tt + out ;
				carry = 0 ;
				}
			}
		    else {
			carry = 0 ;
			out = dec.charAt(k) + out ;
			}
		}
	if ( carry > 0 ) { whole++ ; }
	out = whole+"."+out ;
	if(IsNegative) { out ="-"+out ; }
	return out ;
	} 

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i=getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

 function validdigs(ctrl) {
	strtest=ctrl.value;
	var out="";
	var idx;
	warn=0 ;
	for (var u=0;u<strtest.length;u++) {
		idx=strtest.substr(u,1);
		if (  idx <= "9"  && idx >= "0" ) { out=out + idx; } else { warn=1 ;}
		}
	if ( warn == "1" ) { alert("The number just input had invalid characters.\nIt will be changed to " + out); }
	ctrl.value=out;
	return ;
	}
function URLEncode(ctl ) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = ctl.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
			}
		    else if (SAFECHARS.indexOf(ch) != -1) {
		   	encoded += ch;
			}
		    else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				alert( "Unicode Character '" 
		                        + ch 
                		        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
				}
			     else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for

	return encoded;
	}

function capname(nametocap) {
	var out = "" ;
	for (k=0;k<nametocap.length;k++) {
		var gg = nametocap.substr(k,1) ;
		if ( k == 0 ) { out += nametocap.substr(k,1).toUpperCase() ; } else { out += nametocap.substr(k,1).toLowerCase() ; }
		}
	return out ;
	}

function capallname(nametocap) {
	var out = "" ;
	for (k=0;k<nametocap.length;k++) {
		var gg = nametocap.substr(k,1) ;
		if ( k == 0 || nametocap.substr(k-1,1)==" " ) { out += nametocap.substr(k,1).toUpperCase() ; } else { out += nametocap.substr(k,1).toLowerCase() ; }
		}
	return out ;
	}

function explode(inputstring, separators, includeEmpties) {
	inputstring = new String(inputstring);
	separators = new String(separators);
	if(separators == "undefined") { 
		separators = " :;";
		}

	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;

	for(x=0; x < inputstring.length; x++) {
		chard = inputstring.charAt(x);
		if(separators.indexOf(chard) != -1) {
			if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { }
			          else {
				fixedExplode[count] = currentElement;
				count++;
				currentElement = "";
				}
			 }
		       else { currentElement += chard; }
		}

	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
		fixedExplode[count] = currentElement; 
		}
	return fixedExplode;
	}
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
	//formatNumber(3.14159265, "##0.####")
	//3.1416
	//formatNumber(3.14, "0.0###%")
	//314.0%
	//formatNumber(314159, ",##0.####")
	//314,159
	//formatNumber(31415962, "$,##0.00")
	//members.ozemail.com.au/~dcrombie/format.html
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");
//var number1 = number - 0 ;
//alert(number+'--**********--'+number1) ;
    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }
function count_click(id) {
	xmlHttpcc99=wantXmlHttpObject() ;
	if (xmlHttpcc99==null) {
		alert ("Browser does not support HTTP Request") ;
		return ;
		} 
	var url=syspath+"count_clickthru.html" ;
	url=url+"?id="+id;
	//alert(url);
	xmlHttpcc99.onreadystatechange=count_click_return ;
	xmlHttpcc99.open("GET",url,true) ;
	xmlHttpcc99.send(null) ;
	}
function count_click_return() {
	if (xmlHttpcc99.readyState==4 || xmlHttpcc99.readyState=="complete") { 
		//alert("=="+xmlHttpcc99.responseText+"==response") ;
		}
	}
function wantXmlHttpObject() { 
	var objXMLHttp=null ;
	if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() ; }
	else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") ; }
	return objXMLHttp ;
	}

function trim(str, chars) {  
	return ltrim(rtrim(str, chars), chars);  
	}  
   
function ltrim(str, chars) {  
	chars = chars || "\\s";  
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");  
	}  
   
function rtrim(str, chars) {  
	chars = chars || "\\s";  
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");  
	}  
function replacegreencolor(v) {	v.className="greenshadowbtn" ; }
function changegreencolor(v) { v.className="greenbtn" ; }
function replaceredcolor(v) { v.className="redshadowbtn" ; }
function changeredcolor(v) { v.className="redbtn" ; }
function replacesalmoncolor(v) { v.className="salmonshadowbtn" ; }
function changesalmoncolor(v) { v.className="salmonbtn" ; }
function replacelbluecolor(v) { v.className="skyblueshadowbtn" ; }
function changelbluecolor(v) { v.className="skybluebtn" ; }