
//var popUpWidth = Math.round(screen.width / 2) + 150;
//var popUpHeight = Math.round(screen.height / 2) + 150;

var popUpWidth = 800;
var popUpHeight = 600;

var leftPos = Math.round(screen.width / 2) - Math.round(popUpWidth / 2);
var topPos =  Math.round(screen.height / 2) - Math.round(popUpHeight / 2);

function cek_empty(field,fieldNam) {
	ret_val=true;
	if (field.value == "") {
		alert(fieldNam + " tidak boleh kosong.");
		field.focus();
		ret_val=false;
	}
	return ret_val;
}

function isPhone(phone)
{
	if (cek_empty(phone,"Telephone Number"))
	{
		if (isNaN(phone.value))
		{
			alert("Incorrect Telephone Number");
			phone.focus();
			return false;

		}
		else {			
			return true;
		}
	}
	else {			
		return false;
	}
}

function isEmailAddr(email)
{
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if (pindex > index+1)
			result = true;
	}
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	  
	if (required && !cek_empty(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) && formField.value!="")
	{
		alert(fieldLabel + " yang anda masukkan tidak lengkap");
		formField.focus();
		result = false;
	}
	return result;
}

function cekPassword(pass1,pass2,fieldNam) {
	if (pass1.value=="" || pass2.value=="")
	{
		alert("Password required. Please enter your Password");
		if (pass1.value=="")
			pass1.focus();
		else if (pass2.value=="")
			pass2.focus();

		return false;
	}
	else if (pass1.value!=pass2.value)
	{
		alert("Both Password field must have the same value.");
		pass1.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkEmail(email1,email2,fieldNam) {
	if (email1.value=="" || email2.value=="")
	{
		alert("E-mail address required. Please enter your E-mail address");
		if (email1.value=="")
			email1.focus();
		else if (email2.value=="")
			email2.focus();

		return false;
	}
	else if (email1.value!=email2.value)
	{
		alert("Both E-mail field must have the same value.");
		email1.focus();
		return false;
	}
	else if (!validEmail(email1,'E-mail Address',true))
	{
		return false;
	}
	else {
		return true;
	}
}


function checkSingleEmail(email1,fieldNam) {
	if (email1.value=="" || email1.value=="e-mail address")
	{
		alert("E-mail address required. Please enter your E-mail address");
		
		email1.focus();

		return false;
	}
	else if (!validEmail(email1,'E-mail Address',true))
	{
		return false;
	}
	else {
		return true;
	}
}


function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


array_search = function (array, value) {

   var results = -1;

   for (var i = 0; i < array.length; i++) {
      if (array[i] == value) { results = i; }
   }
   return results;

}
/*** Copy Right Information ***
  * Please do not remove following information.
  * Modal Popup v1.0
  * Author: John J Kim
  * Email: john@frontendframework.com
  * URL: www.FrontEndFramework.com
  * 
  * You are welcome to modify the codes as long as you include this copyright information.
 *****************************/
 
//With the window size & the element size functions built-in
ModalPopup = function (elem,options) {
	
	//option default settings
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '#000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 90000;
	var AddLeft = options.AddLeft || 0; //in px
	var AddTop = options.AddTop || 0; //in px
	
	AddTop = AddTop + document.documentElement.scrollTop;
	function _Convert(val) {
		if (!val) {return;}
		val = val.replace("px","");
		if (isNaN(val)) {return 0;}
		return parseInt(val);
	}
	var popup = document.getElementById(elem);
	if (!popup) {return;}
	//set the popup layer styles
	var winW = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var winH = screen.height;
	//display the popup layer
	popup.style.display = "block";
	popup.style.visibility = "visible";
	var currentStyle;
	if (popup.currentStyle)	{ 
		currentStyle = popup.currentStyle; 
	}
	else if (window.getComputedStyle) {
		currentStyle = document.defaultView.getComputedStyle(popup, null);
	} else {
		currentStyle = popup.style;
	}

	var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

	var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

	popup.style.left = (winW/2 - elemW/2 + AddLeft - 10) + "px";
	popup.style.top = (winH/2 - elemH/2 + AddTop - 10) + "px";
	popup.style.position = "absolute";
	popup.style.zIndex = Zindex + 1;

	/*if (winH > document.body.clientHeight  + AddTop)
	{
		BackgroundHeight = winH;
	}
	else {*/
		BackgroundHeight = document.body.clientHeight  + AddTop;
	//}
	
	if (HasBackground) {	
		if (!ModalPopup._BackgroundDiv) {
			addDiv = false;
			var browser=navigator.appName;
			if (!document.getElementById("BackGroundDiv") || browser=="Microsoft Internet Explorer")
			{
				addDiv = true;
				ModalPopup._BackgroundDiv = document.createElement('div');
			}
			else {
				ModalPopup._BackgroundDiv = document.getElementById("BackGroundDiv");
			}
			ModalPopup._BackgroundDiv.style.display = "none";
			ModalPopup._BackgroundDiv.style.width = document.body.clientWidth + "px";
			ModalPopup._BackgroundDiv.style.height = BackgroundHeight + "px";
			ModalPopup._BackgroundDiv.style.position = "absolute";
			ModalPopup._BackgroundDiv.style.top = "0px";
			ModalPopup._BackgroundDiv.style.left = "0px";
			if (addDiv)
			{
				document.body.appendChild(ModalPopup._BackgroundDiv);
			}
		}
		ModalPopup._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopup._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopup._BackgroundDiv.style.height = BackgroundHeight + "px";
		ModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.zIndex = Zindex;
		ModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		//Display the background
		ModalPopup._BackgroundDiv.style.display = "block";
		ModalPopup._BackgroundDiv.style.visibility = "visible";
	}

}
ModalPopupParent = function (elem,options) {
	
	//option default settings
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '#000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 90000;
	var AddLeft = options.AddLeft || 0; //in px
	var AddTop = options.AddTop || 0; //in px
	
	AddTop = AddTop + top.document.body.scrollTop;
	function _Convert(val) {
		if (!val) {return;}
		val = val.replace("px","");
		if (isNaN(val)) {return 0;}
		return parseInt(val);
	}
	var popup = top.document.getElementById(elem);
	if (!popup) {return;}
	//set the popup layer styles
	var winW = (top.document.layers||(top.document.getElementById&&!top.document.all)) ? window.outerWidth : (top.document.all ? top.document.body.clientWidth : 0);
	var winH = screen.height;
	//display the popup layer
	popup.style.display = "block";
	popup.style.visibility = "visible";
	var currentStyle;
	if (popup.currentStyle)	{ 
		currentStyle = popup.currentStyle; 
	}
	else if (window.getComputedStyle) {
		currentStyle = top.document.defaultView.getComputedStyle(popup, null);
	} else {
		currentStyle = popup.style;
	}

	var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

	var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

	popup.style.left = (winW/2 - elemW/2 + AddLeft - 10) + "px";
	popup.style.top = (winH/2 - elemH/2 + AddTop - 10 - 100) + "px";
	popup.style.position = "absolute";
	popup.style.zIndex = Zindex + 1;

	/*if (winH > top.document.body.clientHeight  + AddTop)
	{
		BackgroundHeight = winH;
	}
	else {*/
		BackgroundHeight = top.document.body.clientHeight  + AddTop;
	//}
	top.document.body.style.overflow="hidden";
	
	if (HasBackground) {	
		if (!ModalPopupParent._BackgroundDiv) {
			addDiv = false;
			var browser=navigator.appName;
			if (!top.document.getElementById("BackGroundDiv") || browser=="Microsoft Internet Explorer")
			{
				addDiv = true;
				ModalPopupParent._BackgroundDiv = top.document.createElement('div');
			}
			else {
				ModalPopupParent._BackgroundDiv = top.document.getElementById("BackGroundDiv");
			}
			ModalPopupParent._BackgroundDiv.id = "ThisDiv";
			ModalPopupParent._BackgroundDiv.style.display = "none";
			ModalPopupParent._BackgroundDiv.style.width = top.document.body.clientWidth + "px";
			ModalPopupParent._BackgroundDiv.style.height = BackgroundHeight + "px";
			ModalPopupParent._BackgroundDiv.style.position = "absolute";
			ModalPopupParent._BackgroundDiv.style.top = "0px";
			ModalPopupParent._BackgroundDiv.style.left = "0px";
			if (addDiv)
			{
				top.document.body.appendChild(ModalPopupParent._BackgroundDiv);
			}
		}
		ModalPopupParent._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopupParent._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopupParent._BackgroundDiv.style.height = BackgroundHeight + "px";
		ModalPopupParent._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopupParent._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
		ModalPopupParent._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
		ModalPopupParent._BackgroundDiv.style.zIndex = Zindex;
		ModalPopupParent._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		//Display the background
		ModalPopupParent._BackgroundDiv.style.display = "block";
		ModalPopupParent._BackgroundDiv.style.visibility = "visible";
	}

}



ModalPopupBlock = function (elem,options) {
	
	//option default settings
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '#000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 90000;
	var AddLeft = options.AddLeft || 0; //in px
	var AddTop = options.AddTop || 0; //in px
	
	AddTop = AddTop + document.documentElement.scrollTop;
	function _Convert(val) {
		if (!val) {return;}
		val = val.replace("px","");
		if (isNaN(val)) {return 0;}
		return parseInt(val);
	}
	var popup = document.getElementById(elem);
	if (!popup) {return;}
	//set the popup layer styles
	var winW = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var winH = screen.height;
	//display the popup layer
	popup.style.display = "block";
	popup.style.visibility = "visible";
	var currentStyle;
	if (popup.currentStyle)	{ 
		currentStyle = popup.currentStyle; 
	}
	else if (window.getComputedStyle) {
		currentStyle = document.defaultView.getComputedStyle(popup, null);
	} else {
		currentStyle = popup.style;
	}

	var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

	var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

	popup.style.left = (winW/2 - elemW/2 + AddLeft - 10) + "px";
	popup.style.top = (AddTop + 50) +"px";
	popup.style.position = "absolute";
	popup.style.zIndex = Zindex + 1;

	/*if (winH > document.body.clientHeight  + AddTop)
	{
		BackgroundHeight = winH;
	}
	else {*/
		BackgroundHeight = document.body.clientHeight  + AddTop;
	//}
	document.body.style.overflow="hidden";
	
	if (HasBackground) {	
		if (!ModalPopupBlock._BackgroundDiv) {
			addDiv = false;
			var browser=navigator.appName;
			if (!document.getElementById("BackGroundDiv") || browser=="Microsoft Internet Explorer")
			{
				addDiv = true;
				ModalPopupBlock._BackgroundDiv = document.createElement('div');
			}
			else {
				ModalPopupBlock._BackgroundDiv = document.getElementById("BackGroundDiv");
			}
			ModalPopupBlock._BackgroundDiv.id = "ThisDiv";
			ModalPopupBlock._BackgroundDiv.style.display = "none";
			ModalPopupBlock._BackgroundDiv.style.width = document.body.clientWidth + "px";
			ModalPopupBlock._BackgroundDiv.style.height = BackgroundHeight + "px";
			ModalPopupBlock._BackgroundDiv.style.position = "absolute";
			ModalPopupBlock._BackgroundDiv.style.top = "0px";
			ModalPopupBlock._BackgroundDiv.style.left = "0px";
			if (addDiv)
			{
				document.body.appendChild(ModalPopupBlock._BackgroundDiv);
			}
		}
		ModalPopupBlock._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopupBlock._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopupBlock._BackgroundDiv.style.height = BackgroundHeight + "px";
		ModalPopupBlock._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopupBlock._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
		ModalPopupBlock._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
		ModalPopupBlock._BackgroundDiv.style.zIndex = Zindex;
		ModalPopupBlock._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		//Display the background
		ModalPopupBlock._BackgroundDiv.style.display = "block";
		ModalPopupBlock._BackgroundDiv.style.visibility = "visible";
	}

}

ModalPopup.Close = function(id) {
	if (id) {
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";
	} 
	if  (ModalPopup._BackgroundDiv) {
		ModalPopup._BackgroundDiv.style.display = "none";
		ModalPopup._BackgroundDiv.style.visibility = "hidden";
	}
}
ModalPopupBlock.Close = function(id) {
	
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";

		document.getElementById("ThisDiv").style.display = "none";
		document.getElementById("ThisDiv").style.visibility = "hidden";
	
	
	document.body.style.overflow="auto";
}
ModalPopupParent.Close = function(id) {
	
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";

		document.getElementById("ThisDiv").style.display = "none";
		document.getElementById("ThisDiv").style.visibility = "hidden";
	
	
	document.body.style.overflow="auto";
}

var GlobalModalPopup = this.ModalPopup;
