var homeUrlGlb = location.host;

function initIeHome(homeUrl) {
    homeUrlGlb == homeUrl;
    document.getElementById("tbar-ieHome2").href = "http://" + homeUrlGlb;
}

function makeIeHome(lnk) {
    lnk.style.behavior = 'url(#default#homepage)';
    lnk.setHomePage("http://" + homeUrlGlb);
    return false;  
}

function msDown1(img,flNam) {
    img.src = "/images/top-bar/" + flNam + "2.gif"; 
}
function msUp1(img,flNam) {
    img.src = "/images/top-bar/" + flNam + ".gif"; 
}
function showLoginForm() {
    document.getElementById("onlogin").style.display = '';
    document.getElementById("onload").style.display = "none";
}

function hideLoginForm() {
    document.getElementById("onlogin").style.display = "none";
    document.getElementById("onload").style.display = "";
}

function getAjaxObjectTB() { 
    var objXMLHttp=null
        if (window.XMLHttpRequest) {
            objXMLHttp=new XMLHttpRequest()
        }
        else if (window.ActiveXObject) {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
    return objXMLHttp
} 

function sendEmailTB(idSfx) {
    xmlHttp=getAjaxObjectTB()
    if (xmlHttp==null) {
        alert ('Your browser does not support HTTP Request. Please contact us at "info@prodege.com" to get your password.')
        return;
    }
    txtEmail = getElementByIdName("emailAddress" + idSfx).value;
    if (txtEmail == "") {
        alert ("Please enter your Email Address.")
        return;
    }
    url="/?cmd=sb-pswd-reminder&email=" + txtEmail;
    url=url+"&amp;sid="+Math.random();
    xmlHttp.onreadystatechange=getPResultTB;
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function getPResultTB() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        result = xmlHttp.responseText
        if (result == 1) {
            alert("Your Password has been sent.");
        } 
        else  if (result == 2) {
            alert("Your Email Address was not found on our system.");
        }
        else if (result == 3) {
            alert("Please enter a valid Email Address.");
        } 
        else  {
            alert("There was an unexpexted error sending your password." +
            String.fromCharCode(10) + String.fromCharCode(10) + "Please try again or contact us at info@prodege.com");
        } 
    }
}
function getElementByIdName(elmId) {
    elm = document.getElementById(elmId);
    if (elm.id == elmId) {
        return elm;
    }
    elms = document.getElementsByName(elmId);
    for(i=0; i<elms.length; i++) {
        elm = elms[i];
        if (elm.id == elmId) {
            return elm;
        }   
    }
}
function logInTB(idSfx) {
    txtEmail = getElementByIdName("emailAddress" + idSfx);
    txtPswd = getElementByIdName("pswd" + idSfx);
    valid = true;
    if (txtEmail.value == "") {
        alert("Please enter your Email Address");
        return;
    }
    if (txtPswd.value == "") {
        alert("Please enter your Password");
        return;
    }
    document.getElementById("frmLogIn-tbar" + idSfx).action = "/?cmd=sb-login&from=" + 
         (location.href.indexOf("?") > -1 ? escape(location.href.replace(/&invalid-login=./g,'')).replace(/\+/g,'%2b') : location.href + "?cmd=home");
    document.getElementById("frmLogIn-tbar" + idSfx).submit();
}

function logOutFCCallback(success) {
    if (success) {
		location.href = "/?cmd=sb-logout&from=" + escape(location.href.replace(/&invalid-login=./g,'')).replace(/\+/g,'%2b');	
	}
	else {
		alert("There's been a problem logging out of Facebook.\n\nPlease try again.")
	}
}

function TBFCCallback() {
	location.href = location.href.replace(/&invalid-login=./g,'');	
}

function RegistrationFCCallback() {
	location.href = location.href.replace(/&invalid-login=./g,'');	
}  
//function RegistrationFBOnly() {
//	  location.href = "/?cmd=sb-register&from=sb-fb-register";
//}  

function logOutTB() {
	if (typeof FB != "undefined") {
		var aUID = null;
		FB_RequireFeatures(["Connect"], function() {
			initFB()
			aUID = FB.Connect.get_loggedInUser();
			if ( aUID != null ) {
				FB.Connect.logout(logOutFCCallback);
			} else {
				location.href = "/?cmd=sb-logout&from=" + escape(location.href.replace(/&invalid-login=./g,'')).replace(/\+/g,'%2b');	
			}
		});
	}
	else
	{
		location.href = "/?cmd=sb-logout&from=" + escape(location.href.replace(/&invalid-login=./g,'')).replace(/\+/g,'%2b');	
	};
}

    function enterLoginTB(evt, idSfx) {
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        if(charCode == 13) {
            logInTB(idSfx);
            return false;
        }  
    }       
    
function blinkSwagBucks() {
    blinks ++; 
    if (blinks > 90) {
        clearInterval(blinkTimer);
        return
    }
    colr = (blinks%2 ? "#FF0909" : "#666666");
    document.getElementById("tbar-sbAmount").style.color = colr;
}

function focusPassword(ctl) {
    ctl.style.display='none';
    pswdCtl = document.getElementById('pswd2');
    pswdCtl.style.display='';
    pswdCtl.focus();
}

function blurPassword(ctl) {
    if (ctl.value == "") {
        ctl.style.display='none';
        document.getElementById('pswdTxt').style.display='';
    }
}

function blurEmail(ctl) {
    if (ctl.value == "") ctl.value="email address";
}

function focusEmail(ctl) {
    if (ctl.value == "email address") ctl.value="";
}
