// JavaScript Document
var ns4 = document.layers;

var ns6 = document.getElementById && !document.all;

var ie4 = document.all;

offsetX = 0;

offsetY = 20;

var toolTipSTYLE="filter:alpha(opacity=5);-moz-opacity:.05;opacity:.05;";

function initToolTips()

{
	
  if(ns4||ns6||ie4)

  {

    if(ns4) toolTipSTYLE = document.toolTipLayer;

    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;

    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else

    {

      toolTipSTYLE.visibility = "visible";

      toolTipSTYLE.display = "none";

    }

    document.onmousemove = moveToMouseLoc;

  }

}

function toolTip(msg, fg, bg)

{
  if(toolTip.arguments.length < 1) // hide

  {

    if(ns4) toolTipSTYLE.visibility = "hidden";

    else toolTipSTYLE.display = "none";

  }

  else // show

  {

    if(!fg) fg = "#777777";

    if(!bg) bg = "#FFFFFF";

    var content =

    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +

    '<table width="250" border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 

    '"><td align="left"><font face="sans-serif" color="' + fg +

    '" size="-2">&nbsp\;' + msg +

    '&nbsp\;</font></td></table></td></table>';
	
    if(ns4)

    {

      toolTipSTYLE.document.write(content);

      toolTipSTYLE.document.close();

      toolTipSTYLE.visibility = "visible";

    }

    if(ns6)

    {

      document.getElementById("toolTipLayer").innerHTML = content;

      toolTipSTYLE.display='block'

    }

    if(ie4)

    {

      document.all("toolTipLayer").innerHTML=content;

      toolTipSTYLE.display='block'

    }

  }

}

function moveToMouseLoc(e)

{

  if(ns4||ns6)

  {

    x = e.pageX;

    y = e.pageY;

  }

  else

  {

    x = event.x + document.body.scrollLeft;

    y = event.y + document.body.scrollTop;

  }
  if((x + offsetX + 250)>=document.body.clientWidth)
  	{
		toolTipSTYLE.left = x + offsetX - 250;
	}
else
	{
		toolTipSTYLE.left = x + offsetX;
	}

  toolTipSTYLE.top = y + offsetY;

  return true;

}

function isEmail( text )
{
	var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp( pattern );
	return regex.test( text );
}


//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 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 minLength(inputString,inputLength)

{
  return (inputString.length >= inputLength) ? true : false;
}  

function identical(input1,input2){
	return input1==input2;
}

function matching(input1,input2){
//	var pattern = "\\d-\\d";
//	alert(input2);
	var pattern =input2;
	var regex = new RegExp( pattern );
	return regex.test( input1 );
}

function ValidUserPass(input2){
	 var re = new RegExp("[\\W-]");
	  var m = re.exec(input2);
	  if (m != null) { //non character is match
		return false
	  } else {
		return true;
	  }
}

function SelectedItem(){
	oSelection=false;
	for(i=1;i<arguments.length;i++)
		{
			if(arguments[0]===arguments[i])
				{
					oSelection=true;
				}
		}
		
	return oSelection;
}

workSpaceChangeSize=function(){
	if(document.body.clientWidth<=1050){
		document.getElementById('mainContent').style.width='1050px';
		document.getElementById('headerIDForm').style.width='1050px';
		document.getElementById('headerMenuID').style.width='1040px';
		document.getElementById('AdminPanel').style.width='1050px';
	} 
	else
	{
		document.getElementById('mainContent').style.width='98%';	
		document.getElementById('headerIDForm').style.width='100%';
		document.getElementById('headerMenuID').style.width='100%';
		document.getElementById('AdminPanel').style.width='100%';
	}
	
	set_maxWidthLeft();
}

set_maxWidthLeft=function(){
	var maxSpace=document.getElementById('innerContent').clientWidth;
	
	!(document.getElementById('rightFrameAdmin')) ? rightWidth=0 : rightWidth=document.getElementById('rightFrameAdmin').clientWidth+20;
	
	if(!document.getElementById('leftFrameAdmin')){return false;}
	
	document.getElementById('leftFrameAdmin').style.width=maxSpace-rightWidth;
}


//try with ajax//
function getHttpRequest(){
	var http_request=false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	return http_request;
}

function OpenAddress(oAddress,oLayer){
		var xmlHttp=getHttpRequest();
				
		if(!xmlHttp){return false;}
		
		var url = oAddress;
		xmlHttp.open("GET", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", url.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.onreadystatechange = function() 
			{
				if(xmlHttp.readyState == 4 ) 
					{
						var result = xmlHttp.responseText;
						try
							{
								document.getElementById(oLayer).innerHTML="";	
								document.getElementById(oLayer).innerHTML = result;
							}
						catch (e)
							{
								document.getElementById(oLayer).innerText = "";
								var ElementBaru = document.createElement('div');
								ElementBaru.innerHTML = result;
								document.getElementById(oLayer).appendChild(ElementBaru);								
							}
						
					}
			}
		xmlHttp.send(null);	
}


/*validating data*/

function validateCommentForm(thisform,varUrl){
	if(thisform.cName.value.length<4 ){
		alert("Mohon masukkan nama lebih dari 4 karakter");
		thisform.cName.focus();
	}else if(!isEmail( thisform.cMail.value) ){
		alert("Masukkan Alamat Email dengan benar");
		thisform.cMail.focus();
	}else if(thisform.cComment.value.length==0 && thisform.comments.value==""){
		alert("Masukkan komentar!!!");
		thisform.cComment.focus();
	}else if(thisform.cComment.value.length > 500){
		alert("Komentar harus kurang dari 500 karakter");
		thisform.cComment.focus();
		return;
	}else if(thisform.cVerify.value!=thisform.cVerifyImage.value){
		alert("Kode yang anda masukkan kurang benar");
		thisform.cVerify.focus();
		return;
	}else{
		var params="";
		for(i=0; i<thisform.elements.length; i++){
			params+='&'+thisform.elements[i].name+'='+escape(encodeURI( thisform.elements[i].value ));
		}
		var xmlHttp=getHttpRequest();
		if(!xmlHttp){return false;}
		
		var url = varUrl;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.onreadystatechange = function() 
			{
				if(xmlHttp.readyState == 4 && xmlHttp.status == 200) 
					{
						alert("Terima kasih. Komentar Anda sudah kami terima");
						result = xmlHttp.responseText;
						thisform.reset();
						//document.getElementById('output').innerHTML = result;            
					}
			}
			
		xmlHttp.send(params);
	}
}

function submitForm(varUrl,outLayer,progressBar){
	var thisform=document.forms[0];	
	var params="";
	for(i=0; i<thisform.elements.length; i++){
		params+='&'+thisform.elements[i].name+'='+escape(encodeURI( thisform.elements[i].value ));
	}
		
	var xmlHttp=getHttpRequest();
	if(!xmlHttp){return false;}
	
	var url = varUrl;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) 
				{
					result = xmlHttp.responseText;
					thisform.reset();
					if(document.getElementById(progressBar)) {document.getElementById(progressBar).style.display='none';}
					if(document.getElementById(outLayer)) {document.getElementById(outLayer).innerHTML = result;}
				}
		}
		
	xmlHttp.send(params);
}

function basename(path) {
	var a=path;
	var b=a.match(/[\/|\\]([^\\\/]+)$/);
	return b[1];
}