
function inArray(str,arr){
	for(i=0;i<arr.length;i++){
		if(arr[i]==str)return 1;
	}
	return 0;
}



function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!n)return;  if(!d) d=document; 
  if(d.document)d=d.document;
  if(d.contentDocument)d=d.contentDocument;
  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]; 
  if(d.forms){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 findObj(n,d){
	return MM_findObj(n,d);
}
function WM_netscapeCssFix() {
    document.location = document.location;
}
 
function WM_netscapeCssFixCheckIn() {
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
   if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
    }
    window.onresize = WM_netscapeCssFix;
  }
}
 
WM_netscapeCssFixCheckIn();

function winop(filename,width,height){
	params = "height="+height
		   + " ,width="+width
		   + " ,top=0"
		   + " ,left=0"
		   + " ,scrollbars=1"
		   + ", resizable=1"
	window.open(filename,"preview",params);
}
function openFullScreen(url){
	var dims=getWindowDims();
	winop(url,dims[0],dims[1]);
}
function getWindowDims(){
	var w; var h
	if(window.screen.width){
		return [window.screen.width,window.screen.height];
	}
	if(window.innerWidth){
		return [window.innerWidth,window.innerHeight];
	}else if(document.getElementsByTagName('body')[0].clientWidth){
		return [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight]
	}
	return [0,0];
} 
function getDocDims(){
	return [document.body.clientWidth,document.body.clientHeight];
}
function preload() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preload.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function rollOut(){
	MM_swapImgRestore();
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function rollOver(imgName,imgSrc){
	MM_swapImage(imgName,'',imgSrc,1);
}

function stristr(needle,haystack){
	needle = new String(needle).toLowerCase();
	haystack = new String(haystack).toLowerCase();
	return haystack.indexOf(needle)>-1?1:0;
}

function endswith(str,substr){
	if(typeof(str)!="string")str=new String(str);
	if(typeof(substr)!="string")substr=new String(substr);
	if(!str || !substr)
		return 0;
	if(str.substring(str.length-substr.length).toLowerCase() == substr.toLowerCase())
		return 1;
	return 0;
}
function startswith(str,substr){
	if(!typeof(str)=="string")str=new String(str);
	if(!typeof(substr)=="string")substr=new String(substr);
	if(!str || !substr)
		return 0;
	if(str.substring(0,substr.length).toLowerCase() == substr.toLowerCase())
		return 1;
	return 0;
}
function strto(str,subs){//--return all of $str up to $substr non-inclusive
	if(!stristr(subs,str)){
		return str;
	}
	return str.substring(0,str.indexOf(subs));
}
function strfrom(str,subs){//--return all of $str after $substr non-inclusve
	if(!stristr(subs,str)){
		return "";
	}
	return str.substring(str.indexOf(subs)+subs.length);
}
function strfromto(str, from, to){
	if(!(subs=strfrom(str,from)))return "";
	return strto(subs,to);
}

function valid_email(val){
	return val.match(/^[\w\-\.]{1,255}@[\w\-\.]{2,255}\.\w{2,5}$/)
}
function input_hidden(name,value){
	if(!value)value="";
	return '<input type="hidden" name="'+name+'" value="'+value+'" />';
}
function refer(return_str){
	if(return_str)
		return location.href.toString().base64_encode();
	return input_hidden("refer",refer(1));
}
function input_text(name,value,size,maxlength,addl){
	if(!value)value="";
	if(!size)size="20";
	if(!maxlength)maxlength="255";
	if(!addl)addl="";
	var params=new Array(
		'type="text"', 'name="'+name+'"','id="'+name+'"',
		'value="'+value+'"','maxlength="'+maxlength+'"',
		'size="'+size+'"',	'class="textinput"',
		addl
		);
	return '<input '+params.join(" ")+'/>';
}
function getVal(frmObj,getSelVal){
	if(!frmObj)return;
	if(typeof(frmObj.type)=="undefined"){
		if(typeof(frmObj.length)!="undefined"){
			frmObj.type="radio";
		}
	}
	var t=frmObj.type;
	if(stristr("text",t)||stristr("password",t))
		return trim(frmObj.value);
	if(stristr("radio",t)){
		for(i=0;i<frmObj.length;i++)
			if(frmObj[i].checked) return frmObj[i].value;
		return false;
	}
	
	if(stristr("checkbox",t))
		return frmObj.checked;
		
	if(stristr("select",t)){
		if(getSelVal)
			return selectedValue(frmObj.name);
		else
			return selectedText(frmObj.name);
	}
	
	return trim(frmObj.value);
}

function getValByName(frmObjName,targFormName){
	var obj=findObj(frmObjName);
	if(targFormName){
		var tf=findObj(targFormName);
		if(tf.elements)
			if(tf.elements[frmObjName])
				obj=tf.elements[frmObjName];
	}
	return getVal(obj);
}
function setValByName(frmObjName,value){
//sets, checks or selects a value on any form field type
	value=new String(value);
	var frmObj=findObj(frmObjName);
	if(!frmObj)return;
	if(typeof(frmObj.type)=="undefined")
		if(typeof(frmObj.length)!="undefined")
			frmObj.type="radio";
	var t=frmObj.type;
	if(stristr("file",t)){
		try{
			frmObj.value=value;
			return;
		}catch(e){
			return;
		}
	}
	if(stristr("checkbox",t)){
		if(!value.length)value=false;
		if(value=="0")value=false;
		frmObj.checked=value?true:false;
		return;
	}
	if(stristr("radio",t)){
		selectRadio(frmObjName,value);
		return;
	}
	if(stristr("select",t)){
		selectValue(frmObjName,value);
		return;
	}
	if(typeof(frmObj.value)!="undefined"){
		frmObj.value=value;
		return;
	}
}
function radioVal(frmObjName){
	frmObj=findObj(frmObjName);
	for(i=0;i<frmObj.length;i++){
		if(frmObj[i].checked)
			return frmObj[i].value;
	}
	return false;
}
function selectRadio(frmObjName,value){
	frmObj=findObj(frmObjName);
	if(!frmObj)return;
	if(typeof(frmObj.length)=="undefined")return;
	for(i=0;i<frmObj.length;i++){
		if(frmObj[i].value==value){
			frmObj[i].checked=true;
			return;
		}
	}
}
function checkBox(frmObj){
	selectCheck(frmObj);
}
function unCheckBox(frmObj){
	selectCheck(frmObj,1);
}
function selectCheck(frmObj,uncheck){
	if(typeof(frmObj)!="object")
		frmObj=findObj(frmObj);
	if(!frmObj)return;
	frmObj.checked=(!uncheck);
}
function toggleCheck(frmObj){
	if(typeof(frmObj)!="object")
		frmObj=findObj(frmObj);
	if(!frmObj)return;
	frmObj.checked=!frmObj.checked;
}
function isChecked(checkObj){
	if(typeof(checkObj)!="object")
		checkObj=findObj(checkObj);
	if(!checkObj)return 0;
	if(typeof(checkObj.checked)=="undefined")return 0;
	return checkObj.checked;
}
function selectedValue(fieldName){
	fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return "";
	if(typeof(fieldName.selectedIndex)=="undefined")return "";
	return fieldName[fieldName.selectedIndex].value;
}
function selectedText(fieldName,ignoreDash){
	fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return "";
	if(typeof(fieldName.selectedIndex)=="undefined")return "";
	if(ignoreDash && fieldName[fieldName.selectedIndex].text.charAt(0)=="-")return "";
	return fieldName[fieldName.selectedIndex].text;
}

function selectedValue(fieldName){
	if(typeof(fieldName)!="object")
		fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return "";
	if(typeof(fieldName.selectedIndex)=="undefined")return "";
	if(fieldName.selectedIndex==-1)return "";
	return fieldName[fieldName.selectedIndex].value;
}
function selectedText(fieldName,ignoreDash){
	if(typeof(fieldName)!="object")
		fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return "";
	if(typeof(fieldName.selectedIndex)=="undefined")return "";
	if(fieldName.selectedIndex==-1)return "";
	if(ignoreDash && fieldName[fieldName.selectedIndex].text.charAt(0)=="-")return "";
	return fieldName[fieldName.selectedIndex].text;
}
function selectValue(fieldName,value){
	fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return ;
	if(typeof(fieldName.selectedIndex)=="undefined")return;
	for(i=0;i<fieldName.options.length;i++){
		if(typeof(value)=="object"){//list of values
			if(in_array(fieldName.options[i].value,value)){
				fieldName.options[i].selected=true;
				continue;
			}
		}
		if(fieldName.options[i].value==value){
			fieldName.options[i].selected=true;
			return;
		}
	}
}
function selectText(fieldName,value){//chooses an option in a select list
	fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return ;
	if(typeof(fieldName.selectedIndex)=="undefined")return;
	for(i=0;i>fieldName.options.length;i++){
		if(typeof(value)=="object"){//list of values
			if(in_array(fieldName.options[i].text,value)){
				fieldName.options[i].selected=true;
				continue;
			}
		}
		if(fieldName.options[i].text==value){
			fieldName.options[i].selected=true;
			return;
		}
	}
}

function insertTextToInput( input, insText ) {//---this will insert text into an input at the current curosr position
	if(!(input=getDomObj(input)))return;
	input.focus();
	if( input.createTextRange ) {
		document.selection.createRange().text += insText;
	} else if( input.setSelectionRange ) {
		var len = input.selectionEnd;
		input.value = input.value.substr( 0, len )	+ insText + input.value.substr( len );
		input.setSelectionRange(len+insText.length,len+insText.length);
	} else { 
		input.value += insText; 
	}
}

function scrollToSelected(fieldName){//--doesn't work
	fieldName=findObj(fieldName);
	if(typeof(fieldName)=="undefined")return ;
	if(typeof(fieldName.selectedIndex)=="undefined")return;
	if(typeof(fieldName.options)=="undefined")return;
	for(i=0;i<fieldName.options.length;i++){
		if(fieldName.options[i].selected==true){
			fieldName.options[i].selected=false;
			fieldName.options[i].selected=true;
		}
	}
}
function checkAll(formname,checkUnChecked,strMatch){
	frm=findObj(formname);
	for(i=0;i<frm.elements.length;i++){
		var el=frm.elements[i];
		if(typeof(el.name)=="undefined")continue;
		if(typeof(el.type)=="undefined")continue;
		if(!el.name || !el.type)continue;
		if(el.type.toLowerCase().indexOf("check")==-1)continue;
		if(strMatch){
			if(el.name.indexOf(strMatch)==-1)
				continue;
		}
		el.checked=checkUnChecked?true:false;
	}
}
function getSelectedCheckCount(frmObj,strMatch){
	if(typeof(frmObj)!="object")
		frmObj=findObj(frmObj);
	if(!frmObj)return;
	var ret=0;
	for(i=0;i<frmObj.elements.length;i++){
		var el=frmObj.elements[i];
		var type=el.type;
		var name=el.name;
		if(!type || !name)continue;
		if(type.toLowerCase().indexOf("check")==-1)continue;
		if(typeof(el.checked)=="undefined")continue;
		if(strMatch){
			if(name.indexOf(strMatch)==-1){
				continue;
			}
		}
		if(el.checked)ret++;
	}
	return ret;
}
function getSelectedCheckIds(frmObj,strMatch){
		if(typeof(frmObj)!="object")
		frmObj=findObj(frmObj);
	if(!frmObj)return;
	var ret=new Array();
	for(i=0;i<frmObj.elements.length;i++){
		var el=frmObj.elements[i];
		var type=el.type;
		var name=el.name;
		if(!type || !name)continue;
		if(type.toLowerCase().indexOf("check")==-1)continue;
		if(typeof(el.checked)=="undefined")continue;
		if(strMatch){
			if(name.indexOf(strMatch)==-1){
				continue;
			}
		}
		if(el.checked)ret[ret.length]=el.name;
	}
	return ret;
}
function validEmail(emStr){
	return valid_email(emStr);
}
function validEmailValue(fieldname){
	return valid_email(getValByName(fieldname));
}
function email_format(str){return str.replace(/[^a-zA-Z_\-0-9@\.]+/g,"");}
function wordsonly(str){return str.replace(/[^a-zA-Z-\s]+/g,"");}
function lc(str){
	if(typeof(str)!="string")return str;
	return str.toLowerCase();
}


function ucfirst(str){
	var ret = "";
	var let=str.substring(0,1).toUpperCase();
	return let+str.substring(1,str.length);
}

function ucwords(str){
	var ret = new Array();
	words = str.split(" ");
	for(i=0;i<words.length;i++)
		ret[ret.length]=ucfirst(words[i]);
	return ret.join(" ");
}

function uspace(str){
	return str.replace(/_/g," ");
}

function stripSlashes(str){
	return str.replace(/\\/g,"");
}
function strip_tags(str){
	if(!str)return "";
	var reg=/<([^>])+>/g;
	return str.replace(reg,"");
}
function stristr(needle,haystack){
	needle=needle.toString().toLowerCase();
	haystack=haystack.toString().toLowerCase();
	if(haystack.indexOf(needle)>-1)return 1;
	return 0;
}

function trim(str){
	if(typeof(str)=="undefined")return "";
	return str.toString().replace(/(^\s+|\s+$)/g,"");
}

function numsonly(str){
	return str.replace(/[^\d\.]+/g,"");
}

function nobadchars(str){
	return str.replace(/\W+/g,"");
}
function alphanum(str){
	return nobadchars(str);
}

function limitCharLength(str,len){
	return str.substring(0,len);
}

function wordsonly(str){
	return str.replace(/[^a-zA-Z-\s]+/g,"");
}
function email_format(str){
	return str.replace(/[^a-zA-Z\-0-9@\.]+/g,"");
}
function array_diff(arr1, arr2){ //returns array w/ all values of arr1 not in arr2
	var ret = new Array();
	for(var i=0;i < arr1.length;i++){
		if(!in_array(arr1[i], arr2)) ret[ret.length]=arr1[i];
	}
	return ret;
}

function array_keys(arr){
	var ret = new Array();
	for(e in arr)
		ret[ret.length]=e;
	return ret;
}

function array_search(needle,haystack){
	for(var i=0;i< haystack.length;i++){
		if(needle==haystack[i])return i;
	}
	return false;
}

function array_sum(arr){
	ret = 0;
	for(var i=0;i< arr.length;i++){
		var item = parseFloat(arr[i]);
		ret+=item;
	}
	return ret;
}
function array_unique(arr){
	var ret = new Array();
	for(var i=0;i< arr.length;i++)
		if(!in_array(arr[i],ret)) ret[ret.length]=arr[i];
	return ret;
}
function array_values(arr){
	var ret = new Array();
	for(e in arr)
		ret[ret.length]=arr[e];
	return ret;
}
function array_append(oldarr,appendarr){
	for(i=0;i<appendarr.length;i++){
		oldarr[oldarr.length]=appendarr[i];
	}
	return oldarr;
}
function in_array(needle,haystack){
	for(var i=0;i< haystack.length;i++)
		if(needle==haystack[i])return 1;
	return 0;
}
function trim_arr(arr){
	var tmp=new Array();
	for(i=0;i<arr.length;i++){
		if(arr[i])tmp.push(arr[i]);
	}
	return tmp;
}
function isPartialPath(path){//eg filename
	if(!path)
		return 0;
	if(stristr("/",path))
		return 0;
	if(stristr("\\",path))
		return 0;
	if(path.match(/\.\w+$/))
		return 1;
	return 0;
}
function cleanfilename(path){
	path=path.replace("/[^\w\.\-_]/g",'_');
	return trim(path);
}
function basename(path){
	var sep="";
	if(!path)
		return "";
	if(stristr("/",path))
		sep="/";
	if(stristr("\\",path))
		sep="\\";
	if(!sep){
		//--could be just a partial filename. opera does this
		if(path.match(/\.\w+$/))
			return path
		return "";
	}
	path=path.substring(path.lastIndexOf(sep)+1);
	return path;
}
function bbasename(path){
	if(!path)
		return "";
	if(!stristr(".",path)){
		if(path)
			return path
		return "";
	}
	path=basename(path);
	if(!stristr(".",path)){
		if(path)
			return path
		return "";
	}
	return path.substring(0,path.lastIndexOf("."))
}
function dirname(path){
	var tmp=path.split("/");
	if(tmp[0]=="http:"){
		for(i=0;i<3;i++){
			tmp.shift();//kill scheem&hostname parts
		}
	}
	tmp.pop();
	return "/"+tmp.join("/");
}
function validateCCNum(cardType,cardNum){
	cardType = cardType.toUpperCase();
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);

	switch (cardType){
		case "VISA":
			return ( (cardLen == 16) && (firstdig == "4"));
		case "AMEX":
			var validNums = "47";
			return ((cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0));
		case "MASTERCARD":
			var validNums = "12345";
			return ((cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0));
		case "DISCOVER":
			return  ((cardLen == 16) && (first4digs == "6011"));
		case "DINERS":
			var validNums = "068";
			return ((cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0));
	}
	return 0;
}

