function get(n, d) {
	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=get(n,d.layers[i].document);
		}
		if(!x && d.getElementById) {
			x=d.getElementById(n); 
		}
	return x;
}

function nf(amnt) {
    var mnt = 0;
    mnt = (Math.round(amnt*100))/100;
    return (mnt == Math.floor(amnt)) ? amnt + '.00' 
              : ( (amnt*10 == Math.floor(amnt*10)) ? 
                       amnt + '0' : amnt);
}

function chkLogin(f) {
	return (f.username.value == '' || f.password.value == '') ? false:true;
}

function lostPass(f){
	var url = "../" + f + "/lostpass.php";
	window.open(url,'cmdWin','width=300,height=125,resizable');
}

function checkFormReq(f,req,spares) {
	var error = false;
	var confPass = false;
	var confEmail = false;
	var confEmail2 = false;
	var msg = "ERROR\n";
	var cnt = 0;
	var fld;
	if (req.indexOf("password")!=-1 && req.indexOf("password2")!=-1) {
		confPass = true;
	}
	if (req.indexOf("email")!=-1 && req.indexOf("email2")!=-1) {
		confEmail = true;
	}
	if (spares.indexOf("email3")!=-1 && spares.indexOf("email4")!=-1) {
		confEmail2 = true;
	}

	required = req.split(",");
	second_email = spares.split(",");
	
	for (i=0;i<required.length;i++) {
		eval("f." + required[i] + ".style.backgroundColor='#FFFFFF'");
		eval('fld = f.' + required[i] + '.value');
		if (Trim(fld) == '') {
			error = true;
			//alert(required[i]);
			cnt++;
			eval("f." + required[i] + ".style.backgroundColor='#FFCCCC'");
		}
	}
	var s = (cnt!=1) ? "s":"";
	if(cnt>0) { msg += "\n" + cnt + " mandatory field" + s + " missing"; }
	
	if (req.indexOf("email")!=-1) {
		if(!checkEmail(f.email.value)) {
			error = true;
			msg += "\nEmail address is not valid";
		}
	}
	if (spares.indexOf("email3")!=-1) {
		if(!checkEmail(f.email.value)) {
			error = true;
			msg += "\n2nd Email address is not valid";
		}
	}

	if(confPass && f.password.value != f.password2.value) {
		error = true;
		msg += "\nPasswords do not match"
	}
	if(confEmail && f.email.value != f.email2.value) {
		error = true;
		msg += "\nEmail addresses do not match"
	}
	if(confEmail2 && f.email3.value != f.email4.value) {
		error = true;
		msg += "\n2nd Email addresses do not match"
	}
	
	if (error) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function checkFormReqEdit(f,req) {
	var error = false;
	var msg = "ERROR\n";
	var cnt = 0;
	var fld;

	required = req.split(",");
	
	for (i=0;i<required.length;i++) {
		eval("f." + required[i] + ".style.backgroundColor='#FFFFFF'");
		eval('fld = f.' + required[i] + '.value');
		if (Trim(fld) == '') {
			error = true;
			//alert(required[i]);
			cnt++;
			eval("f." + required[i] + ".style.backgroundColor='#FFCCCC'");
		}
	}
	var s = (cnt!=1) ? "s":"";
	if(cnt>0) { msg += "\n" + cnt + " mandatory field" + s + " missing"; }
	
	
	if (error) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

// hide address from spam robots
function doMail(user,domain,style){
	var at = String.fromCharCode(64);
	var linkStr = "mai" + "lto:" + user + at + domain;
	document.write('<a class=\"' + style + '\" href=\"' + linkStr + '\">' + user + at + domain + '</a>');
}

function checkEmail(str) {
	var valid = true;
	if(str.indexOf("@") == -1) { valid = false; }
	if(str.indexOf(".") == -1) { valid = false; }
	return valid;
}

// Only need to give first three params
function openCenteredWindow(url, height, width, name, parms){
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { 
   		if (win) {
			win.window.focus();
		}
   }
   return win;
}

function disablecopytext() {
	if(event.srcElement.tagName!='INPUT' && event.srcElement.tagName!='IMG') {
		window.event.returnValue = false;
	}
}

function disablerightclick() {
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	} else if (document.all&&!document.getElementById) {
		document.onmousedown=clickIE4;
	}
}

function clickIE4() {
	if (event.button==2) {
		return false;
	}
}

function clickNS4(e) {
	if (document.layers||document.getElementById&&!document.all) {
		if (e.which==2||e.which==3) {
			return false;
		}
	}
}

function disablesaveas() {	
	if(document.images) {
    	for(i=0;i<document.images.length;i++) {
            document.images[i].onmousedown = right;
            document.images[i].onmouseup = right;
        }
    }
}

function right(e) {
	if (navigator.appName == 'Netscape' && e.which == 3) {
	   alert('Images are copyright!');
	   return false;
    }
    if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
       alert('Images are copyright!');
	   return false;
	} else {
		return true;
	}
}

function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


function LTrim(STRING){
	while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}

function checkAgentReq(f,req) {
	var error = false;
	var confEmail = false;
	var msg = "ERROR\n";
	var cnt = 0;
	var fld;
	if (req.indexOf("email")!=-1 && req.indexOf("email2")!=-1) {
		confEmail = true;
	}
	required = req.split(",");
	
	for (i=0;i<required.length;i++) {
		eval("f." + required[i] + ".style.backgroundColor='#FFFFFF'");
		eval('fld = f.' + required[i] + '.value');
		if (Trim(fld) == '') {
			error = true;
			//alert(required[i]);
			cnt++;
			eval("f." + required[i] + ".style.backgroundColor='#FFCCCC'");
		}
	}
	var s = (cnt!=1) ? "s":"";
	if(cnt>0) { msg += "\n" + cnt + " mandatory field" + s + " missing"; }
	
	if (req.indexOf("email")!=-1) {
		if(!checkEmail(f.email.value)) {
			error = true;
			msg += "\nEmail address is not valid";
		}
	}
	if(confEmail && f.email.value != f.email2.value) {
		error = true;
		msg += "\nEmail addresses do not match"
	}
	
	if (error) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function hideDiv(hidDiv){
  var isIE = (window.ActiveXObject)?true:false;
  var attributeClass = (isIE)?"className":"class";
  var element = document.getElementById(hidDiv);

 if(element==null)
   return;
   if(element.getAttribute(attributeClass)=="hidden")
        element.setAttribute(attributeClass, "visible");
   else
        element.setAttribute(attributeClass, "hidden");
}	