﻿
// Global Variable Declarations
var isLoaded = false;

// Global Functions

// Adds appropriate targets to anchor tags.
function processAnchorTargets()
{
    if (!document.getElementsByTagName) return;

    var anchors = document.getElementsByTagName("a");
    
    for (var i=0; i < anchors.length; i++)
    {
        var anchor = anchors[i];
        
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup")
        {
            anchor.target = "_blank";
        }
    }
}

// Submits form[0]
function submitForm()
{
    document.forms[0].submit();
    return true;
}

// Submit Target Form
function submitTargetForm(in_formIndex)
{
    document.forms[in_formIndex].submit();
    return true;
}


// Image Swaps
function imageSwap(in_Name, in_State)
{
    if (!isLoaded)
    {
        return true;
    }
    document.images[in_Name].src = eval(in_Name + "_" + in_State + ".src");
}

// Opens a popup with a description of the Card Code.
function openCardCodeDescription(in_appRoot)
{
	popWindow(in_appRoot + "CardCode.html", "scrollbars=no,width=575,height=350");
}

// Window Openders
function popWindow(in_target, in_WindowParameters)
{
    //windowParameters are very browser dependent.  Be sure to test in all browswers when
    //changing window parameters.

    //For instance for Both IE and Netscape browsers to absolutely position a window properly 2 sets
    // of dimensions should be included example: screenX=0,screenY=0,left=0,top=0
    //To set the height and width of the windows example: width=625,height=400
    //A Good PopupWindow in all browsers with no toolbar, no scrollbar, and not resizable.
    //windowParameters = "scrollbars=no,width=625,height=400";
    
    if ( in_WindowParameters.length == 0 )
    {
        in_WindowParameters = "resizable,dependent,toolbar,scrollbars,location,status,menubar";
    }
    
    popupWin = window.open(in_target,'PopupWindow',in_WindowParameters);
}

function createPopup(image,width,height,campaign)
{
	var isNS = (document.layers);
	var isIE = (document.all);
	var htmlString1 = ('<html><head><title>YUDU Press  ');
	var htmlString2 = ('</title></head><body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#000000" alink="#FF00FF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">');
	var htmlString3 = ('<a href="javascript:window.close()"><img src="'+image+'" border="0" hspace="0" vspace="0" alt="Click To Close" /></a></body></html>');
	var htmlComplete = (htmlString1+campaign+htmlString2+htmlString3);
	var OpenWindow = window.open("", "media_popup", "height="+height+",width="+width);
	if (isNS) {
		OpenWindow.document.open();
		OpenWindow.document.write(htmlComplete)
		OpenWindow.document.close();
	} else {
		OpenWindow.document.write(htmlComplete);
	}
	
	return false;
}

// Global Initialization

function blurInputs()
{
    if (!document.getElementsByTagName) return;

    var inputs = document.getElementsByTagName("input");
    
    for (var i=0; i < inputs.length; i++)
    {
        var inp = inputs[i];
        inp.blur();
    }
    
}

function globalInit()
{
    processAnchorTargets();
    
    isLoaded = true;
} 