function isValidExpDate(mmyy){
	mmyy=mmyy.split("/");
	if(mmyy[0].charAt(0)=="0")mmyy[0]=mmyy[0].substring(1);
	mo=parseInt(mmyy[0]);yr=parseInt("20"+mmyy[1]);
	if(!mo||isNaN(mo) || !yr ||isNaN(yr) || (mo<1||mo>12))
		return 0;
	var thisYear=new Date().getYear();
	var thisMo=new Date().getMonth();
	if(thisYear>yr)return 0;
	return 1;
}
function isValidExpDate2(mm,yyyy){
	var d=mm+"/"+yyyy.substring(2,4);
	return isValidExpDate(d);
}
function validZip(zipObj){
	if(findObj(zipObj).value.length<5)
		return 0;
	return 1;
}
function validPhone(phoneObj){
	if(findObj(phoneObj).value.length<10)
		return 0
	return 1;
}


function getDateTime(){
	var d = new Date();
	var s="";
	s+=(d.getMonth() + 1) + "/";
	s+=d.getDate() + "/";
	s+=(d.getYear()+(d.getYear()<1000?1900:0))+" ";
	hrs=d.getHours();
	if(hrs>12){
		hrs-=12;
		if(hrs<10)hrs="0"+hrs;
		ampm="PM";
	}else{
		ampm="AM";
	}
	s+=hrs+":" 
	mins=d.getMinutes();
	if(mins<10)mins="0"+mins
	s+=mins+" "+ampm;
	return(s);
}


