//context path
var path='';

//untuk setmaxVariable
		var HINTS_CFG ;
		// text/HTML of the hints
		var HINTS_ITEMS; 
		var myHint;
//END setmaxVariable

//change locale
function locale(requestUri, locale){
	window.location = requestUri + '?locale=' + locale;
	return false;
}
//submit form without submit buttons
function submit_form(nama, btn){
	var frm = document.getElementById(nama);
	if(frm){
		btn.disabled=true;
		frm.submit();
	}
	return false;
}
//check if enter is pressed on inputs
function checkEnter(e, nama){ // event object
	var characterCode; // literal character code
	if(e && e.which){ // NN4
		e = e;
		characterCode = e.which;
	} else{ // IE
		e = event;
		characterCode = e.keyCode;
	}
	if(characterCode == 13){ // enter
		var frm = document.getElementById(nama);
		if(frm) frm.submit(); //submit
		return false;
	} else{
		return true;
	}
}
//popup window with a given height & weight
function popWin(href, width, height) {
	var vWin;
	vWin = window.open(href,'','height='+height+',width='+width+	',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,modal=yes,status=yes'+
		',left='+((screen.availWidth-width)/2)+
		',top='+((screen.availHeight-height)/2));
	vWin.opener = self;
} 
//limit string length in textareas
function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
}
/*
Fungsi untuk membuat date input pada textbox biasa (digabung dengan fungsi inputDate dibawah)
 */
function checkDate(nama, elm, evt, onchg){
	
	keyCode = evt.keyCode;
	awal = getSelectionStart(elm);
	akhir = getSelectionEnd(elm);
	nilai = elm.value;
	var result = false;
	is_date_field = true;
	
	//kalau tekan enter atau tab
	if( keyCode==13 || keyCode==9 ){
		result = true;
		
	//kalau cursor pilihan > 1
	}else if(awal != akhir){
		var a=0;
		if(awal>=6) a=6; else if(awal>=3) a=3;
		setSelectionRange(elm, a, a);
	
	//kalau panah kiri atau kanan
	}else if( keyCode==37 || keyCode==39 ){
		result = true;

	//kalau tombol backspace
	}else if(keyCode == 8){
		if( awal==3 || awal==6 ) {
			evt.keyCode = 37;
			result = true;	
		}else if(awal==0){

		}else{
			elm.value = nilai.substring(0,awal-1) + '0' + nilai.substring(awal);
			var kurang = 1;
			if( awal==4 || awal==7 ) kurang = 2;
			setSelectionRange(elm, awal-kurang, awal-kurang);
		}

	//kalau cursor sebelum tanda slash ( / )
	}else if( awal==2 || awal==5 ) {
		setSelectionRange(elm, awal+1, awal+1);

	//kalau cursor ada di akhir textbox
	}else if(awal == 10) {
		
	//kalau di-click
	}else if( keyCode == 0 || !keyCode ){
		if( awal==2 || awal==5 ) setSelectionRange(elm, awal+1, awal+1);

	//kalau yang diinput adalah angka
	}else if( (keyCode>=48 && keyCode<=57) || (keyCode>=96 && keyCode<=105) ){
		if(keyCode>=96) keyCode -= 48;
		keyChar = String.fromCharCode(keyCode);
		elm.value = nilai.substring(0,awal) + keyChar + nilai.substring(awal+1);
		var tambah = 1;
		if( awal==1 || awal==4 ) tambah = 2; 
		setSelectionRange(elm, awal+tambah, awal+tambah);
	}


	if(elm.value == '__/__/____' || elm.value == '00/00/0000') document.getElementById(nama).value = '';
	else document.getElementById(nama).value = elm.value;
	
	if(elm.value.indexOf("_") == -1) eval(unescape(onchg));
	else document.getElementById(nama).value = '';
	
	return result;

}
/* Fungsi untuk mengganti disable/enable inputDate */
function enableDisableDate(nama){
	document.getElementById('_' + nama).disabled = !document.getElementById('_' + nama).disabled;
	document.getElementById('img_' + nama).disabled = !document.getElementById('img_' + nama).disabled;
}

