function fixUserType () {
	if("broker"==myuser) {document.usertypeswitch.usertype[0].checked=true;}
	else {document.usertypeswitch.usertype[1].checked=true;}
}

function addPadlock(){
	var str, adv="/advisor/", toBeInserted, pcTitle,inserting=true;
	var closedHtml="<img src='/images/padlock-open.gif' border='0'/>";
	var openHtml="<img src='/images/padlock-open.gif' border='0'/>";
	var closedTitle="Please login to see Expanded Features and Content";
	var openTitle="Expanded Features and Content are available to you";
	if ((myuser == "broker") && (2<=securityStatus)) {toBeInserted=openHtml;pcTitle=openTitle;inserting=false;} 
	else {toBeInserted=closedHtml;pcTitle=closedTitle;}
	if (inserting) {
		for(i=0;i<document.links.length;i++){
			str=document.links[i].href;
			//alert (str);
			if( (str.indexOf(adv) >= 0)
			 && (str.indexOf("javascript") < 0 )
			 && (str.indexOf("rewrite_href=no") < 0 )
			 && (document.links[i].innerHTML.indexOf(toBeInserted) < 0)) {
				document.links[i].innerHTML=document.links[i].innerHTML + toBeInserted;
				document.links[i].title=pcTitle;
			}
		}
	}
}
function hostWithoutPort(host) {
	hostNoPort=host, columnPosition=0;
	if (0<(columnPosition=host.indexOf(':'))) {hostNoPort=host.substring(0,columnPosition);}
	return hostNoPort;
}
function appendPrinterFriendlyIfNeeded(){genericAppend(false, "nav=no","rewriteurl=no");}
function appendUserTypeIfNeeded(){if("broker"==myuser) {genericAppend(true, "usertype=advisor","rewriteadvisorurl=no");}}
function genericAppend(force,queryParamAndValue, doNotRewriteParamAndValue) {
	var str;
	if((document.location.search.indexOf(queryParamAndValue)!=-1) || force) {
		for(i=0;i<document.links.length;i++){
			if (document.location.host==hostWithoutPort(document.links[i].host)) {
				str=document.links[i].search;
				if(str.indexOf(queryParamAndValue)==-1&&document.links[i].href.indexOf("javascript")==-1&&document.links[i].href.indexOf("mailto")==-1 && document.links[i].href.indexOf(doNotRewriteParamAndValue) == -1 ){
					if(str.indexOf("?")!=-1) {document.links[i].href=document.links[i].protocol+"//"+document.links[i].host+"/"+document.links[i].pathname+document.links[i].search+"&"+queryParamAndValue+document.links[i].hash;}
					else {document.links[i].href=document.links[i].protocol+"//"+document.links[i].host+"/"+document.links[i].pathname+"?"+queryParamAndValue+document.links[i].hash;}
				}
			}
		}
		for(i=0;i<document.forms.length;i++){
			str=document.forms[i].action;
			if(str.indexOf(queryParamAndValue)==-1){
				if(str.indexOf("?")==-1) {document.forms[i].action=document.forms[i].action+"?"+queryParamAndValue;}
				else {document.forms[i].action=document.forms[i].action+"&"+queryParamAndValue;}
			}
		}
	}
	
}

function overwriteURLs(){
	for(i=0;i<document.links.length;i++){
		if(document.links[i].href.indexOf("javascript")!=-1){
			document.links[i].href=document.links[i].href.substring(document.links[i].href.search("javascript"));}
	}
	
	appendPrinterFriendlyIfNeeded();
	appendUserTypeIfNeeded();
	addPadlock();
	//fixUserType ();
}
function trimSpaces(targetString,trimMode) {
    // 0 = trim begin and end
    // 1 = trim begin only
    // 2 = trim after only
    var iPos=0;
    if (trimMode==0 || trimMode==1) {
        if (targetString.charAt(iPos)==" ") {
            while(targetString.charAt(iPos)==" ") {iPos++; }
            targetString = targetString.substr(iPos);
        }
    }
    iPos = targetString.length-1;
    if (trimMode==0 || trimMode==2) {
        if (targetString.charAt(iPos)==" ") {
            while(targetString.charAt(iPos)==" ") {iPos--;}
            targetString = targetString.substr(0,iPos+1);
        }
    }
    return targetString;
}
function checkemail(email){
	//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var filter=/^([!-Z^-~]+)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return (filter.test(email));
}