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

//////////////////////// color/// bg-color/// font/// fnt size // font style//
var tipStyle = new Array("black","#F2F2FF","Verdana","8pt","bold"); // define styles for tips
var errStyle = new Array("black","#F2F2FF","Verdana","8pt","bold"); // defile style for errors
var webtipStyle = new Array("black","#1E9FFF","Verdana","8pt","bold"); // defile style for web editor tips

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 = E_JS_INVALIDDATA;
	
	image = "<TABLE BORDER=0><TR><TD><IMG style='margin:0px' src='" + IMAGE_PATH + "/common/info.gif'></TD>";
	title = "<TD style='black: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 black 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 openNewWindow(theURL,winName,features) 
{
	return window.open(theURL,winName,features);
}

function submitFeedback(sid)
{
	openNewWindow("?ACTION=FEEDBACK&sid="+sid , "_feedback", "width=690,height=400");
}

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 showWebTip(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';
	}
	msg = "<TABLE BORDER=0 width=250px'><TR><TD colspan=2 align='center' style='color:"+webtipStyle[0]+";background-color:"+webtipStyle[1]+";font-family:"+webtipStyle[2]+";font-size:"+webtipStyle[3]+";font-weight:"+webtipStyle[4]+";padding-left:10px;padding-right:10px;text-align='center''>" + msg + "</TD></TR></TABLE>";
	
	if((ver >= 5.5) && (browser == "Microsoft Internet Explorer"))
	{
		var tipPopup = window.createPopup();
		var tipPopBody = tipPopup.document.body;
		
		tipPopBody.style.color = webtipStyle[0];
		tipPopBody.style.backgroundColor = webtipStyle[1];
		tipPopBody.style.border = "solid black 1px";
		tipPopBody.style.margin = "1px";
		tipPopBody.style.fontFamily = webtipStyle[2];
		tipPopBody.style.fontSize = webtipStyle[3];
		tipPopBody.style.fontWeight = webtipStyle[4];
		
		tipPopBody.innerHTML =  msg;
		
		tipPopup.show(0 , -60, 250, 0, id);
		var realHeight = tipPopBody.scrollHeight + 10;
		poppedTip = tipPopup;
		tipPopup.show(80, -60, 250, realHeight, id);
		
	}
	else
	{
		tip = document.getElementById("popTip");
		
		btable = "<TABLE style='border:solid white 1px;margin:1px;background-color:"+webtipStyle[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 + msg + endbtable;
		
		tip.style.left= posx+40;
		tip.style.top = posy+25;
		
		tip.style.visibility = "visible";
	}
	return true;
}

function showTipFocus(msg, id)
{
	id.focus();
	showTip(msg,id);
	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";
	}
}

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 JSinfoDialog(msg)
{
	if (window.showModalDialog && showModalDlg)
	{	
		var res;
		
		res = window.showModalDialog("scripts/dialogs/infoDialog.php?msg="+msg+"&title="+E_JS_CONFIRMTITLE+"&yes="+E_JS_OK,"","dialogWidth:420px; dialogHeight:120px; scroll:no; status:no;");
		return (res != null);
	}
	else
		return confirm(msg);
}

function returnmyacc() 
{
	document.returnbackform.submit();
}

function mainform(val,prj)
{
	f = document.backform;
	f.pcode.value = val;
	f.proName.value = prj;
	f.submit();
}

function submit(action)
{
	f = document.layoutfrm;
	f.ACTION.value = action;
	f.submit();
}

function ShowHelp(code,id,sid)
{
	var theURL = "index.php?ACTION=HELP&code=" + code + "&id=" + id + "&sid=" + sid;
	var features = "status=no,scrollbars=yes,height=410,width=640";
	temp = openNewWindow(theURL, "Help" + code , features);
	temp.focus();
}

function statusbarmsg(msg)
{
	window.status = msg;
}

function expand(divId)
{	
	div = document.getElementById(divId);
	img = document.getElementById('img' + divId);
	if (div.style.display != 'block')	//i.e it is none
	{
		div.style.display = 'block';
		img.src = '/images/g4l/common/minus.jpg';
	}
	else
	{
		div.style.display = 'none';
		img.src = '/images/g4l/common/plus.jpg';
	}
}

function goBack()
{
	document.backfrm.submit();
}


function submitGraphicsSection(val)
{		
	f = document.worktypefrm;
	
	if( val == 1 )
		f.ACTION.value = "LOGO";
	else if (val == 5 )
		f.ACTION.value = "ADDITIONALSERVICES";
		
	f.wid.value = val;
	f.submit();
}

function replace(s, t, u)
{
	var condition;
	
	do{
		condition = 1;
		i = s.indexOf(t);
		r = "";
		if (i == -1) return s;
		r += s.substring(0,i) + u;
		if ( i + t.length < s.length)
		{
			r += replace(s.substring(i + t.length, s.length), t, u);
			condition = 0;
		}
		s = r;
	}while (condition != 1);
	
	return s;
}

