if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement) {
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) {
		switch (where) {
			case 'beforeBegin':
				this.parentNode.insertBefore(parsedNode,this); break;
			case 'afterBegin':
				this.insertBefore(parsedNode,this.firstChild); break;
			case 'beforeEnd':
				this.appendChild(parsedNode); break;
			case 'afterEnd':
				if (this.nextSibling)
					this.parentNode.insertBefore(parsedNode,this.nextSibling);
				else 
					this.parentNode.appendChild(parsedNode);
				break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}
}
var dimid=null;
if (window.ScriptPath + "" == "undefined") ScriptPath="";
function showHide(id,flag) { 
	obj=document.getElementById(id);  
	if (obj==null)        
		return obj;   
	if (flag==null)        
		flag=(obj.style.display!="");   
	if (flag)      
		obj.style.display="";   
	else    
		obj.style.display="none"; 
	return obj;
}
function showHideContent(oimg,txt,id) {
	var obj=showHide(txt+id); 
	if (obj!=null) {  
		otd=obj.parentNode.parentNode.childNodes[0]; 
		if (otd.tagName==null)   
			otd=obj.parentNode.parentNode.childNodes[1]; 
		oimg=otd.childNodes[0]; 
	} 
	if ((oimg!=null) && (oimg.tagName.toUpperCase()=="IMG")) {  
		if (obj.style.display=="")
			nsrc=oimg.src.replace("rightarrow.gif","downarrow.gif");
		else if (obj.style.display=="none")   
			nsrc=oimg.src.replace("downarrow.gif","rightarrow.gif");
		oimg.src=nsrc;
	}
}
function switchDim(obj,flag) {
	if (flag==null)
		flag=1;
	var stron=flag==1?"_on":"";
	cbck=obj.background;
	bgioff="url("+ScriptPath+"../images/menu_dim.gif)";
	bgion="url("+ScriptPath+"../images/menu_dim_on.gif)";
	oanc=obj.childNodes[obj.childNodes.length-1];
	if (!oanc.tagName) {
		if (obj.childNodes.length>=2)
			oanc=obj.childNodes[obj.childNodes.length-2];
	}
	if (oanc.tagName && (oanc.className.toLowerCase().search('menu_dim')>=0 || (cbck && cbck.toLowerCase().search('menu_dim')>=0))) {
		if (oanc.tagName)
			oanc.className="menu_dim"+stron;
		obj.className="menu_dim"+stron;
		if (stron=="")
			nbck=bgioff;
		else
			nbck=bgion;
		obj.style.backgroundImage=nbck;//"http://domx2/sunfishcm/ecms3upload/ecms/sites/trimegah/library/images/menu_dim"+stron+".gif";  
	}
	else  {
		if (stron=="")
			nbck=bgioff.replace("menu_dim","menu_sub");
		else
			nbck=bgion.replace("menu_dim","menu_sub");
		obj.style.backgroundImage=nbck;//"http://domx2/sunfishcm/ecms3upload/ecms/sites/trimegah/library/images/menu_sub"+stron+".gif"; 
	}
}
function getOpenContent(idsub) {  
	var sparam=location.search;
	if (idsub!=null) {  
		otd=document.getElementById('dimMenu_'+idsub);  
		if (otd!=null)    {
			if (dimid!=null) {
				switchDim(dimid,0);
			}
			switchDim(otd)
			dimid=otd;
		}
	} 
	if (sparam.length>1) {    
		sparam=sparam.slice(1);    
		var vparam=sparam.split("&");    
		for (i=0;i<vparam.length;i++) {      
			nparam=vparam[i].split("=");      
			if (nparam[0].toLowerCase()=="def") {        
				showHideContent(null,'hdnContent_',nparam[1]);
				break;      
			}    
		}  
	}
}
function openStockInfo(theURL,isdelay) {
	if (isdelay!=null && isdelay==1) {
		setTimeout("openStockInfo('"+theURL+"')",1000);
		return;
	}
	frName="frStock";
	ofr=document.getElementById(frName);
	if (ofr==null)
		ofr=document.createElement("IFRAME");
	with (ofr.style) {
		width="620";
		height="220";
		display="none";
	}
	ofr.name=frName;
	ofr.id=frName;
	document.body.appendChild(ofr);
	setTimeout("frames[frames.length-1].name='"+frName+"';",1000);
	ofr.src=theURL;
}
function reloadMenu() {
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='HM_Arrays.js' TYPE='text/javascript'><\/SCR" + "IPT>");
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='"+ScriptPath+"HM_Script"+ HM_BrowserString +".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}
function additionalNews(id,mnid) {
	obj=document.getElementById(id);
	if (obj!=null) {
		obj.onmouseover=function(event) {popUp("elMenu"+mnid,event,this);}//popUp("elMenu"+mnid,event,this);
		obj.onmouseout=function(event) {popDown("elMenu"+mnid,event);}
		menudelay=false;
//		setTimeout("reloadMenu();",1000);
	}
}
function setInpDate(theform,cdate) {
	var sday=1;
		eday=0;
	theform.frmInputDate;
	arrDIM=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	cyear=theform.selYear.options[theform.selYear.selectedIndex].value;
	cmonth=theform.selMonth.selectedIndex;
	inpDate=theform.selDate;
	if (inpDate.selectedIndex>0)
		cday=inpDate.selectedIndex;
	else
		cday=0;
	if (cdate!=null) {
		sdate=cdate.split("/");
		if (sdate.length==3) {
			cmonth=sdate[0];
			cday=sdate[1];
			cyear=sdate[2];
		}
	}
	if (cmonth>0) {
		sday=1;
		if (cmonth==2)
			eday=(cyear%400==0)||((cyear%4==0)&&(cyear%100!=0))?29:28;
		else
			eday=arrDIM[cmonth-1];
	}
	inpDate.options.length=1;
	nopt=new Option("Any","");
	inpDate.options[0]=nopt;
	for (i=sday;i<=eday;i++) {
		nopt=new Option(i,i);
		inpDate.options.length++;
		inpDate.options[i]=nopt;
	}
	if (cday<=eday)
		inpDate.selectedIndex=cday;
	theform.selMonth.selectedIndex=cmonth;
	theform.selYear.selectedIndex=cyear-theform.selYear.options[0].value;
}
function submitDate(theform) {
	theform.target="frStock";
	theform.submit();
}
function GetXmlHttpObject() {
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
function stateChanged(plcHolder) { 
	if (xmlHttp.readyState==4) {
		document.getElementById(plcHolder).innerHTML=xmlHttp.responseText;
		document.body.style.cursor="default";
	}
}
function getDynInfo(theURL,plcHolder,isdelay,theform) {
	if (plcHolder==null)
		plcHolder="DYN_CONTENT";
	var ajaxMethod="GET";
		ajaxParam=new Array();
	if (theform!=null) {
		ajaxMethod="POST";
		for (i=0;i<theform.elements.length;i++) {
			elm=theform.elements[i];
			if (elm.type.toUpperCase()=="TEXT")
				elmval=elm.value;
			else if (elm.type.toUpperCase()=="HIDDEN")
				elmval=elm.value;
			else if (elm.type.toUpperCase()=="PASSWORD")
				elmval=elm.value;
			else if (elm.type.toUpperCase()=="SELECT-ONE")
				elmval=elm.options[elm.selectedIndex].value;
			else if (elm.type.toUpperCase()=="RADIO" && elm.checked)
				elmval=elm.value;
			else if (elm.type.toUpperCase()=="CHECKBOX" && elm.checked)
				elmval=elm.value;
			else
				elmval="";
			ajaxParam.push(theform.elements[i].name+"="+elmval);
		}
	}
	divTD=document.getElementById(plcHolder);
	if (theURL.length==0) { 
		divTD.innerHTML="";
	  	return;
	}
	if (isdelay!=null && isdelay==1) {
		setTimeout("getDynInfo('"+theURL+"','"+plcHolder+"')",1000);
		return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX");
	  return;
	  } 
/*	var url="gethint.asp";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();*/
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
//			divTD.innerHTML=xmlHttp.responseText;
			sethtml(divTD,xmlHttp.responseText); 
			document.body.style.cursor="default";
		}
	}
//	xmlHttp.onrequestend=OnEndRequest;
	if (theURL.search("&ajaxcall=")<0)
		theURL+="&ajaxcall=yes";
	xmlHttp.open(ajaxMethod,theURL,true);
	strParam=null;
	if (theform!=null) {
		strParam=ajaxParam.join("&");
		xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", strParam.length);
		xmlHttp.setRequestHeader("Connection", "close");
	}
	xmlHttp.send(strParam);
	divTD.innerHTML="<font color=\"white\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>";
	setTimeout("waitMessage('"+plcHolder+"','<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><center>Loading Content ...</center>')",500);
	document.body.style.cursor="wait";
	scURL=theURL.split("?");
	scQS=scURL[1].split("&");
	var ask="";
	for (i=0;i<scQS.length;i++) {
		scPrm=scQS[i].split("=");
		if (scPrm[0].toLowerCase()=="ask") {
			ask=scPrm[1];
			break;
		}
	}
	if (ask!="")
		getOpenContent(ask.toUpperCase());
}
function waitMessage(id,msg) {
	var obj=document.getElementById(id);
	var bre=new RegExp('\"',"gi");
	ntxt=obj.innerHTML.toLowerCase().replace(bre,"");
	if (obj!=null && ntxt=="<font color=white>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>") {
		obj.innerHTML=msg;
	}
}
function OnEndRequest(sender,args)
{                            
    alert("Microsoft Ajax has just finished updating the page!");      
}
function sethtml(obj,content)
{
    var search = content;//.toLowerCase();
		orgsearch = content;
    var script;
        adembed="";
	obj.innerHTML=content;//+javascript[^>]+
    while( script = search.match(/(<script[^>]*>\s*(<!--)?)/i))
    {
      search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
      if (!(endscript = search.match(/((-->)?\s*<\/script>)/i))) break;
      
      block = search.substr(0, search.indexOf(RegExp.$1));
      search = search.substring(block.length + RegExp.$1.length);
      
      var oScript = document.createElement('script');
	  if (block.substr(0,14).toUpperCase()=="CF_RUNCONTENT(") {
	  	adembed+=block.substr(15,block.length-18);
		block="";
	  }
	  if (block!="") {
      	oScript.text = block;
      	document.getElementsByTagName("head").item(0).appendChild(oScript);
	  }
    }
	if (adembed!="")
    	obj.insertAdjacentHTML("beforeEnd",adembed);
}
function validateSearch(theform,plcholder,condition,msg) {
	if (condition==null)
		condition=true;
	if (!condition) {
		alert(msg);
		return false;
	}
	else {
		getDynInfo(theform.action,plcholder,null,theform);
		return false;
	}
}
function validateForm(theform,plcholder,condition,msg) {
	if (condition==null)
		condition=true;
	if (!condition) {
		alert(msg);
		return false;
	}
	else {
		getDynInfo(theform.action,plcholder,null,theform);
		return false;
	}
}
function OpenReport(rpt){
	var win=window.open('http://www.trimegah.com/laporan/' + rpt,'report', 'tollbar=0,width=800,height=600');
	win.focus();
}
function BukaWin(urlnya)
{
	window.open('http://www.trimegah.com/' + urlnya, '_blank', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}