var IMAGE_PATH = "/images";
var Errpopup = true;

var tipStyle = new Array("white","#5BA0E3","Verdana","8pt","");
var errStyle = new Array("white","#5BA0E3","Verdana","8pt","");

function showError(id, msg, title)
{
	if(!Errpopup) // tht means do not show popup and donot focus.
		return false;
	var version = navigator.appVersion;
	var index = version.indexOf('MSIE') + 5;
	var ver = version.substr(index, 3);
	var browser = navigator.appName;

	var fontSize = '10pt';

	if ( browser == "Microsoft Internet Explorer")
	{
		var userAgent = navigator.userAgent;
		if ( userAgent.indexOf("Opera") >= 0)
			browser = "Opera";

		if(ver >= 5.5)
			fontSize = '8pt';
	}
	// uses errStyle that set in the page top;

	id.focus();

	if (title == null || title == "")
			title = "Invalid data";

	image = "<TABLE BORDER=0><TR><TD><IMG style='margin:0px' src='" + IMAGE_PATH + "/small/info.gif'></TD>";
	title = "<TD style='color:white;font-size:"+ fontSize + "'><b>" + title + "</b></TD></TR>";
	msg = "<TR><TD colspan=2 align=justify style='color:"+errStyle[0]+";background-color:"+errStyle[1]+";font-family:"+errStyle[2]+";font-size:"+errStyle[3]+";font-weight:"+errStyle[4]+";padding-left:10px;padding-right:10px'>" + msg + "</TD></TR></TABLE>";

	if((ver >= 5.5)  && (browser == "Microsoft Internet Explorer"))
	{
		var oPopup = window.createPopup();
		var oPopBody = oPopup.document.body;

		oPopBody.style.color = errStyle[0];
		oPopBody.style.backgroundColor = errStyle[1];
		oPopBody.style.border = "solid white 1px";
		oPopBody.style.margin = "1px";
		oPopBody.style.fontFamily = errStyle[2];
		oPopBody.style.fontSize = errStyle[3];
		oPopBody.style.fontWeight = errStyle[4];

		oPopBody.innerHTML = image + title + msg;
		oPopup.show(id.offsetWidth - 10, 10, 260, 100, id);
		var realHeight = oPopBody.scrollHeight + 10;
		oPopup.show(id.offsetWidth - 10, 10, 260, realHeight, id);
	}
	else
	{
		if (timer)
			{
				clearTimeout(timer);
				timer = false;
			}
		err = document.getElementById("popErr");

		btable = "<TABLE style='border:solid white 1px;margin:1px;background-color:"+errStyle[1]+"'><TR><TD>";
		endbtable = "</TD></TR></TABLE>";
		tempid = id;
		posx = 0;
		posy = 0;

		while (tempid)
		{
			posx += tempid.offsetLeft;
			posy += tempid.offsetTop;
			tempid = tempid.offsetParent;
		}


		err.innerHTML = btable + image + title + msg + endbtable;
		err.style.left= posx+ id.offsetWidth - 10;
		err.style.top = posy+10;
		err.style.visibility = "visible";

		timer = setTimeout("hideErr()",5000);
	}

	return false;
}

function hideErr()
{
	err = document.getElementById("popErr");
	err.style.visibility = "hidden";
}

function trimString(str)
{
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function chkNumeric(number)
{
	var checkOK = "0123456789"; // only allow 0-9 be entered

	var allValid = true;

	for (i = 0;  i < number.length;  i++)
	{
		ch = number.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;

		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}

	}

	return (allValid);
}

function chkDecimalNumeric(number)
{
	var checkOK = "0123456789."; // only allow 0-9 be entered

	var allValid = true;
	var isDecimal = false;

	for (i = 0;  i < number.length;  i++)
	{
		ch = number.charAt(i);

		//check if there are more then 1 dot
		if(ch == ".")
		{
			if(isDecimal == true)
			{
				allValid = false;
				break;
			}

			isDecimal = true;
		}

		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;

		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}

	}

	return (allValid);
}