function inputDate(nama, nilai, aktif, onchg, tabidx){
	var nilai2 = '';
	if(!nilai || nilai=='') nilai = '__/__/____';
	else nilai2 = nilai;
	
	if(!onchg) onchg='';
	
	var disabled = '';
		disabled2= '';
	if(aktif){
	 disabled = ' readOnly ';
	 disabled2= ' disabled ';
	}
	
	if(!tabidx) tabidx=''; else tabidx = 'tabindex="' +tabidx+ '"';

	document.write(
		'<input '+disabled2+'type="text" '+tabidx+' name="_'+nama+'" id="_'+nama+'" value="'+nilai+'" maxlength="10" size="12" style="text-align: center;"  '+
		'onmouseup="return checkDate(\''+nama+'\', this, event, \''+escape(onchg)+'\')" onkeydown="return checkDate(\''+nama+'\', this, event, \''+escape(onchg)+'\')" >\n' +
		'<input '+disabled+'type="hidden" name="'+nama+'" id="'+nama+'" value="'+nilai2+'">\n'+
		'<img '+disabled2+'src="/E-Insurance/include/images/calendar.jpg" align="baseline" title="Calendar" border="0" id="img_'+nama+'">'
		);

	function chg(cal){

        var date = cal.date;
        //var time = date.getTime()
        //var date2 = new Date(time);
        //field.value = date2.print("%Y-%m-%d %H:%M");


		document.getElementById(nama).value = date.print("%d/%m/%Y");
		eval(unescape(onchg));
	}
	
    Calendar.setup({
        inputField     :    "_"+nama,
        ifFormat       :    "%d/%m/%Y",
        button         :    "img_"+nama,
        align          :    "Tl",
        onUpdate : chg
    });
}

<!-- Print Function
function PrintParts(arrElementNames)
{ var objWindow=window.open("about:blank", "print", "left=0, top=0, width=800, height=0, toolbar=no, scrollbars=yes");
  var strHtml="<%@ page contentType = \"application/vnd.ms-excel\" %><html>";
  strHtml += "<head>";
  strHtml += "<title>Sinarmaslife E-Insurance PRINTED DATA</title>";
  strHtml += "<meta name=\"author\" content=\"PT. Asuransi Jiwa Sinarmas MSIG  | Administered by: Yusuf Sutarko | Original design: Andreas Viklund - http://andreasviklund.com/ | Icons: Paul Jarvis - http://2pt3.com/\" />";
  strHtml += "<link rel=\"stylesheet\" type=\"text/css\" href=\"/E-Insurance/include/css/andreas02.css\" media=\"screen\" title=\"andreas02 (screen)\" />";
  strHtml += "<link rel=\"stylesheet\" type=\"text/css\" href=\"/E-Insurance/include/css/print.css\" media=\"print\" />";
  strHtml += "<script type=\"text/javascript\" src=\"/E-Insurance/include/js/links.js\"></script>";
  strHtml += "</head>";
  strHtml += "<body style=\"background=white;\">";
  strHtml += "<br>";
  for (var i=0; i<arrElementNames.length; i++){ var element=document.getElementById(arrElementNames[i]);
  	  										    strHtml += element.innerHTML; }
  strHtml += "</body>";
  strHtml += "</html>";
  objWindow.document.write(strHtml);
  objWindow.document.close();
  objWindow.print();
  objWindow.close();
}

/*
Fungsi untuk hide Loading message seperti GMAIL
*/
function hideLoadingMessage(){
	if(parent)
		if(parent.document){
			var dZone = parent.document.getElementById('dZone');
			if(dZone) dZone.style.visibility = 'hidden';
			window.scrollbars = false;
		}
}

