<!--
/* two parts in this file 												*/
/* one is custom functions and the other for dynamic html				*/

/* misc for custom functions */


/* BillingSetup   						*/
/* type = G / I							*/
/* invNo = invoice Number				*/
var billingDialog;
function openChargesBillingSetup(type, invNo){
	var w = 445, h = 380;

	if (document.all) {
	   /* the following is only available after onLoad */
	   w = document.body.clientWidth;
	   h = document.body.clientHeight;
	}
	else if (document.layers) {
	   w = window.innerWidth;
	   h = window.innerHeight;
	}


//alert(returnURL('/HMS/showBillingFolioDetail.cgi'))

    if (billingDialog && !billingDialog.closed) {
    	billingDialog.location = returnURL('/HMS/showBillingFolioDetail.cgi')  + '?mode=noframe&Action=Edit&Type=' + type + 'InvNo=' + invNo + '&' + Math.random();
    	billingDialog.focus();
    } else
    	billingDialog = window.open(returnURL('/HMS/showBillingFolioDetail.cgi')  
    		+ '?mode=noframe&Action=Edit&Type=' + type + '&InvNo=' + invNo + '&' + Math.random(), "", "width=" + 780 + "px  , height=" + 620  + "px , left=" + 20 +",top="+10+",toolbar=no,status=no, resizable=1");
     
    
}


/*	misc for dynamic html							*/
function getPleaseChooseOptionText(text)  {
	return getOption(text,"");
}

function getPleaseChooseOption()  {
	return getOption("Please choose","");
}

function getOption(text, value)  {
	newElem = document.createElement("option");
	newElem.text = text;
	newElem.value = value;
	return newElem;
}

function removeAllOption(chooser) {
	while(chooser.options.length) {
		chooser.remove(0);
	}
}

function removeOptions(chooser,fromIndex,toIndex) {
	if(chooser.options.length>=fromIndex) {
		for(i=fromIndex;i<toIndex+1 && i<chooser.options.length;i++) {
			chooser.remove(fromIndex);
		}
	}
}

function capitalLetterOnly(textfield,event) {
    var charCode = (event.charCode) ? event.charCode : ((event.keyCode) ? event.keyCode : 
        ((event.which) ? event.which : 0));
	if((charCode>=65 && charCode <=91) || (charCode>=97 && charCode <=123)) {
		textfield.value = textfield.value.toUpperCase() 
	}
}

function removeOptionsFromIndex(chooser,fromIndex) {
	j=chooser.options.length-fromIndex;
	for(i=0;i<j;i++) {
		chooser.remove(fromIndex);
	}		
}

function radioValue(radioButton)
{
	for (x = 0; x <= radioButton.length; x++)
	{
		if (radioButton[x].checked == true) return radioButton[x].value; 
	} 
         // if it didn't find anything, return the .value  (behaviour of single radio btn)
        return radioButton.value;
}

function setSelector(selector, code) {
	for(var i=0;i<selector.options.length && selector.options[i].value != code;i++);
		
	if(i==selector.options.length) {
		alert('js:fill selector ['+selector.name+':'+code+']error, pls contact system administrator')
		if ( selector.options.length>0 ) {
			selector.options[0].selected=true
		}
	}
	else {
		selector.options[i].selected=true
	}
}

function enableForm(form) {
	for(i=0;i<form.elements.length;i++) {
		form.elements[i].disabled=false
	}
}

function disableForm(form) {
	for(i=0;i<form.elements.length;i++) {
		form.elements[i].disabled=true
	}
}

function visi(nr)
{
	if (document.layers)
	{
		vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
		document.layers[nr].visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all[nr].style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(nr).style.visibility = vista;

	}
}

function blocking(nr)
{
	if (document.getElementById)
	{
		var elem=document.getElementById(nr)
		if(elem) {
			vista = (elem.style.display == 'none') ? 'block' : 'none';
			elem.style.display = vista;
		}
	}	
	else if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
}

function setDisplay(id, visible) {
	//IE only
	if(document.all)
		document.getElementById(id).style.display=(visible?'block':'none')
}


//-->
