
function OpenWindow(url, w, h, attr)
{
	var m_attr = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	var x,y;

	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	if (attr)
	{
		m_attr = attr;
	}	
	window.open(url, "", m_attr+",width="+w+",height="+h+",left="+Math.round((x-w)/2)+",top="+Math.round((y-h)/2));
}

function PreviewImage(imageid, w, h, autoresize)
{
	OpenWindow("/Forms/PreviewImage.aspx?imageid="+imageid+"&autoresize="+autoresize, w, h, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
}

function PrintPage() {
	var loc = location.href;
	if (loc.indexOf("#")>0) {
		loc = loc.substring(0, loc.indexOf("#"));
	}
	var pri = "?p=1";
	if (loc.indexOf("?")>0) {
		pri = "&p=1";
	}
	OpenWindow(loc+pri, 620, 400);
}

function SendPage(path, id) {
	var loc = path + "?pageid=" + id;
	OpenWindow(loc, 320, 280, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
}

function CheckForm(form)
{
	if (form.from.value == "" || form.to.value == "")
	{
		if (form.from.value == "")
		{
			document.getElementById('error1').style.display = "inline";
		}
		if (form.to.value == "")
		{
			document.getElementById('error2').style.display = "inline";
		}
		return false;
	}
	else
	{
		return true;
	}
}

function SetPostAction(val)
{
	var sUrl = val;
	if (sUrl.indexOf("/")<0) {
		sUrl = "/forms/"+sUrl;
	}
	if (sUrl.indexOf(".aspx")<0) {
		sUrl = sUrl + ".aspx";
	}
	//var ctl = document.all["postaction"];
	//ctl.value = val;
	document.forms[0].action = sUrl;
}

function doSearch(fld, target) 
{
	location.href= target + '?search=' + encodeURI(eval("document.forms[0]." + fld).value);
}


function doKeySearch(evt, fld, target) 
{	
	if (evt.keyCode==13) 
	{	
		window.document.forms[0].action = target + '?search=' + eval("document.forms[0]."+fld).value;	
		evt.returnValue = null;
		evt.cancelBubble = true;
		
		doSearch(fld, target);		
	}
	return false;
}

//=====================================
// Utilities
//=====================================

function QS(name) {
	var tmp = unescape( location.search.substring(1) );
	var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
	if ( i >= 0 ) {
		tmp = tmp.substring( name.length+i+1 );
		i = tmp.indexOf("&");
		return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
	}
	return("");
}

/* -----------------------------------
--------------------------------------
-----     Map region code       ------
--------------------------------------
----------------------------------- */

var mActiveArea = null;
var mActiveDiv = null;
var mActiveCountry = null;
var divActive = false;
var mTimer = null;
var IDtoClear = null;
var pngAlpha = false;
var pngNormal = false;

function SetActiveArea(id) {	
	if (id!=mActiveArea) {			
		if(IDtoClear != null)
		{				
			ClearMenus(IDtoClear);
		}			
		window.clearTimeout(mTimer);			
		HideAll();			
		var obj = document.getElementById(id);			
		//alert(obj);
		var amenu = menus[id];
		if (obj!=null && amenu!=null) {
			var topOffset = 97; // no. of pixels from top of browser to map
			var leftOffset = (document.body.clientWidth/2)-375; // no. of pixels from left side of browser to map
			obj.style.top = parseInt(amenu[0]) + topOffset;
			obj.style.left = parseInt(amenu[1]) + leftOffset;
			//var bgheight = (obj.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes.length*14 + 28);
			//obj.style.height = bgheight + "px";
			obj.style.display = "inline";				
			document.getElementById(id.substring(0,id.length-4) + "activemap").style.display = "inline";
			mActiveArea = id;
			mActiveDiv = id;
		}
	}
}

function ClearActiveArea(id) {
	mActiveDiv = null;
	mActiveArea = null;
	mTimer = window.setTimeout("ClearMenus('"+id+"')", 200);
	IDtoClear = id;
}

function ClearMenus(id) {	
	if (id!=mActiveDiv && id!=mActiveArea) {
		var obj = document.getElementById(id);
		if (obj!=null) {
			obj.style.display = "none";
			mActiveArea = null;
			document.getElementById(id.substring(0,id.length-4) + "activemap").style.display = "none";
			if (mActiveCountry != null)
			{
				ClearActiveCountry(mActiveCountry);
			}
		}
	}
	IDtoClear = null;
}

function SetActiveDiv(obj) {
	mActiveDiv = obj.id;
}

function ClearActiveDiv(obj) {
	mActiveDiv = null;
	mActiveArea = null;
	//ClearMenus(obj.id);
	mTimer = window.setTimeout("ClearMenus('"+obj.id+"')", 200);
	IDtoClear = obj.id;
}

function SetActiveCountry(id) {
	document.getElementById(id).style.display='inline';
	mActiveCountry = id;
}

function ClearActiveCountry(id) {
	document.getElementById(id).style.display = "none";
	mActiveCountry = null;
}