// pop-up windows //

function showPopUp(file, width, height)
{
	var new_win = window.open(file, 'new_win', ('HEIGHT=' + height + ',WIDTH=' + width + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,status=yes'));
}


function agendaPop(file, width, height)
{
	var new_win = window.open(file, 'new_win', ('HEIGHT=' + height + ',WIDTH=' + width + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,status=yes'));
	
	new_win.print();
}

// toggle display of object //

function showDiv(sec)
{
	if(document.getElementById(sec).style.display == 'none')
	{
     		document.getElementById(sec).style.display = 'inline';
    	}
    	else
    	{
		document.getElementById(sec).style.display = 'none';
	}
}



// collapsable menus //

function showsublist(item){
	var xdisplay = document.getElementById(item).style.display;
       document.getElementById(item).style.display = ((xdisplay == "block") ? "none" : "block");

	var aimage = document.getElementById(item).parentElement.style.listStyleImage;
       document.getElementById(item).parentElement.style.listStyleImage = ((aimage == "url(/transactionservices/home/img/carat_open.gif)") ? "url(/transactionservices/home/img/carat_closed.gif)" : "url(/transactionservices/home/img/carat_open.gif)");
   }


// clear text in form field upon focus //
		function clearText(field){
			if (field.defaultValue == field.value) field.value = '';
			else if (field.value == '') field.value = field.defaultValue;
		}

// Cookie Functions //

function testCookies()
{
	var name = "CookieTest";
	
	try
	{
		createCookie(name,'true',1);
		
		if (readCookie(name) == "true")
		{
			eraseCookie(name);
			return true;
		}
	}
	catch(e)
	{
		return false;
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}


// detect which directory the page resides in //
function $(id)
{
	if (typeof id == "string")
	{
		return document.getElementById(id);
	}
	else if (typeof id == "object")
	{
		return id;
	}
	else
	{
		return null;
	}
}

function hasCssClass(id, cssClass)
{
	if ($(id) == null) return false;
	
	var cssClassList = $(id).className;
	
	if (cssClassList.length == 0)
	{
		return false;
	}
	else
	{
		if (cssClassList.indexOf(cssClass) >= 0)
		{
			return true;
		}
		return false;
	}
}

function addCssClass(id, cssClass)
{
	if ($(id) == null) return false;
	
	var cssClassList = $(id).className;
	
	if (cssClassList.length == 0)
	{
		$(id).className = cssClass;
		return true;
	}
	
	if (cssClassList.indexOf(cssClass) >= 0)
	{
		return false;
	}
	else
	{
		var classArray = cssClassList.split(" ");
		classArray.push(cssClass);
		$(id).className = classArray.join(" ");
		return true;
	}
}

function removeCssClass(id, cssClass)
{
	if ($(id) == null) return false;
	
	var cssClassList = $(id).className;
	
	if (cssClassList.length == 0)
	{
		return false;
	}
	
	if (cssClassList.indexOf(cssClass) >= 0)
	{
		var classArray = cssClassList.split(" ");
		var newClassList = new Array();
		for (x in classArray)
		{
			if (classArray[x] != cssClass)
			{
				if (classArray[x] != "")
				{
					newClassList.push(classArray[x]);
				}
			}
		}
		$(id).className = newClassList.join(" ");
		return true;
	}
	else
	{
		return false;
	}
}

function toggleCssClass(cssClass)
{
	if (hasCssClass(this, cssClass))
	{
		removeCssClass(element, cssClass);
	}
	else
	{
		addCssClass(element, cssClass);
	}
}

function toggleParentCssClass(element, cssClass)
{
	var targetElement = element.parentNode;
	
	if (hasCssClass(targetElement, cssClass))
	{
		removeCssClass(targetElement, cssClass);
	}
	else
	{
		addCssClass(targetElement, cssClass);
	}
}

function urlParser(uri)
{
	var urlPattern=new RegExp("^[a-z]{4,5}://[A-Za-z0-9.]+/{1}");
	
	this.raw = document.URL;
	this.server = urlPattern.exec(this.raw);
	this.subDirs = this.raw.replace(this.server,"").split("/");
	this.file = this.subDirs[this.subDirs.length - 1];
	
	this.match = function (query)
	{
		if (this.raw.indexOf(query) >= 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function urlParser(uri)
{
	var urlPattern=new RegExp("^[a-z]{4,5}://[A-Za-z0-9.]+/{1}");
	
	this.raw = uri;
	this.server = urlPattern.exec(this.raw);
	this.subDirs = this.raw.replace(this.server,"").split("/");
	this.file = this.subDirs[this.subDirs.length - 1];
	
	this.match = function (query)
	{
		if (this.raw.indexOf(query) >= 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function here()
{
	this.uri = new urlParser(document.URL);
	
	if (document.referrer != '')
	{
		this.ref = new urlParser(document.referrer);
		this.hasRef = true;
	}
	else
	{
		this.ref = "";
		this.hasRef = false;
	}
}

function changeVisibility(element)
{
	if (hasCssClass(element, "hide"))
	{
		removeCssClass(element, "hide");
	}
	else
	{
		addCssClass(element, "hide");
	}
}

function hideEl(element)
{
	addCssClass(element, "hide");
}

function showEl(element)
{
	removeCssClass(element, "hide");
}

function changeSelected(element)
{
	if (hasCssClass(element, "selected"))
	{
		removeCssClass(element, "selected");
	}
	else
	{
		addCssClass(element, "selected");
	}
}

function synchMenu(element)
{
	menu_main = element + "_main";
	menu_sub = element + "_sub";
	
	changeSelected(menu_main)
	changeVisibility(menu_sub);
}


// User Location Functions //

function getLocation()
{
	try
	{
		return unescape(readCookie("UserLocation"));
	}
	catch(e)
	{
		return null;
	}
}

function setLocation(here)
{
	if (testCookies())
	{
		createCookie("UserLocation",escape(here),1);
		return here;
	}
	else
	{
		return here;
	}
}

function getCountry()
{
	try
	{
		return unescape(readCookie("UserCountry"));
	}
	catch(e)
	{
		return null;
	}
}

function setCountry(here)
{
	if (testCookies())
	{
		createCookie("UserCountry",escape(here.replace(/ /g,"_")),1);
		return here;
	}
	else
	{
		return here;
	}
}

function getClientType()
{
	try
	{
		return unescape(readCookie("ClientType"));
	}
	catch(e)
	{
		return null;
	}
}

function setClientType(here)
{
	if (testCookies())
	{
		createCookie("ClientType",escape(here),1);
		return here;
	}
	else
	{
		return here;
	}
}

// Left Menu Functions //

function returnDocument()
{
    var file_name = document.location.href;
    var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
    return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function initMenu()
{
	var menu = document.getElementById("nav");
	var here = document.location.href; // May need to be document.URL when used on the server.

	if (menu != null)
	{
		var aList = menu.getElementsByTagName("a");
	
		for (anchor in aList)
		{
			if (aList[anchor].parentNode != undefined)
			{
	
				if (aList[anchor].parentNode.nodeName == "LI" && aList[anchor].parentNode.getElementsByTagName("ul").length == 0)
				{
					aList[anchor].className = "none";
				}
			}
	
			if (aList[anchor].href == here)
			{
				anchorParent = aList[anchor].parentNode;
	
				if (anchorParent.getElementsByTagName("ul").length == 0 && aList[anchor].className != "none")
				{
					aList[anchor].className = "closed";
				}
	
				while (anchorParent.nodeName != "DIV")
				{
					if (anchorParent.nodeName == "LI")
					{
						anchorParent.className = "open";
					}
	
					anchorParent = anchorParent.parentNode;
				}
			}
		}
	}
}


/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}


function loadXMLDoc(fileName)
{
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.validateOnParse = false;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("","",null);
	}
	else
	{
		alert('Your browser cannot handle this script');
	}
	xmlDoc.async = false;
	xmlDoc.load(fileName);
	
	return(xmlDoc);
}

function transformXML(xmlFile, xslFile)
{
	xml = loadXMLDoc(xmlFile);
	xsl = loadXMLDoc(xslFile);
	// code for IE
	if (window.ActiveXObject)
	{
		xml.validateOnParse = false;
		return xml.transformNode(xsl);
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		return xsltProcessor.transformToFragment(xml, document);
	}
}


/**
 * Create a new Document object. If no arguments are specified,
 * the document will be empty. If a root tag is specified, the document
 * will contain that single root tag. If the root tag has a namespace
 * prefix, the second argument must specify the URL that identifies the
 * namespace.
 */
var XML = new Object();
XML.newDocument = function(rootTagName, namespaceURL)
{
	if (!rootTagName) rootTagName = "";
	if (!namespaceURL) namespaceURL = "";
	if (document.implementation && document.implementation.createDocument)
	{
		// This is the W3C standard way to do it
		return document.implementation.createDocument(namespaceURL, rootTagName, null);
	}
	else
	{
		// This is the IE way to do it
		// Create an empty document as an ActiveX object
		// If there is no root element, this is all we have to do
		var doc = new ActiveXObject("MSXML2.DOMDocument.3.0");
		doc.validateOnParse = false;
		// If there is a root tag, initialize the document
		if (rootTagName)
		{
			// Look for a namespace prefix
			var prefix = "";
			var tagname = rootTagName;
			var p = rootTagName.indexOf(':');
			if (p != -1) {
			prefix = rootTagName.substring(0, p);
			tagname = rootTagName.substring(p+1);
		}
		// If we have a namespace, we must have a namespace prefix
		// If we don't have a namespace, we discard any prefix
		if (namespaceURL)
		{
			if (!prefix) prefix = "a0"; // What Firefox uses
		}
		else prefix = "";
		// Create the root element (with optional namespace) as a
		// string of text
		var text = "<" + (prefix?(prefix+":"):"") +  tagname +
			(namespaceURL
				?(" xmlns:" + prefix + '="' + namespaceURL +'"')
				:"") +
			"/>";
		// And parse that text into the empty document
		doc.loadXML(text);
		}
		return doc;
	}
};

/**
 * Synchronously load the XML document at the specified URL and
 * return it as a Document object
 */
XML.load = function(url) {
	// Create a new document with the previously defined function
	var xmldoc = XML.newDocument();
	xmldoc.async = false;  // We want to load synchronously
	xmldoc.load(url);      // Load and parse
	return xmldoc;         // Return the document
};

/**
 * Asynchronously load and parse an XML document from the specified URL.
 * When the document is ready, pass it to the specified callback function.
 * This function returns immediately with no return value.
 */
XML.loadAsync = function(url) {
	var xmldoc = XML.newDocument();
	// If we created the XML document using createDocument, use
	// onload to determine when it is loaded
	if (document.implementation && document.implementation.createDocument) {
		xmldoc.onload = function() { callback(xmldoc); };
	}
	// Otherwise, use onreadystatechange as with XMLHttpRequest
	else {
		xmldoc.onreadystatechange = function() {
			if (xmldoc.readyState == 4) callback(xmldoc);
		};
	}
	// Now go start the download and parsing
	xmldoc.load(url);
};


// Content Timer
function Timer()
{
	this.expires = new Date();
	this.today = new Date();
	this.linkedObject = new Object;
	
	//Pass a string formatted '[month]/[day]/[4 digit year]'
	this.set = function(strDate)
	{
		var datePattern=new RegExp("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]");
		if (!datePattern.test(strDate))
		{
			return;
		}
		
		arrDate = strDate.split("/");
		numPattern = new RegExp(/^0[1-9]/);
		
		for(j=0;j<arrDate.length;j++)
		{
			if (numPattern.test(arrDate[j]))
				arrDate[j] = arrDate[j].match(numPattern)[0].substr(1);
		}
		
		iMonth = parseInt(arrDate[0]) - 1;
		iDay = parseInt(arrDate[1]);
		iYear = parseInt(arrDate[2]);
		
		var numberPattern = /^0[1-9]/;
		
		this.expires.setFullYear(iYear,iMonth,iDay);
	}
	
	this.isExpired = function()
	{
		if (this.expires < this.today)
		{
			return true;
		}
		else
			return false;
	}
	
	this.expire = function(domObject)
	{
		myDOM = $(domObject);
		
		if (myDOM == null)
			return false;
		
		if (this.isExpired())
		{
			myDOM.style.display = "none";
			return true;
		}
		else
			return false;
	}
}

function expireEventTable(domTable)
{
	if ($(domTable) == null || $(domTable).nodeName.toUpperCase() != "TABLE")
		return false;
	
	var eventRows = $(domTable).rows;
	var eventTimer = new Array;
	
	for (i=0;i<eventRows.length;i++)
	{
		if (eventRows[i].title)
		{
			eventTimer[i] = new Timer();
			eventTimer[i].set(eventRows[i].title);
			if (eventTimer[i].expire(eventRows[i]))
			{
				$(domTable).deleteRow(i);
				i = i - 1;
			}
			else if (isEven(i))
				eventRows[i].className = "bggray1";
		}
	}
	
	return true;
}

function expireEvents()
{
	var eventTable = Object;
	eventTable = document.getElementById("EventTable");
	
	eventTable.style.visibility = "hidden";
	
	if (expireEventTable(eventTable))
		eventTable.style.visibility = "visible";
}


// Table Functions
function isEven(num) {
	return !(num % 2);
}

// Javascript OnLoader
function addLoadEvent(func)
{
	var oldonload = window.onload; 
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{ 
		window.onload = function()
		{ 
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(initMenu);
//window.onload = initMenu;



//---------Eugene Galper added (copied it from navigation.js to fix region section country dropdown script ------ *************

function gotocountry()
{
	var URL = document.regiondropdown.site.options[document.regiondropdown.site.selectedIndex].value;
	var myCountry = document.regiondropdown.site.options[document.regiondropdown.site.selectedIndex].innerHTML;
	
	setCountry(myCountry);
	
	window.location.href = URL;
}