function gohref(loc,replace){
	if(!replace)location.href=loc;
	else location.replace(loc);
}


function rand(max,min){
	return Math.round((max-min) * Math.random() + min);
}

function input_button(val,eonclick,addl){
	if(!val)val="Submit";
	if(!eonclick)eonclick="void()";
	if(!addl)addl="";
	if(addl)addl=" "+addl;
	return "<input type=\"button\" value=\""+val+"\" class=\"buttoninput\" onclick=\""+eonclick+"\""+addl+" />" ;
}
function createEl(type,attrs){
	var obj=document.createElement(type);
	for(e in attrs)
		obj.setAttribute(e,attrs[e]);
	return obj;
}
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return arrReturnElements;
}

function getDomObj(lObj){
//accepts a string or actual dom object. will always return dom obj on success or false on failure
	if(typeof(lObj)!="object"){
		if(document.getElementById){
			if((lObj=document.getElementById(lObj)))
				return lObj;
		}
		lObj=findObj(lObj);
	}
	if(typeof(lObj)!="object")return 0;
	if(typeof(lObj.style)=="undefined")return 0;
	return lObj;
}

function setInnerHTML(lObj, txt){
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(txt)=="undefined")txt="";
	lObj.innerHTML=txt;
	return 1;
}
function getInnerHtml(lObj){
	if(!(lObj=getDomObj(lObj)))return 0;
	return lObj.innerHTML;
}
function appendHTML(lObj,txt){//--this throws runtime errors in ie with tables. don't know about other elements
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(txt)=="undefined")txt="";
	txt=lObj.innerHTML+txt;
	setInnerHTML(lObj,txt);
	txt="";
}
function getDisp(lObj){
	if(!(lObj=getDomObj(lObj)))return 0;
	var disp=lObj.style.display;
	return (disp=="none"?"none":"block");
}
function setDisp(lObj,disp){
	if(!(lObj=getDomObj(lObj))){return 0;}
	//lObj.style.display=disp;
	
	var nonblocks="a span td tr tbody label select".split(" ");
	var show=(in_array(lObj.tagName.toLowerCase(),nonblocks)?"":"block");
	lObj.style.display=(disp=="none"?"none":show);//set to empty string. doesn't control blocking of element
	return 1;
}
function getVis(lObj){
	if(!(lObj=getDomObj(lObj)))return 0;
	var disp=lObj.style.visibility;
	return (disp=="hidden"?"hidden":"visible");
}
function setVis(lObj,vis){
	if(!(lObj=getDomObj(lObj)))return 0;
	lObj.style.visibility=(vis=="hidden"?"hidden":"visible");
	return 1;
}
function setXY(lObj,x,y){
	if(!(lObj=getDomObj(lObj)))return 0;
	lObj.style.left=x+"px";
	lObj.style.top=y+"px";
}
function setWH(lObj,w,h){
	if(!(lObj=getDomObj(lObj)))return 0;
	lObj.style.height=h+"px";
	lObj.style.width=w+"px";
}
function getOffsetTop(lObj){
	return getOffsetProperty(lObj, 'Top');
}
function getOffsetLeft(lObj){
	return getOffsetProperty(lObj, 'Left');
}
function getOffsetCoords(lObj){
	var x=getOffsetLeft(lObj);
	var y=getOffsetTop(lObj);
	if(!x || isNaN(x))x=0;
	if(!y || isNaN(y))y=0;
	return new Array(x,y);
}
function getOffsetProperty(lObj, property){
	if(!(lObj=getDomObj(lObj)))return 0;
	offsetProperty = 'offset' + property;
	if(typeof(lObj[offsetProperty])=="undefined")return;
	var offsetValue = 0;
	do {
		offsetValue += lObj[offsetProperty];
		lObj = lObj.offsetParent;
	} while (lObj != document.body && lObj != null);
	return offsetValue;
}
function getBorderHeight(lObj){//get height of top+bottom borders
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(lObj.style.borderTopWidth)=="undefined")return 0;
	var ret=0;
	if(!isNaN(height=parseInt(lObj.style.borderTopWidth)))
		ret+=height;
	if(!isNaN(height=parseInt(lObj.style.borderBottomWidth)))
		ret+=height;
	return ret;
}
function getBorderWidth(lObj){//get height of right+left borders
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(lObj.style.borderLeftWidth)=="undefined")return 0;
	var ret=0;
	if(!isNaN(width=parseInt(lObj.style.borderLeftWidth)))
		ret+=width;
	if(!isNaN(width=parseInt(lObj.style.borderRightWidth)))
		ret+=width;		
	return ret;
}
function getOffsetHeight(lObj){//gets offset height and includes border height
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(lObj.offsetHeight)=="undefined")return 0;
	return (lObj.offsetHeight+getBorderHeight(lObj));
}
function getOffsetWidth(lObj){//get offsetWidth and include borders
	if(!(lObj=getDomObj(lObj)))return 0;
	if(typeof(lObj.offsetWidth)=="undefined")return 0;
	return (lObj.offsetWidth+getBorderWidth(lObj));	
}
function setToOffsetSize(lObj){//set the object hard to it's offset height and width so when content changes it doesnt
	if(!(lObj=getDomObj(lObj)))return 0;
	var h=getOffsetHeight(lObj);
	var w=getOffsetWidth(lObj);
	setWH(lObj,w,h);
}
function img(src,link_url,addlimg,addllink){
	if(!addlimg)addlimg="";
	if(!addllink)addllink="";
	var ret='<img src="'+src+'" border="0" '+addlimg+' />';
	if(link_url)
		ret='<a href="'+link_url+'" '+addllink+'>'+ret+'</a>';
	return ret;
}
function resizeImages(containerObj,setWidth){
	//resize all imges inside containerObj to be expr(containerObj.offsetWidth-widthOffset)
	//setWidth will override the offset size of containerObj and force images larger to be this width
	//also resizes embeds like youtube videos etc.
	containerObj=getDomObj(containerObj);
	if(!containerObj)return;
	if(!setWidth)return;
	var imgs=containerObj.getElementsByTagName("img");
	for(i=0;i<imgs.length;i++){
		if(imgs[i].width>setWidth){
			imgs[i].width=setWidth;
			imgs[i].style.width=setWidth+"px";
		}
	}
	var embs=containerObj.getElementsByTagName("embed");
	for(i=0;i<embs.length;i++){
		if(!embs[i].height || !embs[i].width)continue;
		if(embs[i].width<setWidth)continue;
		embs[i].width=setWidth;
		embs[i].height*=Math.round(embs[i].width/setWidth);
		if(embs[i].style){
			embs[i].style.height=embs[i].height+"px";
			embs[i].style.width=embs[i].width+"px";
		}
	}
}
function nl(){return String.fromCharCode(10);}
function nl2br(str){
	if(!str)return "";
	if(stristr("<br",str))return str;//already has linebreaks
	if(stristr("<p",str))return str;
	if(stristr("<div",str))return str;
	if(stristr("<table",str))return str; 
	var re=/[\r\n]/g;        
	str=str.replace(re,"<br>");
	return str;
}
function br2nl(str){
	if(!str)return "";
	var re=/<br\s?\/>/g;
	return str.replace(re,"\n");
}
function getScrollTop(){//cross browser way to get scrollX/Y property
	if(typeof(window.scrollY)!="undefined")
		return window.scrollY;
	if(typeof(document.body)!="undefined")
		if(typeof(document.body.scrollTop)!="undefined")
			return document.body.scrollTop;
	return 0;
}
function getScrollLeft(){
	if(typeof(window.scrollX)!="undefined")return window.scrollX;
	if(typeof(document.body)!="undefined")
		if(typeof(document.body.scrollLeft)!="undefined")
			return document.body.scrollLeft;
	return 0;
}
function getWindowHeight(){
	var height=0;
	if(document.body){
		if(document.body.clientHeight)
			return document.body.clientHeight;
		if(document.body.scrollHeight)
			return document.body.scrollHeight;
	}
	if(document.documentElement){
		if(document.documentElement.clientHeight)
			return document.documentElement.clientHeight;
		if(document.documentElement.scrollHeight)
			return document.documentElement.scrollHeight;
	}
	return 0;
}
function getWindowWidth(){
	var width=0;
	if(document.body){
		if(document.body.clientWidth)
			return document.body.clientWidth;
		if(document.body.scrollWidth)
			return document.body.scrollWidth;
	}
	if(document.documentElement){
		if(document.documentElement.clientWidth)
			return document.documentElement.clientWidth;
		if(document.documentElement.scrollWidth)
			return document.documentElement.scrollWidth;
	}
	return 0;
}
function setXpos(lObj,x){
	if(!(lObj=getDomObj(lObj)))return 0;
	if(isNaN(x))return 0;
	lObj.style.left=x+"px";
}
function setYpos(lObj,y){
	if(!(lObj=getDomObj(lObj)))return 0;
	if(isNaN(y))return 0;
	lObj.style.top=y+"px";
}
function moveTo(lObj,x,y){
	setXpos(lObj,x);
	setYpos(lObj,y);
}
function moveToObj(lObj,targObj,alignment){
	//move lObj to just below targObj same left+top
	//alignment can be forced
	if(!(lObj=getDomObj(lObj)))return 0;
	if(!(targObj=getDomObj(targObj)))return 0;
	var xy=getOffsetCoords(targObj);
	var x=xy[0];
	var y=xy[1];
	var targHeight=getOffsetHeight(targObj);
	var targWidth=getOffsetWidth(targObj);
	var lObjHeight=getOffsetHeight(lObj);
	var lObjWidth=getOffsetWidth(lObj);
	var scrtop=getScrollTop();
	var wheight=getWindowHeight();
	var wwidth=getWindowWidth();
	if(!alignment){
		//try to auto-determine alignment
		if((scrtop+wheight)<(y+targHeight+lObjHeight) && lObjHeight<wheight)
			alignment="above";
		else
			alignment="below";
		
	}
	//--move menu below target object
	if(alignment=="right"){//align lobj to the right below targObj
		x+=targWidth;
		x-=lObjWidth;
	}else if(alignment=="rightof"){//top right corner of lObj aligned with bottom right corner of targobj
		x+=targWidth;
	}else if(alignment=="above"){
		y-=lObjHeight;
	}else if(!alignment || alignment=="below"){//--default to below, bottom left corner of targobj
		y=targHeight+y;
	}
	if((x+2+lObjWidth)>wwidth){
		x-=(lObjWidth-targWidth);
	}
	moveTo(lObj,x+2,y);
}

