
function GetGoogleKey(gphosttxt, arrGoogleKeys)
{
    var sHost = gphosttxt.toUpperCase();
    for (var i = 0; i < arrGoogleKeys.length ; i++) {
        if (arrGoogleKeys[i][0].toUpperCase() == sHost || arrGoogleKeys[i][0] == '') {
            return arrGoogleKeys[i][1];
        }
    }
    return '';
}

function GoogleMapSetup(arrGoogleKeys, sGoogleURLMask)
{
  var DanaEvalSave = null;
  try {
    DanaEvalSave = DanaEval;
  } catch (e) { }
  try {
    var DanaEval = function(v) { return v; };  
  } catch (e) { }
  eval("var gphosttxt = document.location.hostname;");
  try {
    DanaEval = DanaEvalSave;
  } catch (e) { }
  
  var sGoogleKey = GetGoogleKey(gphosttxt, arrGoogleKeys);
  var sURL = sGoogleURLMask.replace("~KEY~", sGoogleKey);
  
  //alert(gphosttxt+":::"+sURL);
  
  document.write(unescape("%3Cscript src='" + sURL + "' type='text/javascript'%3E%3C/script%3E"));
}

//function to select all itmes in the final list for submission
function ToggleCheckControl(spanFieldControlName, fieldName, ControlOn, ControlOff)
{
    var bState;
    if (eval('document.forms[0].all(\'' + spanFieldControlName + '\')').innerHTML == ControlOn)
    {
        eval('document.forms[0].all(\'' + spanFieldControlName + '\')').innerHTML = ControlOff;
        bState = true;
    }
    else
    {
        eval('document.forms[0].all(\'' + spanFieldControlName + '\')').innerHTML = ControlOn;
        bState = false;
    }
    if (eval('document.forms[0].' + fieldName) != null)
    {
    	var selLength = eval('document.forms[0].' + fieldName).length;
    	if (isUndefined(selLength)) {    // Handle the single case
    	    eval('document.forms[0].' + fieldName).checked = bState;
    	}
    	else {
    	    for(i = 0 ; i < selLength ; i++)
    		    {eval('document.forms[0].' + fieldName)[i].checked = bState;}
    	}
	}
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

//function to select all itmes in the final list for submission
function selectAll(fieldName,OnOff)
{
	var selLength = eval('document.forms[0].' + fieldName).length;
	for(i = 0 ; i < selLength ; i++)
		{eval('document.forms[0].' + fieldName)[i].checked = OnOff;}
}

//Function for launching a window to display help files for Custom Impressions module
function helpWin(URL)
{
	window.open(URL,'help','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=420,height=500,left=100,top=100');
}

function imageWin(URL)
{
	window.open(URL,'Image','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=650,height=600,left=100,top=100');
}

function LinksWin(URL)
{
	window.open(URL,'Image','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}

function openInNewWindow(href)
{
    var config = {
        status: 1
        ,resizable: 1
        ,scrollbars: 1
        ,width: 800
        ,height: 650
        ,target: '_blank'
    };

    if (href == '')
        return false;

    var attrs = '';
    var sep = '';
    for (var i in config) {
        if (i == 'target') { continue; }
            attrs += sep + i + '=' + config[i];
            sep = ',';
        }

    var pop = window.open(href, config.target, attrs);
    if (pop) {
        if (pop.focus) { pop.focus(); }
        return false;
    }
   
    return true;
 }

function fnProcessReturn(btnName){
    var btn = document.getElementById(btnName);

    if (window.event)
    {
        if (event.keyCode == 13)
        {
    	    event.returnValue=false;
		    event.cancelBubble = true;
		    btn.click();
		}
	}
    else if(event.which && event.which == 13) // Netscape/Firefox/Opera
    {
        event.returnValue=false;
	    event.cancelBubble = true;
		btn.click();
	}
}

// START - Google analytics tagging related functions //
function logRelatedItems(googleTag,anchor)
{  
  logEvent(googleTag,false);
  document.location.href=anchor;  
}

// END - Google analytics tagging related functions //