function JSconfirm(msg)
{
	if (window.showModalDialog && showModalDlg)
	{
		var res;

		res = window.showModalDialog("/scripts/dialogs/confirmdialog.php?msg="+msg+"&title="+E_JS_CONFIRMTITLE+"&yes="+E_JS_YES+"&no="+E_JS_NO,"","dialogWidth:420px; dialogHeight:140px; scroll:no; status:no;");
		return (res != null);
	}
	else
		return confirm(msg);
}

function goBack()
{
	document.backfrm.submit();
}
function submit(action)
{
	document.accountfrm.ACTION.value=action;
	document.accountfrm.submit();
}

var c_ptype = "1";
function showPackageDetails( ptype ) {
	var divPDet = document.getElementById('packDet_' + ptype);
	var divPDetSel = document.getElementById('packDet_' + c_ptype);
	divPDetSel.style.display = 'none';
	divPDet.style.display = 'block';
	c_ptype = ptype;
}


function showTip(msg,id)
{

	var version = navigator.appVersion;
	var index = version.indexOf('MSIE') + 5;
	var ver = version.substr(index, 3);
	var browser = navigator.appName;

	var fontSize = '10pt';

	if ( browser == "Microsoft Internet Explorer")
	{
		var userAgent = navigator.userAgent;
		if ( userAgent.indexOf("Opera") >= 0)
			browser = "Opera";

		if(ver >= 5.5)
			fontSize = '8pt';
	}
	// uses tipStyle set in the page top;

	title = "<TD style='color:black;font-size:"+ fontSize + "'><B>" + TT_JS_QUICKHELP + "</B></TD></TR>";
	image = "<TABLE BORDER=0 width=250px><TR><TD><IMG style='margin:0px' src='" + IMAGE_PATH + "/common/info.gif'></TD>";
	msg = "<TR><TD colspan=2 align=justify style='color:"+tipStyle[0]+";background-color:"+tipStyle[1]+";font-family:"+tipStyle[2]+";font-size:"+tipStyle[3]+";font-weight:"+tipStyle[4]+";padding-left:30px;padding-right:10px'>" + msg + "</TD></TR></TABLE>";


	if((ver >= 5.5) && (browser == "Microsoft Internet Explorer"))
	{

		var tipPopup = window.createPopup();
		var tipPopBody = tipPopup.document.body;

		tipPopBody.style.color = tipStyle[0];
		tipPopBody.style.backgroundColor = tipStyle[1];
		tipPopBody.style.border = "solid black 1px";
		tipPopBody.style.margin = "1px";
		tipPopBody.style.fontFamily = tipStyle[2];
		tipPopBody.style.fontSize = tipStyle[3];
		tipPopBody.style.fontWeight = tipStyle[4];

		tipPopBody.innerHTML = image + title + msg;

		tipPopup.show(0 , -95, 250, 0, id);
		var realHeight = tipPopBody.scrollHeight + 10;
		poppedTip = tipPopup;
		tipPopup.show(75, 25, 250, realHeight, id);
	}
	else
	{
		tip = document.getElementById("popTip");

		btable = "<TABLE style='border:solid white 1px;margin:1px;background-color:"+tipStyle[1]+"'><TR><TD>";
		endbtable = "</TD></TR></TABLE>";
		tempid = id;
		posx = 0;
		posy = 0;

		while (tempid)
		{
			posx += tempid.offsetLeft;
			posy += tempid.offsetTop;
			tempid = tempid.offsetParent;
		}
		tip.innerHTML = btable + image + title + msg + endbtable;

		tip.style.left= posx-0;
		tip.style.top = posy+25;

		tip.style.visibility = "visible";
	}
	return true;
}


function hideTip()
{
	var version = navigator.appVersion;
	var index = version.indexOf('MSIE') + 5;
	var ver = version.substr(index, 3);
	var browser = navigator.appName;

	if ( browser == "Microsoft Internet Explorer")
	{
		var userAgent = navigator.userAgent;
		if ( userAgent.indexOf("Opera") >= 0)
			browser = "Opera";
	}

	if((ver >= 5.5) && (browser == "Microsoft Internet Explorer"))
	{
		if (poppedTip)
		{
			poppedTip.hide();
			poppedTip = false;
		}
	}
	else
	{
		tip = document.getElementById("popTip");
		tip.innerHTML="";
		tip.style.visilbility = "hidden";
	}
}
