function CreateArray(dim1,dim2,dim3) {

	if (CreateArray.arguments.length == 1) {
		return new Array(dim1);
	} else if (CreateArray.arguments.length == 2){
		var multiArray = new Array(dim1)
		for (var i = 0; i < dim1; i++) {
			multiArray[i] = new Array(dim2);
		}
		return multiArray;
	} else {
		var multiArray = new Array(dim1)
		for (var i = 0; i < dim1; i++) {
			multiArray[i] = new Array(dim2);
		}
		for (var i = 0; i < dim1; i++) {
			for (var j = 0; j < dim2; j++) {
				multiArray[i][j] = new Array(dim3);
			}
		}
		return multiArray;
	}

}


function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function remCommas(a) {

	a=a.split(",").join("");

	return a;
}

function ShowRemain(txt){
	var frm = document.frmInput;
	var sl = new String(txt);
	var counter = frm.ms.length;
	if (sl.length >= 165) {
		alert('Pesan anda telah mencapai limit karakter');
		frm.content_value.value = sl.substr(0,165);
	}
	frm.ms.value = sl.length;
}

function AjaxRequest(url,containerid,m,frmObj,imgpath,clear1,clear2) {
	var urlSid // to make the request page unique, avoiding page cache
	var page_request = false
	var method
	var separator
	var parameters
	var ajax_goto = null
	
	if (url.indexOf("?") == -1)
		separator = "?"
	else
		separator = "&"
	
	urlSid = url + separator + "ajax=1&sid=" + Math.random() 
	
	if (m == 3) {
		m = 2
		var nofloat = 'yes';
	} else var nofloat;
	
	if (m == 1) { // 1 = POST, 2 = GET
		method = 'POST'
		ajax_goto = 'AjaxRequest(\'?mod=sM&act=00002&note=1\',\'' + containerid + '\',2,null);'
		//alert(goto)
	}
	else
		method = 'GET'	

	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject) { // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e) {
			try {
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e) {}
		}
	}
	else
		return false
	
	//StartFloat();
	document.body.style.cursor="wait";

	if (nofloat != 'yes') document.getElementById(containerid).innerHTML = "<img src=\""+imgpath+"\" width=\"16\" height=\"16\">";
	
	if (clear1) document.getElementById(clear1).innerHTML = '';
	if (clear2) document.getElementById(clear2).innerHTML = '';
	
	//document.getElementById("AdFloater").style.visibility = "visible"

	page_request.onreadystatechange = function() {
		AjaxLoad(page_request, containerid, m, ajax_goto)
	}
		
	page_request.open(method, urlSid, true)
	
	if (method == 'POST') {
		//alert(goto)
		parameters = getObj(frmObj)
		page_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
		page_request.setRequestHeader("Content-length", parameters.length);
	    page_request.setRequestHeader("Connection", "close");
		page_request.send(parameters)
	}
	else
		page_request.send(null)
}

function AjaxLoad(page_request, containerid, m, ajax_goto) {
	if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
		//document.getElementById("AdFloater").style.visibility = "hidden"
		document.body.style.cursor="";
			
		if (m == 2) {
			document.getElementById(containerid).innerHTML = page_request.responseText
			//loadJSsrc(jsSrc)
		}
		else {
			//document.getElementById(containerid).innerHTML = page_request.responseText
			//alert(goto)
			eval(ajax_goto)
			
		}
	}
}


function do_pop(link,width,height){
	window.open(link,'popup','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width='+width+',height='+height+'');
}


function getElementValue(formElement) {
	
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type) {
		
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}


function setElementValue(formElement, value) {
	
	switch(formElement.type) {
		
		case 'undefined': return;
		case 'radio': formElement.checked = value; break;
		case 'checkbox': formElement.checked = value; break;
		case 'select-one': formElement.selectedIndex = value; break;

		case 'select-multiple':
			for(var x=0; x < formElement.length; x++) 
				formElement[x].selected = value[x];
			break;

		default: formElement.value = value; break;
	}
}


var http_request = false;
function makeRequest(url,parameters,destination) {
  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;
  }
 
  //http_request.onreadystatechange = alertContents;
  http_request.onreadystatechange = function() {
		alertContents(destination)
  }
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
}

function alertContents(destination) {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById(destination).innerHTML = result;            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function AjaxElementProcess(obj,target,imgpath) {
  var getstr = "&";

  var check = document.getElementsByName(obj);
	
  for (i=0; i<check.length; i++)  if (check[i].checked) getstr += obj+"[]=" + check[i].value + "&";

  document.getElementById(obj).innerHTML = "<img src=\""+imgpath+"\" width=\"16\" height=\"16\">";  

  makeRequest(target,getstr,obj);
}


function EditCurrency(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  if (whichCode == 0) return true;  // Tab

  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  else return true;
}


function currencyFormat(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  if (whichCode == 0) return true;  // Tab

  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}


function currencyFormatNoDecimal(fld, milSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  if (whichCode == 0) return true;  // Tab
  
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if (fld.value.charAt(i) != '0') break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len > 0) {
    aux2 = '';
    for (j = 2, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += aux.substr(len - 2, len);
  }
  return false;
}


function PMA_markRowsInit() {
	// for every table row ...
	var rows = document.getElementsByTagName('tr');
	for ( var i = 0; i < rows.length; i++ ) {
		// ... with the class 'odd' or 'even' ...
		if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
			continue;
		}
		// ... add event listeners ...
		// ... to highlight the row on mouseover ...
		if ( navigator.appName == 'Microsoft Internet Explorer' ) {
			// but only for IE, other browsers are handled by :hover in css
			rows[i].onmouseover = function() {
				this.className += ' hover';
			}
			rows[i].onmouseout = function() {
				this.className = this.className.replace( ' hover', '' );
			}
		}
	}
}


