function popwin(url, width, height){
	var _width = screen.availWidth; 
	var _height = screen.availHeight; 
	var centered_width = 0;
	var centered_height = 0;	
	if (_width > width) centered_width = (_width - width) / 2;
	if (_height > height) centered_height = (_height - height) / 2;
	viewer = window.open(url,"viewer","top=" + centered_height + ",left=" + centered_width + ",status=yes,scrollbars=yes,menubar=no,resizable=yes,width=" + width + ",height=" + height);
	viewer.focus();
	return false;
}

function promptForProduct(default_val) {
	if ($('#apply_form select').val() == default_val)
		alert('Please select a product');

	return $('#apply_form select').val() != default_val;
}

function executeSearch(form) {
	popwin($(form).attr('action')+'?'+$(form).serialize(), 850, 600)
	return false;
}

window.tracking = {
	trackEvent : function(data) {
		_hbPageView(data.pageName, hbx.mlc);
	},
	setPopulationGroups : function(grps){
		try {
			_hbSet("seg", grps);
			_hbSend();
		}
		catch(e){
			if(window.console) {
				console.debug(e.message);
			}
		}
	},
	
    getMLC : function(mlcRoot) { 
        var mlc = mlcRoot;
        var mlcRx = new RegExp("^https?://[^/]+/([^\\.]*)");
        var mlcGrps = mlcRx.exec(document.location.href);

        if(mlcGrps != null && mlcGrps.length == 2) {
            mlc += "/" + mlcGrps[1].replace(/(_|-)/, "").toUpperCase();
        }

        return mlc;
    }
}

window.stateManager = {
		
	createCookie : function(name,value,days) {
		var expires;
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = ";expires=" + date.toGMTString();
		}
		else {
			expires = "";
		}
		document.cookie = name+"="+value+expires+"; path=/";
	},

	readCookie : function (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;
	},
	
	eraseCookie : function(name) {
		createCookie(name,"",-1);
	},
	
	getCurrentBookmark : function() {
		var str_url = new String(document.location.href);
		var ar = str_url.split(/#/);
		var bmrk = (ar.length > 1) ? ar[1] : null;
		return bmrk;
	}
}


function generateSIFR(id, txt, w, h, swf, link, offsetTop, textColour, textAlign, popwinWidth, popwinHeight) {
	if (textAlign == null) textAlign = "left";
	var so = new SWFObject(swf + "?" + id, id, w, h, "6", "transparent");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.addVariable("txt", escape(txt.replace("&amp;", "&")));
	so.addVariable("textalign", "left");
	so.addVariable("offsetTop", offsetTop);
	so.addVariable("textcolor", textColour);
	if(link != "") so.addVariable("link", link);
	so.addVariable("w", w);
	so.addVariable("h", h);
	if(popwinWidth != null && popwinHeight != null) {
		so.addVariable("popwin", true);
		so.addVariable("popwin_width", popwinWidth);
		so.addVariable("popwin_height", popwinHeight);
	}
	so.write("flashcontent_" + id);
}