var width = "250";
var border = "1";
var offsetx = 2;
var offsety = 10;

var fcolor = "#FFFFFF";
var backcolor = "#456AB5";
var textcolor = "#000000";
var capcolor = "#FFFFFF";

// used by Antioch.Common.Transfer
var handler       = "/Transfer.aspx";
var transferFault = "/Errors/Transfer-Fault";
var errorHandler  = "/Error.htm";
			
function goToTechTerm(techTerm)
{
	openWindow("/index.aspx?page=MainMenu/Our-products-and-services/Keeping-the-promise/Tech-highlights/Dictionary#" + techTerm);
}

/// <summary>
/// Gets the value of a name/value pair from the querystring
/// </summary>
/// <param name="pName">The name of the name/value pair</param>
/// <returns>The value of the name/value pair from the querystring.</returns>
function getQueryStringValue(pName)
{
	var lValue = "";
	var lCurrentUrl = document.URL;
	
	pName = pName + "=";
	var lPosStart = lCurrentUrl.indexOf( pName );
	
	if( lPosStart != -1 )
	{
		var lPosEnd = lCurrentUrl.indexOf("&", lPosStart);
		if (lPosEnd == -1)
		{
			lValue = lCurrentUrl.substring(lPosStart+pName.length, lCurrentUrl.length);
		}
		else
		{
			lValue = lCurrentUrl.substring(lPosStart+pName.length, lPosEnd);
		}
	}
	return lValue;
}

//Opens a new window
function openWindow(url)
{
    var mywindow = window.open(url);
    
    if (mywindow.opener == null)
    {
            mywindow.opener = self;
            mywindow.focus();
    }
}

//Opens a new window with a specific height and width
function openWindowWithWindowSize(url,screenHeight,screenWidth)
{
    var mywindow = window.open(url,"_blank","toolbar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=" + screenWidth + ", height=" + screenHeight + "");
    
    if (mywindow.opener == null)
    {
            mywindow.opener = self;
            mywindow.focus();
    }
}

// Submits the current form when Enter Key is pressed.
// This function is called from the "onkeydown" on the "Body" tag
var submitOnEnter = false;
function EnterKeySubmit()
{
	if (window.event.keyCode==13)
	{
		alert(submitOnEnter);
		document.form[0].submit()
	}
}

function addBookmark(bookmarktitle)
{  
	var strUseragent = navigator.userAgent.toLowerCase();
	if((strUseragent.indexOf("macintosh") > -1) || (strUseragent.indexOf("mac_powerpc") > -1) )
	{
		alert("Press Apple+D to add a bookmark to this site.");
	}
	else
	{
		if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
		{
			window.external.AddFavorite(location.href,bookmarktitle)
		}
		else 
		{ 
			if (navigator.appName=='Netscape')
			{
				alert("Press CTRL+D to add a bookmark to this site.");
			}
			else 
			{
				alert("Sorry, your browser does not support this function.")
			}
		}
	}
    return ;
}

//Flag used to determine if globe information should be persisted
var shouldPersist = false;

// Sets locale information in a cookie based on what was selected on the globe page
function setLocaleInformationInCookie(pRegion, pMarket, pLocale, pUrl, pCookieExpirationDays)
{
	if(shouldPersist)
	{
		var now = new Date();
		now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * pCookieExpirationDays);
		
		SetCookie(CookieKeyRegion, pRegion, now, "/");
		SetCookie(CookieKeyMarket, pMarket, now, "/");
		SetCookie(CookieKeyLocale, pLocale, now, "/");
		SetCookie(CookieKeyCMDomain, pUrl, now, "/");
	}
	else
	{
		// Expire the cookie
		DeleteCookie (CookieKeyRegion, "/");
		DeleteCookie (CookieKeyMarket, "/");
		DeleteCookie (CookieKeyLocale, "/");
		DeleteCookie (CookieKeyCMDomain, "/");
	}
}

function PWSConfirm(url, message)
{
	if (confirm(message))
	{
		window.location=url;
	}
}


