/*
	Name:		Global JS Functions
	File:		/js/global.js
	Version:	2009-07-14
----------------------------------------------- */

/*	Init
	- Called on all pages
----------------------------------------------- */
function init() {
	// unobtrusive JS class
	document.body.className = "hasJS loading";
	window.addEvent('domready', function() {
		new plinth();
		new tables();
		if($('siteMap')){
		new siteMap('siteMap','siteMapTrigger');
		}
		new confirm(); 
			
		Cufon.replace('h1, h2, .plinth h3, .existingcustomers h3, table.vertical th, td.lrg, caption, a.tabLinkTitle');
		// unobtrusive JS class
		document.body.className = "hasJS domReady";			
		
		// new window links
		var blankLinks = $$('a[rel=blank]');
		blankLinks.set('target','_blank');
		
		// lists
		$$('ul li:first-child').addClass('first');
		$$('ul li:last-child').addClass('last');
		
		// sub navigation
		var navSecondary = $$('.navsecondary');
		var navSecondarySub = navSecondary.getElement('ul ul');
		if(navSecondarySub[0]!=null) {
			var selected = navSecondary.getElement('li.selected');
			selected.addClass('expanded');
		}

		//If not an app form make it not https
		if (!CheckApp()){
			//Replace https with http:// if necessary
			var myUrl = document.location.href;
			myUrl = myUrl.replace(new RegExp(/^https\:\/\//i),"http://");
			if (myUrl != document.location.href) {
				window.location = myUrl;
			}
		}
		
	});

	
	
}




/*	getUrlKey
	- Function to get parts of urls
----------------------------------------------- */
function $getUrlKey(key, url) {
    if (arguments.length < 2) url = location.href;
    if (arguments.length > 0 && key != "") {
        if (key == "#") {
            var regex = new RegExp("[#]([^$]*)");
        } else if (key == "?") {
            var regex = new RegExp("[?]([^#$]*)");
        } else {
            var regex = new RegExp("[?&]" + key + "=([^&#]*)");
        }
        var results = regex.exec(url);
        return (results == null) ? "": results[1];
    } else {
        url = url.split("?");
        var results = {};
        if (url.length > 1) {
            url = url[1].split("#");
            if (url.length > 1) results["hash"] = url[1];
            url[0].split("&").each(function(item, index) {
                item = item.split("=");
                results[item[0]] = item[1];
            });
        }
        return results;
    }
};

/*	RTeKnowledge
----------------------------------------------- */
function RTeKnowledge(url) {
	winHeight = 460;
	winWidth = 640;
	winTop = (screen.height/2) - (winHeight/2)
	winLeft = (screen.width/2) - (winWidth/2)
	features = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height=' + winHeight + ',width=' + winWidth + ',top=' + winTop+',left=' + winLeft;
	myWindow = window.open('https://' + url , 'eKnowledge', features);
 };
 
function CheckApp() {
	//Check to see if page is an application form...
	if ($('FDC_APPLICATION_NAME')){
		//Application
		return true;		
	}
	else
	{
	    //Not an Application
	    return false;
	}	
};

function popitup(url) {
	var newwindow = window.open(url,'name','status=yes,width=790,height=577');
	if(window.focus){ newwindow.focus() }
	return false;
};