//GET COOKIE
function getCookie(Name) { 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
	return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
}

//SET COOKIE
function setCookie(name, value, days) {
	var expireDate = new Date()
	//set "expstring" to either future or past date, to set or delete cookie, respectively
	var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
	document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

//ALERT EMPTY FIELD FORM
function alertEmptyForm(field, msg){
	alert(field.id + msg);
	field.select();
	field.focus();
}

//ALERT HTML MODE
function alertHTML(field, msg){
	if(popUpWin){
		if(!popUpWin.closed) popUpWin.close();
	}
	
	width = 300;
	height = 150;

	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	popUpWin = window.open('', "openwindow", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,dependent=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.document.open();
	popUpWin.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
	popUpWin.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
	popUpWin.document.write("<head>");
	popUpWin.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />");
	popUpWin.document.write("<title>Pesan Error!</title>");
	popUpWin.document.write("<style type=\"text/css\">");
	popUpWin.document.write("body{ font-family: Arial; font-size: 12px; color: windowtext; background-color: buttonface; overflow: hidden; padding: 0px; margin: 0px;}");
	popUpWin.document.write("td{ font-family: Arial; font-size: 12px; color: windowtext; background-color: buttonface; overflow: hidden; }");
	popUpWin.document.write("a:link, a:visited, a:active{ display: block; color: #000000; width: 100%; height: 100%; padding-top: 25px; text-decoration: none; position: absolute; top: 0px; left: 0px; z-index: 3; cursor: auto; background-color: transparent;}");
	popUpWin.document.write("</style>");
	popUpWin.document.write("</head>");
	popUpWin.document.write("<body onblur=\"window.close();\">");
	popUpWin.document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	popUpWin.document.write("<tr><td style=\"height: 150px;\" align=\"center\">");
	popUpWin.document.write("<a href=\"#\" onclick=\"window.close();\">");
	popUpWin.document.write("<img src=\"../includes/js/info.png\" border=\"0\" alt=\"Pesan Error!\" /><br><br>");
	popUpWin.document.write(field.id + " " + msg);
	popUpWin.document.write("</a>");
	popUpWin.document.write("</td></tr></table></body></html>");	
	popUpWin.document.close();
}

//CHECK BOX CONTROLLER
function checkAll( n, fldName ) {
	if (!fldName) {
		fldName = 'checkbox';
	}
	
	var f = document.adminForm;
	var c = f.cbController.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		checkbox = eval( 'f.' + fldName + '' + i );
		if (checkbox) {
			checkbox.checked = c;
			n2++;
		}
	}
}

//GET CHECK BOX VALUES IN ARRAY
function submitform(){
	fldName = 'checkbox';
	var f = document.adminForm;
	myArray = Array();
			
	for (i=0; i<f.listValueArrayNum.value; i++) {
		checkbox = eval( 'f.' + fldName + '' + i );
		if (checkbox.checked) {
			myArray.push(checkbox.value);
			f.listValueArray.value = myArray;
		}
	}
	
	return true;
}

//GET CHECK BOX VALUES IN ARRAY
function getSelectedRadio(selected){
	document.adminForm.listValue.value = selected;
}


//SET FOCUS AUTOMATICALLY
function setAutoFocus(){
	var closing = true;
	if(document.adminForm != undefined){
		for(k= 0; k<document.adminForm.elements.length; k++){
			if((document.adminForm.elements[k].type == 'text' || document.adminForm.elements[k].type == 'password' || document.adminForm.elements[k].type == 'textarea' || document.adminForm.elements[k].type == 'select') && document.adminForm.elements[k].disabled == false){
				document.adminForm.elements[k].focus();
				k = document.adminForm.elements.length;
			}
		}
	}
}

window.onerror=noerror
function noerror(){
	return true;
}

var popUpWin=0;
function popUpWindow(urlFile,title,width,height){
	if(popUpWin){
		if(!popUpWin.closed) popUpWin.close();
	}

	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	popUpWin = open(urlFile, "openwindow", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,dependent=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowFull(urlFile,title,width,height){
	if(popUpWin){
		if(!popUpWin.closed) popUpWin.close();
	}

	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	popUpWin = open(urlFile, "openwindow", 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,dependent=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function openWindow(url,mode){
	title = "openwindow";
	if(mode == 3){
		popUpWindowFull(url,title,800,600);
	}else if(mode == 4){
		popUpWindowFull(url,title,640,480);
	}else if(mode == 5){
		popUpWindow(url,title,1064,768);
	}else if(mode == 6){
		popUpWindow(url,title,800,600);
	}else if(mode == 7){
		popUpWindow(url,title,640,480);
	}
}

function getEditorContent(editorType){
	f=document.adminForm;

	if(editorType == "fckeditor"){
		f.submit();
	}else if(editorType == "mosce"){
		tinyMCE.triggerSave();
		f.submit();
	}else if(editorType == "tinymce"){
		tinyMCE.triggerSave();
		f.submit();
	}
}