function SwitchContext(dropDown)
{
    var index = dropDown.selectedIndex
    var value = dropDown.options[index].value
    window.location.href=value;
}


//Takes the value of a textBox and adds it to a div and a hiddenfield
//It adds the values in a comma delimited string preceded by the given text
function evaluateVoucherCode(textBox, div, hiddenField, precedingText, errorText, errorDuplicateText, errorSpan)
{
    var errorSpanHasInnerText = (errorSpan.innerText != undefined) ? true : false;
    var hiddenText = hiddenField.value;
    var string;
    var hasInnerText = (div.innerText != undefined) ? true: false;
    if(!hasInnerText)
    {
        string = div.textContent;
    }
    else
    {
        string = div.innerText;
    }
    
    if(hiddenText == "" || hiddenText.indexOf(textBox.value) == -1)
    {
        if(!isNaN(textBox.value) && textBox.value.length == 8)
        {
            var beggingText = precedingText + textBox.value;
            var additionalText = ", " + precedingText + textBox.value;
            
            if(textBox.value != "")
            {
                if(!errorSpanHasInnerText)
                {
                    errorSpan.textContent = "";
                    if(string == "")
                    {
                        string = beggingText;
                        hiddenField.value = beggingText;
                    }
                    else
                    {
                        string += additionalText;
                        hiddenField.value += additionalText;
                    }
                }
                else
                {
                    errorSpan.innerText = "";
                    if(string == "")
                    {
                        string = beggingText;
                        hiddenField.value = beggingText;
                    }
                    else
                    {
                        string += additionalText;
                        hiddenField.value += additionalText;
                    }
                }
                addStringToDiv(string, div);
            }
        }
        else
        {
            if(!errorSpanHasInnerText)
            {
                errorSpan.textContent = errorText;
            }
            else
            {
                errorSpan.innerText = errorText;
            } 
        }
    }
    else
    {
        if(!errorSpanHasInnerText)
        {
            errorSpan.textContent = errorDuplicateText;
        }
        else
        {
            errorSpan.innerText = errorDuplicateText;
        }
    }
    textBox.value = "";
    return false;
}

///Takes the given string and puts it in the div
function addStringToDiv(string, div)
{
    var hasInnerText = (div.innerText != undefined) ? true : false;
    
    if(!hasInnerText)
    {
        div.textContent = string
    }
    else
    {
        div.innerText = string
    }

}

/*
 *  Disable Button after Post Back to avoid multiple Requests to the Server
 */
function DisableControl(controlId)
{
  document.getElementById(controlId).disabled =true;
}
 
function DisableControl_SetTimeout(controlId,interval)
{
  setTimeout("DisableControl('" +controlId + "')",interval);
}
function disableButton(control)
{
  DisableControl_SetTimeout(control.id,1000);
}

// method iterates through a html form and sets the focus
// for the first input or select element it finds
function SetFocus(){
	for(i=0; i<document.forms.length; i++){
		frm = document.forms[i];
		for(j=0; j<frm.elements.length; j++){
			var element = frm.elements[j];
			var sTag = element.tagName.toUpperCase();
			var sType = element.type.toUpperCase();
			if(!element.disabled){
				if((sTag == "INPUT" && (sType == "TEXT" || sType == "RADIO")) || sTag == "SELECT" || sTag == "TEXTAREA"){
					element.focus();
					return;
				}
			}
		}
	}
}

// Will fire the onchange event on an HTML control
function fireOnChangeEvent(pElementID)
{
    var lElement = document.getElementById(pElementID);

    //On IE
    if(lElement.fireEvent)
    {
        lElement.fireEvent('onchange');
    }
    //On Gecko based browsers
    if(document.createEvent)
    {
        var lEvent = document.createEvent('HTMLEvents');
        if(lEvent.initEvent)
        {
            lEvent.initEvent('change', true, true);
        }
        if(lElement.dispatchEvent)
        {
            lElement.dispatchEvent(lEvent);
        }
    }
}