//startsWith function
String.prototype.startsWith = function(str) {return (this.match("^" + str) ==str) }
//endsWith function
String.prototype.endsWith = function(str) {return (this.match(str + "$") ==str) }

//Menu
function LoadMenu() {
	if (document.getElementById("nav") != undefined)
	{
		if (document.all && document.getElementById) {
			navRoot = document.getElementById("nav");
			for (i=0; i<navRoot.childNodes.length; i++)
			{ 
				node = navRoot.childNodes[i];
			   if (node.nodeName=="li" || node.nodeName=="LI")
				{
					node.onmouseover=function() {this.className+=" over";};
					node.onmouseout=function() {this.className=this.className.replace(" over", "");};
				}
			}
		}
	}
}

//footer
function LoadFooter() {
	if (document.getElementById("footer") != undefined)
	{
		var scrollh = window.pageYOffset || document.documentElement.scrollHeight || document.body.scrollHeight;
		var windowh = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		var height = scrollh - windowh
		if (height <= 0)
		{
			document.getElementById("footer").style.position = "absolute";
			document.getElementById("footer").style.bottom = "0px";
		}
		else
		{
			document.getElementById("footer").style.bottom = "0px";
		}
	}
}

//Show message
function showmsg(htmlmsg,tag)
{
	var imgName;
	if (tag=='U')
	{
		imgName = "MsgError.gif";
		htmlmsg = "Oops!! " + htmlmsg;
	}
	else if (tag=='S')
	{
		imgName = "MsgError.gif";
	}
	else if (tag=='D')
	{
		imgName = "MsgDone.gif";
	}
	if (htmlmsg.length > 150)
	{
		document.getElementById("divErrMsg").style.height = "100%";
	}
	//document.body.className = "modalBackground";
	document.getElementById("tblmsg").style.backgroundImage = "url('/imgs/eJCom_1431/" + imgName + "')";
	document.getElementById("tblmsg").style.width = "425px";
	document.getElementById("tblmsg").style.height = "272px";
	document.getElementById("tblmsg").style.backgroundRepeat = "no-repeat";
	document.getElementById("tblmsg").style.backgroundPosition = "center top";
	
	document.getElementById("Footer1_showmsg").style.position = "absolute";
	document.getElementById("Footer1_showmsg").style.left = (document.documentElement.offsetWidth /2) - (425/2);
	document.getElementById("Footer1_showmsg").style.top = (document.documentElement.offsetHeight /2) - (272/2);
	document.getElementById("Footer1_showmsg").style.display = "block";
	document.getElementById("divErrMsg").innerHTML = htmlmsg;
}


//HideMsg
function hidemsg()
{
	ClearLabel();	
	//Show Msg
	if (document.getElementById("Footer1_showmsg") != undefined)
	{
		document.getElementById("Footer1_showmsg").style.display = "none";
	}

	//div loading
	if (document.getElementById("Footer1_divLoading") != undefined)
	{
		document.getElementById("Footer1_divLoading").style.display = "none";
	}
	
	//Social list alert
	if (document.getElementById('SocialListPopup')!= undefined)
	{
		document.getElementById("SocialListPopup").style.display = "none";
	}
}

//Capture Key
function CaptureKey()
{ 
	var c = document.layers ? event.which
	: document.all ? event.keyCode
	: event.keyCode;	//27 = esc key	//32 = space key  //13 = entered
	if (c == 27 || c == 32 || c ==13)  
	{
		hidemsg();
	}
 }

//Scroll Image
function ScrollImage()
{
	//div loading
	if (document.getElementById("Footer1_divLoading") != undefined)
	{
		document.getElementById("Footer1_divLoading").style.top = document.documentElement.scrollTop + 300;
	}

	//Show Msg
	if (document.getElementById("Footer1_showmsg") != undefined)
	{
		document.getElementById("Footer1_showmsg").style.top = document.documentElement.scrollTop + 300;
	}
}

//ChangeBtnText
function ChangeBtnText(cntrl,text,tf)
{
	cntrl.value = text;
}


//Open newWindow
function openWindow(url)
{
	window.open(url,'Mywin', 'status=yes,toolbar=no,menubar=no,resizable=yes,resize=yes,scrollbars=yes, height=600,width=700',false);
	window.focus();
}

//Check Length
function CheckLength(txt,lbl,MaxChar)
{
	if(txt.value.length > (MaxChar))
	{
		var cont = txt.value;
		txt.value = cont.substring(0,(MaxChar));
		return false;
	}
	var a
	if (txt.value.length <= MaxChar)
	{
		a = MaxChar - parseInt(txt.value.length)
		lbl.innerHTML = a
	}
	else
	{
		a = MaxChar - parseInt(txt.value.length)
		lbl.innerHTML = a
		return false;
	}
}

//CheckAll chkbox
function CheckAll(gridID,chkbox)
{
	for (var i=0;i<document.Form1.elements.length;i++)
	{
		var e = document.Form1.elements[i];
		
		if ((e.name != 'checkall') && (e.type=='checkbox') && (e.id.toUpperCase().startsWith(gridID.toUpperCase())) )
		{
			e.checked = chkbox.checked;
			HighlightRow(e);
		}	
	}
}

function CheckAll1()
{
	for (var i=0;i<document.Form1.elements.length;i++)
	{
		var e = document.Form1.elements[i];
		if ((e.name != 'checkall') && (e.type=='checkbox'))
		{
			e.checked = document.Form1.checkall.checked;
			HighlightRow(e);
		}	
	}
}

//HighlightRow
var oldclass;
function HighlightRow(chk)	
{	
	if (chk.checked==true)
	{
		oldclass = chk.parentNode.parentNode.className;
		chk.parentNode.parentNode.className='dgSelect';
	}
	else
	{
		chk.parentNode.parentNode.className=oldclass;
	}
}

//ClearMsg
function ClearMsg()
{
	if(document.getElementById('lblMsg') != undefined || document.getElementById('lblmsg') != undefined)
	{
		setInterval("ClearLabel()",60000);	
	}
}
function ClearLabel()
{
	if(document.getElementById('lblMsg') != undefined)
	{
		document.getElementById('lblMsg').innerHTML = "";
	}
	if(document.getElementById('lblmsg') != undefined)
	{
		document.getElementById('lblmsg').innerHTML = "";
	}
}

//Window Functions
window.document.body.defaultStatus=document.title;
window.onload = function() {LoadMenu(); ClearMsg();};
window.onscroll = function() {ScrollImage();};
window.document.onkeypress = function() {CaptureKey();};