function hideOtherMenus(curMenu){
	//hides all menus modified by toggleMenu()
	addMenu(curMenu);
	for(i=0;i<THE_MENUS.length;i++){
		if(THE_MENUS[i]==curMenu)continue;
		if(!THE_MENUS[i])continue;
		if(!THE_MENUS[i].style)continue;
		THE_MENUS[i].style.visibility="hidden";
	}
}
function addMenu(menuObj){
	if(typeof(THE_MENUS)=="undefined")
		THE_MENUS=new Array();
	if(!THE_MENUS)
		THE_MENUS=new Array();
	THE_MENUS[THE_MENUS.length]=menuObj;
}
function toggleMenu(menuObj,targObj,alignment,forceVis){
//menuObj is the "menu" layer, targObj is the object to display the menu next to
//menuObj is assumed to be hidden by default
//forceVis is boolean that forces the menu object open or closed
	if(!(menuObj=getDomObj(menuObj)))return 0;
	if(!(targObj=getDomObj(targObj)))return 0;
	moveToObj(menuObj,targObj,alignment);
	if(typeof(forceVis)=="undefined")
		var newvis=menuObj.style.visibility=="visible"?"hidden":"visible";
	else
		newvis=(forceVis?"visible":"hidden");
	//---code to deal w/ other menus
	hideOtherMenus(menuObj);
	menuObj.style.visibility=newvis;
	menuObj.style.display=(newvis=="visible"?"":"none");
	if(typeof(quitReload)=="function")quitReload();
}
function hideMenu(menuObj){
	if(!(menuObj=getDomObj(menuObj)))return 0;
	menuObj.style.visibility="hidden";
	menuObj.style.display="none";
}
function toggleDisp(lObj,forceto){//returns the new state none|block
	if(typeof(forceto)!='undefined'){
		var res=setDisp(lObj,forceto);
		return (res?forceto:0);
	}
	var state=getDisp(lObj);
	if(!state)return 0;
	var targ=(state=="none"?"block":"none");
	if(!setDisp(lObj,targ))return 0;
	return targ;
}
function showAll(){
	if(!arguments.length)return;
	for(i=0;i<arguments.length;i++)
		toggleDisp(arguments[i],"block");
}
function hideAll(){
	if(!arguments.length)return;
	for(i=0;i<arguments.length;i++)
		toggleDisp(arguments[i],"none");
}

