try{
    addEventListener('load', function() {
    setTimeout(hideAddressBar, 0);	}, false);
    function hideAddressBar() {
        window.scrollTo(0, 1);
    }
}catch(e){}
    

function doSubmit(e)
{
var f;
    try{
        //f = findParent(e, "form");
        f = document.forms[0];
        f.action = e.href;
        f.submit();
    }
    catch (e) { alert(e); }
}

function doSubmitByUrl(submitUrl)
{
var f;
    try{
        var href = document.location.href;
        if(href.match(/(\&code=\d+)(.+)/))
        {
            submitUrl += (RegExp.$1 + RegExp.$2);
        }
        f = document.forms[0];
        f.action = submitUrl;
        f.submit();
    }
    catch (e) { alert(e); }
}
function findParent(node, localName)
{
    while (node && (node.nodeType != 1 || node.tagName.toLowerCase() != localName))
        node = node.parentNode;
    return node;
}

function submitOnChange(action)
{
    var frm = document.forms[0];
    frm.action = action;
    frm.submit();
}

function isValidEmail(sEmail){ return sEmail.search(/^.+@.+\..+/) > -1; }

function validateForm(fieldList)
{
	var control = null;
	var bRet = true;
	try {
		for (var count = 0; count < fieldList.length; count++) {
			control = document.getElementById(fieldList[count]);
			var v = control.value;
			if (v.length == 0)
				throw ("Please insert " + control.getAttribute("title"));
//			if (control.id == "login" && !isValidLogin(v))
//				throw MSG_INVALID_LOGIN;
			if ((control.id == "sendee" || control.id == "sender") && !isValidEmail(v))
				throw "Invalid e-mail address";
		}
	}
	catch (errMessage) {
		alert(errMessage);
		control.focus();
		bRet = false;
	}
	return bRet;
}

function submitEmail(frm, fieldList) 
{
    try {
        var o1 = frm.elements["notesText"];
        var o2 = frm.elements["notes"];
        
        o1.value = o2.value;
        if (validateForm(fieldList)) 
            frm.submit();
        else
            event.preventDefault();
    }
    catch (e){}
}

function sendEvent(tagObj, type)
{
    try
    {
        var arg, param;
        var href = tagObj.getAttribute("href");
        if (type == "website")
            param = href;
        else
        {
            if (type == "address")
                arg = href.split("?q=");
            else if (type == "ticker")
                arg = href.split("?qlist=");
            else    
                arg = href.split(":");
            param = arg[1];
        }
        var unitId = tagObj.getAttribute("unitId");
        switch(type)
        {
            case "contact":
                doSendEvent("email", 0, "Email : " + param);
                break;
            case "phone":                
                doSendEvent("phone", (unitId ? unitId : 0), "Phone : " + param);
                break;
            case "address":
                doSendEvent("address", (unitId ? unitId : 0), "Address : " + param);
                break;
            case "website":
                doSendEvent("url", (unitId ? unitId : 0), "URL : " + param);
                break;
            case "ticker":
               doSendEvent("ticker", (unitId ? unitId : 0), "Stock symbol : " + param);
               break;            
        }        
    }
    catch(e) { }
}

function doSendEvent(type, unitId, data)
{
    var args = [];
    args.push("type='" + escapeEntities(type) + "'");
    args.push("unitId='" + unitId + "'");
    args.push("data='" + escapeEntities(data) + "'");
    var href = "sendEvent.aspx";
    sendXMLHttp(args, href, "POST");
}

function sendXMLHttp(args, href, method)
{
    try
    {
        var req = new XMLHttpRequest();
        if (args)
        {
            req.open(method || "GET", href, true);
            var data = "<sendEvent " + args.join(" ") + " />";     
            req.send(data);
        }
        else
        {
            req.open(method || "GET", href, true);
            req.send(null);
        }
    }
    catch(e) { }
    
}

function isiPhone() {
    return (navigator.platform.indexOf('iPhone') > -1 || navigator.platform.indexOf('iPod') > -1);
}

function setInnerHeight()
{
    if(isiPhone()) return;
    var availHeight = window.screen.availHeight;
    if(!isiPhone() && (availHeight != null &&  availHeight < 400)) return;
    //For IE
    var innerTable = document.getElementById("innerTable");
    //Footer - 37;HeaderBar - 46;ScrollBar - 37
    innerTable.style.height = (window.screen.availHeight - 37 - 46 - 37) + "px";    
}

function skipHistory() 
{
    if (document.location.href.match(/doc.aspx/)) 
        window.history.forward();
}

function setStates()
{
    try{
        var countries = document.getElementById("country");
        var states = document.getElementById("state");
	if(countries.value == "76")
            states.removeAttribute("disabled");
        else
            states.setAttribute("disabled", "disabled");
    }catch(e){}
}

function confirmDelete(profile)
{
    return confirm("Are you sure you want to remove \"" + profile + "\" from your favorites?");
}