function CheckBoxAll( n, fldName ) {
	if (!fldName) fldName = 'rows_operation';
	var f = document.frmCommonList;
	var g = document.getElementById('common_list');
	
	var c = f.selectAll.checked;
	var n2 = 0;
	
	for (i=1; i <= n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
}


function toggle(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
		e.style.display = 'block';
	else
	e.style.display = 'none';
}


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

/*********************************** Bubble tips related scripts ********************************/

document.write('<span id="bubble" style="BORDER-RIGHT: lightgreen 3px double; PADDING-RIGHT: 3px; BORDER-TOP: lightgreen 3px double; PADDING-LEFT: 3px; FONT-WEIGHT: bold; FONT-SIZE: 11px; Z-INDEX: 200; LEFT: 300px; VISIBILITY: hidden; PADDING-BOTTOM: 3px; BORDER-LEFT: lightgreen 3px double; CURSOR: hand; PADDING-TOP: 3px; BORDER-BOTTOM: lightgreen 3px double; FONT-FAMILY: Calibri, Arial; POSITION: absolute; TOP: 100px; WIDTH: 180px; HEIGHT: 22px; BACKGROUND-COLOR: honeydew" onmouseout="hideBubble()">-</span>');
			
function is_right_available(box,e) {
	if ((box.clientWidth+e.clientX+h_padding)>=winWidth){
		return false;
	}
	return true;
}

function is_top_available(box,e) {
	if ((e.clientY-box.clientHeight-v_padding) < 0){
		return false;
	}
	return true;
}

function is_bot_available(box,e) {
	if ((e.clientY+box.clientHeight+v_padding) > winHeight){
		return false;
	}
	return true;
}

function is_left_available(box,e) {
	if ((e.clientX+box.clientWidth-h_padding)<0){
		return false;
	}
	return true;
}

function boxFinishedMoving(box) {
	var y=box.offsetTop;
	var x=box.offsetLeft;
	if ((y<box.ypos)||(y>box.ypos)||(x<box.xpos)||(x>box.xpos)) {
		return false;
	} else {
		return true;
	}
}

function moveBox() {
	var box = document.getElementById('bubble');
	var y=box.offsetTop;
	var x=box.offsetLeft;
	if (!boxFinishedMoving(box))
	{
		if (y<box.ypos)
		{
			y++;
			box.style.top = y;
		}
		if (y>box.ypos)
		{
			y--;
			box.style.top = y;
		}
		if (x<box.xpos)
		{
			x++;
			box.style.left = x;
		}
		if (x>box.xpos)
		{
			x--;
			box.style.left = x;
		}
		window.setTimeout("moveBox()", 10);
	}
}

winWidth=0;
winHeight=0;
initFrameSize();

function initFrameSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof(window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	winWidth=myWidth;
	winHeight=myHeight;
}

pos = 'right';
h_padding=10;
v_padding=10;
var pucStr;

function showBubble(e, str) {

	var relTarg;
	var bubble = document.getElementById('bubble');
	if (!e) var e = window.event;
	if (e.relatedTarget) relTarg = e.relatedTarget;
	else if (e.fromElement) relTarg = e.fromElement;
	b = bubble.style;
	if (pucStr != str) {
		document.getElementById('bubble').innerHTML=str;
		pucStr = str;
	}
	var mytop = is_top_available(bubble,e);
	var mybot = is_bot_available(bubble, e);
	var myright = is_right_available(bubble,e);
	var myleft = is_left_available(bubble,e);
	if (mybot)
	{
		bubble.ypos=e.clientY+document.body.scrollTop+v_padding;
	}
	if (mytop)
	{
		bubble.ypos=e.clientY+document.body.scrollTop-bubble.clientHeight-v_padding;
	}
	if (myright)
	{
		bubble.xpos=e.clientX+document.body.scrollLeft+h_padding;
	}
	if (myleft)
	{
		bubble.xpos=(e.clientX+document.body.scrollLeft);
	}
	if (bubble.xpos + bubble.clientWidth + 20 > winWidth) bubble.xpos = winWidth - bubble.clientWidth - 20;
	b.visibility='visible';
	if (str.length > 30) b.width = 180;
	else b.width = '';
	window.setTimeout("moveBox()", 10);
}

function hideBubble(e) {
	var bubble = document.getElementById('bubble');
	b = bubble.style;
	b.visibility='hidden';
}

var timeoutId=0;

function hideIt() {
	hideBubble();
}

/*********************************** SMS Text Remaining scripts ********************************/

function textRemaining(txt) {

	var iMaxLengthCharge = 70;
	var oSizeBox2 = window.document.getElementById("charCount");
	var smsCount = window.document.getElementById("txtSMSCount");
	var iSMSCount = 0;
	var msgLen = 0;
	
	msgLen = txt.length;
	
	iMaxLengthCharge = 160;
	if (msgLen > iMaxLengthCharge) iMaxLengthCharge = 153;
	
	if (msgLen > iMaxLengthCharge)
	{
	while (msgLen > iMaxLengthCharge)
	{
	iSMSCount += 1;
	msgLen -= iMaxLengthCharge;
	}
	iSMSCount += 1;
	}
	else
	{
	iSMSCount = 1;
	}
	oSizeBox2.value = iMaxLengthCharge - msgLen;
	smsCount.value = iSMSCount;
}