/* JavaScript Document*/

nhPrefixCookie="_NAHL";

/*setTimeout(location.reload(true),3000);*/
var slideTimeOut=0;

function init(){
	//init all variable here, load on body onload
	setTimeout('location.reload(true)',10*60*1000);
	slideTimeOut=setInterval("setupSlideShow()",100);
	return true;
}

function isEmail( text )
{
	var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp( pattern );
	return regex.test( text );
}

function readCookie(name)

{

  var cookieValue = "";

  var search = nhPrefixCookie + name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}


/* Example:

/ writeCookie("myCookie", "my name", 24);

/ Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.*/

function writeCookie(name, value, hours)

{
  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = nhPrefixCookie + name + "=" + escape(value) + expire;

}

function setFrame(){
	var WidthScreen=document.body.clientWidth;
	var LeftWidth=0;
	var RightWidth=0;
	
	if(WidthScreen<980) 
		{document.getElementById("AdminContent").style.width="980px";}
	else
		{document.getElementById("AdminContent").style.width=WidthScreen+"px";}
		
	var adminLeft=document.getElementById("AdminLeftFrame");	
	if(adminLeft)
		{
			FixedLeft=adminLeft.style.width!="";
			LeftWidth=adminLeft.clientWidth;
		}
	else
		{
			FixedLeft=false;
		}
		
	var adminRight=document.getElementById("AdminRightFrame");
	if(adminRight)
		{
			FixedRight=(adminRight.style.width!="" && !FixedLeft);
		}
	else
		{
			FixedRight=false;
		}
		
	if(FixedLeft){
		(adminRight) ? adminRight.style.width=(WidthScreen-LeftWidth-40)+"px" : false;
	}

	if(FixedRight){
		(adminLeft) ? adminLeft.style.width=(WidthScreen-RightWidth-40)+"px" : false;
	}

}
/*page Numbering*/

function pageNumbering(pId,reff){
	var el=document.getElementById(pId);
	el.onclick=function(){pageNumbering.clicked(reff);}	
	el.onmouseover=function(){pageNumbering.mouseOver(el);}
	el.onmouseout=function(){pageNumbering.mouseOut(el);}
}

pageNumbering.clicked=function(reff){
	location.href=reff;
}

pageNumbering.mouseOver=function(el){
	el.className="page-number-hover";
}

pageNumbering.mouseOut=function(el){
	el.className="page-number";
}

function comboChange(el,src){
	if(src!="")	{location.href=src+el.value+".html";}
}

function srcdirecting(reffPage,inputName){
	var srcValue=new String(document.getElementById(inputName).value);
	
	srcValue=srcValue.replace(/\ /g,'+');
	srcValue=srcValue.replace(/\"\'/g,'');
	location.href=reffPage+"&q="+srcValue+"&startLimit=0&endLimit=10";
}


function getW(){
var w;
	if(document.innerWidth){ w=document.innerWidth;
	} else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
	} else if(document.body){ w=document.body.clientWidth; }
	return w;
}

function getH(){
var h;
	if(document.innerHeight){ h=document.innerHeight;
	} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
	} else if(document.body){ h=document.body.clientHeight; }
	return h;
}

function makeMasked(xWidth,xHeight,pageFrame){
	var theMaskBox=document.createElement("div");
	var fullMask=document.createElement("div");
	var buttonMask=document.createElement("div");
	maskLayer=document.body;

	(document.body.clientHeight>=getH()) ? nHeight=document.body.clientHeight : nHeight=getH();
	(document.body.clientWidth>=getW()) ? nWidth=document.body.clientWidth : nWidth=getW();

	with(fullMask){
		style.top="0px";
		style.left="0px";
		style.width="100%";
		style.height=nHeight+"px";
		id="fullMask";
		className="fullMask";
	}
	
	var topScrolled=getScrollXY();
	topScrolled=topScrolled[0];
	
	with(theMaskBox){
		style.width=xWidth+"px";
		style.height=xHeight+"px";
		style.left=((nWidth-xWidth)/2)+"px";
		style.top=(topScrolled+(nHeight-xHeight)/2)+"px";
		id='theMaskBox';
		className='whiteMask';
		innerHTML="<div class='buttonMask'>"+
				"<div id='btnClose' onclick='closeMask()' class='buttonClick'><strong>x</strong></div></div>"+
				"<div id='innerBox' class='innerBox' style='height:"+(xHeight-25)+"px;'>Mohon tunggu . . . .</div>";
	}
	
	maskLayer.appendChild(fullMask);
	maskLayer.appendChild(theMaskBox);
	OpenAddress(pageFrame,'innerBox');
}