function toggleDispLabel(lObj,txtObj,ontxt,offtxt){
//--toggles display of lObj
//--changes txtObj text to ontxt when display is on, offtxt when display is off (e.g. "more"|"less", "bigger"|"smaller")
	var toggleState=toggleDisp(lObj);
	if(!toggleState)return 0;
	var txt=(toggleState=="none"?offtxt:ontxt);
	return setInnerHTML(txtObj, txt);
}

function openCVV2(){
	window.open('/lib/cvv2.html','cvv2','width=560,height=500,resizable=1,scrollbars=1');
}
function addListener(targObjName,eventName,func){
	var targObj=findObj(targObjName);
	if(!targObj)return;
	if(typeof(targObj["on"+eventName])=="undefined"){
		if(targObj.addEventListener){
			targObj.addEventListener(eventName,func,true);
			return;
		}
	}else{
		targObj["on"+eventName]=func;
	}
}
function linkobj(targObjName,url){
	//turns an object into a clickable link
	var targObj=findObj(targObjName);
	if(!targObj){return;}
	document.write("<style>#"+targObjName+"{cursor:pointer;cursor:hand;}</style>");
	oldonload=window.onload;
	window.onload=function(){
		if(typeof(oldonload)=="function")
			oldonload();
		doLinkObj(targObjName,url);
	}
}

