//"abc".contains("bc") returns true
//"abc".contains("cle") returns false
String.prototype.contains = function(arg)
{
    return this.indexOf(arg) >= 0;
}

function addClassName(el, className)
{
    if(!el.className.contains(className))
    {
        el.className += ' ' + className;
    }
}

function removeClassName(el, className)
{
    if(el.className.contains(className))
    {
        if(el.className.contains(' ' + className))
        {
            el.className = el.className.replace(' ' + className, '');
        }
        else if(el.className.contains(className + ' '))
        {
            el.className = el.className.replace(className + ' ', '');
        }
        else
        {
            el.className = el.className.replace(className, '');
        }
    }
}

function windowOpen(arg1, arg2)
{
    var newwin = null;
    var print = false;
    
    switch(arg1)
    {
        case "REGISTER_TERMS":
            newwin = window.open('/training/policy.html','policy','width=400,height=500,scrollbars=yes');
            print = true;
            break;
        case "PRIVACY":
            newwin = window.open('/privacy.aspx','privacy','width=400,height=500,scrollbars=yes');
            break;
        case "TIMELINE":
            newwin = window.open('/timeline.aspx','privacy','width=730,height=170,scrollbars=no');
            break;
        case "RCI_DIFF":
            newwin = window.open('/training/rciDifferences.aspx','privacy','width=617,height=574,scrollbars=no');
            break;
        case "PREVIEW":
            newwin = window.open(arg2,'preview','width=1044,height=869,scrollbars=yes');
            break;
        case "CREDITS":
            newwin = window.open('/training/credit-information.aspx','preview','width=523,height=390,scrollbars=yes');
            break;
    }
    
    if(newwin)
    {
        newwin.focus();
        if(print) newwin.print();
    }
}

function onImage(el)
{
    el.src = el.src.replace("_off", "_on");
}

function offImage(el)
{
    el.src = el.src.replace("_on", "_off");
}

function hideCreateLogin()
{
    ShowHideDropdowns(true);

    var objDiv = document.getElementById("create-login-wrapper");
    objDiv.style.display = "none";
}

function showCreateLogin()
{
    //Hide dropdowns that will exist under the popup.  In IE they would normally appear on top of the popup.
    ShowHideDropdowns(false);

    var objDiv = document.getElementById("create-login-wrapper");
    
    //sets the transparent background to the size of the window
    var height = -1;
    if(document.height) height = document.height;
    else if(document.body.offsetHeight) height = document.body.offsetHeight;
    
    if(height > -1) objDiv.style.height = height + 'px';
    
    //display inputs
    objDiv.style.display = "block";
}

function ShowHideDropdowns(show)
{
    var display = show ? "visible" : "hidden";
    
    var ddContact = GetElement('ctl00_cphMain_ddReasons');
    if(ddContact) ddContact.style.visibility = display;
}

function popCal(id, e) {

    var x = e.screenX;
    var y = e.screenY;
	link = window.open("/webCal.aspx?id=" + id,"Cal","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=200,height=168,left=" + x + ",top=" + y + ",alwaysRaised=1");
	link.focus();

}

function getMouseCoords(e, axis) {
	var x = 0;
	var y = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		x = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	
	if (axis == "Y") return y;
	if (axis == "X") return x;
}


function chkFilterDates(strStart, strEnd)
{
    var msg = "";
   
}

function GenerateGetElement()
{
	if (document.getElementById) return function(id) { return document.getElementById(id); }
	else if (document.all) return function(id) { return document.all[id]; }
	else if (document.layers) return function(id) { document.layers[id]; }
}
var GetElement = GenerateGetElement();

function uploadCompleted()
{
    var strFilename = document.rup.getResponse();
    if (GetElement("ucContractDetail_lblFilename") != null)
    {
        GetElement("ucContractDetail_lblFilename").innerHTML = strFilename;
        GetElement("ucContractDetail_hidFilename").value = strFilename;
    }
    if (GetElement("ucDocumentDetail_lblFilename") != null)
    {
        GetElement("ucDocumentDetail_lblFilename").innerHTML = strFilename;
        GetElement("ucDocumentDetail_hidFilename").value = strFilename;
    }
    if (GetElement("ucInvoiceDetail_lblFilename") != null)
    {
        GetElement("ucInvoiceDetail_lblFilename").innerHTML = strFilename;
        GetElement("ucInvoiceDetail_hidFilename").value = strFilename;
    }
}

//Preloads images so users don't have to wait.
//This function is called in pnav.js.
//If you need to the images that are preloaded, insert them into arrPreloadImages.
function PreloadImages()
{
    var arrPreloadImages = new Array(
        "/images/common/btnAboutUs_on.gif",
        "/images/common/btnSolutions_on.gif",
        "/images/common/btnTraining_on.gif")
        
    for(i = 0; i < arrPreloadImages.length; i++)
    {
        var preload = arrPreloadImages[i];
        var img = new Image();
        img.src = preload;
    }
}