/*
Fungsi untuk show Loading message seperti GMAIL
*/
function createLoadingMessage(){
	var dZone = $('dZone');
	if(!dZone){
		dZone = document.createElement('div');
		dZone.setAttribute('id', 'dZone');
		dZone.style.position = "absolute";
		dZone.style.zIndex = "1000";
		dZone.style.left = "0px";
		dZone.style.top = "0px";
		dZone.style.width = "100%";
		dZone.style.height = "100%";
		document.body.appendChild(dZone);
		var mZone = document.createElement('div');
		mZone.setAttribute('id', 'mZone');
		mZone.style.position = "absolute";
		mZone.style.top = "0px";
		mZone.style.right = "0px";
		mZone.style.background = "red";
		mZone.style.color = "white";
		mZone.style.fontFamily = "Arial,Helvetica,sans-serif";
		mZone.style.padding = "4px";
		dZone.appendChild(mZone);
		var text = document.createTextNode('Proses sedang dilakukan..harap tunggu sebentar!');
		mZone.appendChild(text);
	}else{
		$('mZone').innerHTML = 'Loading';
		dZone.style.visibility = 'visible';
	}
}

function maxPict(wise,margin,gap,align,css,show_delay,hide_delay,follow,z,IEfix,IEtrans1,IEtrans2,opacity,name, items){
// configuration variable for the hint object, these setting will be shared among all hints created by this object
			HINTS_CFG = {
				'wise'       : wise, // don't go off screen, don't overlap the object in the document
				'margin'     : margin, // minimum allowed distance between the hint and the window edge (negative values accepted)
				'gap'        : gap, // minimum allowed distance between the hint and the origin (negative values accepted)
				'align'      : align, // align of the hint and the origin (by first letters origin's top|middle|bottom left|center|right to hint's top|middle|bottom left|center|right)
				'css'        : css, // a style class name for all hints, applied to DIV element (see style section in the header of the document)
				'show_delay' : show_delay, // a delay between initiating event (mouseover for example) and hint appearing
				'hide_delay' : hide_delay, // a delay between closing event (mouseout for example) and hint disappearing
				'follow'     : follow, // hint follows the mouse as it moves
				'z-index'    : z, // a z-index for all hint layers
				'IEfix'      : IEfix, // fix IE problem with windowed controls visible through hints (activate if select boxes are visible through the hints)
				'IEtrans'    : [IEtrans1, IEtrans2], // [show transition, hide transition] - transition effects, only work in IE5+
				'opacity'    : opacity // opacity of the hint in %%
			};
			// text/HTML of the hints
			HINTS_ITEMS = {
				'tt1' : items,
				'tt2' : '<img src="../include/newImages/suvenir.jpg" border="1" />',
				'tt3' : '<img src="../include/images/offer.gif" border="1" />',
				'tt4' : '<img src="../include/images/garansi.gif" border="1" />',
				'tt5' : '<img src="../include/images/garansi_en.gif" border="1" />',
				'tt6' : '<img src="../include/newImages/award/SertifakatInfoBank2009.jpg" border="1" />'
			};
			
			 myHint = new THints (HINTS_ITEMS, HINTS_CFG);
			 
			 	/*var HINTS_CFG = {
				'wise'       : true, // don't go off screen, don't overlap the object in the document
				'margin'     : 10, // minimum allowed distance between the hint and the window edge (negative values accepted)
				'gap'        : 20, // minimum allowed distance between the hint and the origin (negative values accepted)
				'align'      : 'bltl', // align of the hint and the origin (by first letters origin's top|middle|bottom left|center|right to hint's top|middle|bottom left|center|right)
				'css'        : 'hintsClass', // a style class name for all hints, applied to DIV element (see style section in the header of the document)
				'show_delay' : 200, // a delay between initiating event (mouseover for example) and hint appearing
				'hide_delay' : 500, // a delay between closing event (mouseout for example) and hint disappearing
				'follow'     : true, // hint follows the mouse as it moves
				'z-index'    : 100, // a z-index for all hint layers
				'IEfix'      : true, // fix IE problem with windowed controls visible through hints (activate if select boxes are visible through the hints)
				'IEtrans'    : ['revealTrans(TRANSITION=3,DURATION=.5)', 'revealTrans(TRANSITION=2,DURATION=.5)'], // [show transition, hide transition] - transition effects, only work in IE5+
				'opacity'    : 80 // opacity of the hint in %%
			};
			// text/HTML of the hints
			var HINTS_ITEMS = {
				'tt1': '<img src="${path}/include/newImages/sertifikat-Investor-2008.jpg" border="1" />'
			};
			
			var myHint = new THints (HINTS_ITEMS, HINTS_CFG);*/
			
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