function doLinkObj(objName,url){//same as above but doesn't write out style tag
	addListener(objName,"click",function(){location.href=url;});
}
function cursorwait(){
	if(document.body)
		if(document.body.style)
			document.body.style.cursor="wait";
	window.status="Please wait...";
}
function cursornormal(){
	if(document.body)
		if(document.body.style)
			document.body.style.cursor="default";
	window.status="";
}
function disableForm(elform){
	if(typeof(elform.disabled)!="undefined")elform.disabled=true;
	for(i=0;i<elform.elements.length;i++)
		elform.elements[i].disabled=true;
}
function enableForm(elform){
	if(typeof(elform.disabled)!="undefined")elform.disabled=false;
	for(i=0;i<elform.elements.length;i++)
		elform.elements[i].disabled=false;
}
function postTo(url,formname){
	if(formname)formname="theform";
	findObj("theform").action=url;
	findObj("theform").submit();
}

function getGet(url){
	var qs=strfrom(url,"?");
	if(!qs)return {};
	qs=qs.split("&");
	var ret={};
	for(i=0;i<qs.length;i++){
		var key=strto(qs[i],"=");//--can't use split because value may have an '=' sign like /w base64encoding
		var val=strfrom(qs[i],"=");
		ret[key]=val;
	}
	return ret;
}


var Base64 = {
    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        input = Base64._utf8_encode(input);
        while (i < input.length) {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
        }
        return output;
    },
    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < input.length) {
            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
        }
        output = Base64._utf8_decode(output);
        return output;
    },
    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    },
    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while ( i < utftext.length ) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    }
}
String.prototype.base64_encode=function(){return Base64.encode(this);}
String.prototype.base64_decode=function(){return Base64.decode(this);}

function handleLoginKeyPress(){
	if(typeof(event)=="undefined")return;
	if(!event)return
	if(!event.keyCode)return
	if(event.keyCode!=13)return
	findObj("signinForm").submit();
}


function openImageWindow(imgUrl,width,height){
	var imgUrl=img(imgUrl,"javascript:window.close()",'alt="Close Window"');
	var wnd=window.open("about:blank","_iwnd","width="+width+",height="+height+",scrollbars=1,resizable=1");
	wnd.document.write("<body style='margin:0px;border:0px'><center>"+imgUrl+"</center></body>");
}

