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 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 == 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";

	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';
}