function closeMask(){
	maskLayer.removeChild(document.getElementById('theMaskBox'));
	maskLayer.removeChild(document.getElementById('fullMask'));
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    /*Netscape compliant*/
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    /*DOM compliant*/
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    /*IE6 standards compliant mode*/
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function toolTip(){
}

function getElementsByClassName(className){
	var arr = new Array();
	var elems = document.getElementsByTagName("*");
	for(var i = 0; i < elems.length; i++)
		{
			var elem = elems[i];
			var id = elem.getAttribute("id");
			var cls = elem.getAttribute("class");
			if(cls == className){arr[arr.length] = id;}
		}
	return arr;
}

function _submit(valueAction){
	xForm=document.forms[0];
	el=document.createElement('input');
	with(el){
		name='actionButton';
		id='actionButton';
		value=valueAction;
	}
	
	xForm.insertBefore(el,xForm.lastChild);
	xForm.submit();
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
function blindLayer(pageReff,frWidth,frHeight){
	this.blindLayer=document.createElement("div");
	this.blindLayer.id="_blackMasked";
	this.blindLayer.innerHTML="&nbsp;";
	with(this.blindLayer.style){
		backgroundColor="#000000";opacity=0.8;filter="alpha(opacity='80')";top="0px";left="0px";
		zIndex=10000;position="absolute";height=getH()+"px";width=getW()+"px";
	}
	document.body.appendChild(this.blindLayer);
	(frWidth==null) ? frWidth=600 : true;(frHeight==null) ? frHeight=getH()-100 : true;
	
	this.frpage=document.createElement("div");
	this.frpage.id="_framePage";
	with(this.frpage.style){
		backgroundColor="#E1E1E1";border="1px solid #999999";height=frHeight+"px";top=((getH()-frHeight)/2)+"px";
		position="absolute";left=((getW()-frWidth)/2)+"px";width=frWidth+"px";zIndex=11000;
	}
	
	document.body.appendChild(this.frpage);var frPage=this.frpage;var blPage=this.blindLayer;
	this.blindLayer.onclick=function(){frPage.style.display="none";	blPage.style.display="none";}
}


function goSrc(page,indexPage){
	var srcText=document.getElementById('srcValue').value;
	if(indexPage==null)
		{
			location.href=page+"?&src="+srcText;
		}
	else
		{
			location.href=page+"?&index="+document.getElementById('yearVal').value+"/"+document.getElementById('monthVal').value+"/"+document.getElementById('dateVal').value;
		}
}

//for dropdown menu
function ItemMosOver(idName){
	if(!document.getElementById(idName)){return false;}
	document.getElementById(idName).style.display="block";
}

function ItemMosOut(idName){
	if(!document.getElementById(idName)){return false;}
	document.getElementById(idName).style.display="none";
}

//block screen
function blockScreen(blocked){
	var elBlock=document.getElementById("blockedScreeen");
	var innerBlock=document.getElementById("centerBlockScreen");
	if(elBlock && innerBlock){
		if(blocked==1)
			{
				elBlock.style.display="block";innerBlock.style.display="block";
			}
		else
			{
				elBlock.style.display="none";innerBlock.style.display="none";
			}
	}
}