// Common Function JavaScript Document



/**
 * This function is used to allow only numerics and 
 * control functions. If anyother key is pressed then 
 * it is neglected.
 *
 * @param	object	this is for cross browser compatibility for Mozilla browsers. This is the 'event' object.
 *
 * @return	boolean	true, if the key pressed is in between 0 to 9
 *					false, if the key pressed is not in range 0 to 9, or a control key.
 *
 */
function onlyNumerics(e){
	var e = e? e : window.event;
	if (!e) 
		return;
	
	var key = 0;
	if (e.keyCode) { 
		key = e.keyCode; 
	} // for moz/fb, if keycode==0 use 'which'
	else if (typeof(e.which)!= 'undefined') { 
		key = e.which; 
	} 
	//alert(key);
	if ( (key>=48 && key<=57) || key == 8 || key ==0 ){
		return (true) ;
	}
	else{
		return (false);	
	}
}
/**
* Select only one element
**/
function selectOnlyOne( element ) {
	var el = document.getElementsByName(element.name) ;
	for( i=0; i<el.length; i++ ){
		if ( el[i].value != element.value ) {
			el[i].checked = false;
		}
	}	
}
function reallyDel(str) {
	if ( !str ) {
		str = "Do you really want to DELETE?";
	}
	if ( confirm(str) ) {
		return true;
	}
	return false;
}

/**
* To toggle pdc in payment in/out module
**/

function togglePDC(obj) {
   if(obj.value == '1'){
        document.getElementById('check').className="show";
    }else{
        document.getElementById('check').className="hide";
    }  
}

/**
* To toggle payment mode in payment in/out module
**/

function togglePaymentMode(obj) {
   if(obj.value == '2'){
        document.getElementById('debit').className="show";
        document.getElementById('credit').className="hide";
    }else{
        document.getElementById('debit').className="hide";
        document.getElementById('credit').className="show";
    }
}


/**
* To Load account head depending on transaction type in payment in/out module
**/


//new added
var http_req_alerts;
var http_req_alerts1;

function updateAccountHead(type) {
	
	if(type == '2'){
        document.getElementById('debit').className="show";
        document.getElementById('credit').className="hide";
        document.getElementById('bill').className="show";
        document.getElementById('invoice').className="hide";
        document.getElementById('invoice_no').className="hide";       
        document.getElementById('bill_no').className="hide";                
        document.frmAdd.is_bill_receive[1].checked="true";
        document.frmAdd.is_invoice[1].checked="true";
    }else{
        document.getElementById('debit').className="hide";
        document.getElementById('credit').className="show";
        document.getElementById('invoice').className="show";
        document.getElementById('bill').className="hide";        
        document.getElementById('bill_no').className="hide";
        document.getElementById('invoice_no').className="hide";         
        document.frmAdd.is_bill_receive[1].checked="true";
        document.frmAdd.is_invoice[1].checked="true";
    }
	
    var cboType = document.getElementById("accounthead");
      
    cboType.options.length = 0;
    if(!type){
        cboType.options[0] = new Option("", "");	
        return null;
    }
    
    http_req_alerts = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_req_alerts = new XMLHttpRequest();
    }else if (window.ActiveXObject) { // IE
        try {
            http_req_alerts = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                http_req_alerts = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e) {}
        }
    }
    if (!http_req_alerts) {
        return false;
    } 
    var uri = "get-account-head.php?type=" + type;    
    http_req_alerts.onreadystatechange = loadAccountHead;
    http_req_alerts.open('GET', uri, true);
    http_req_alerts.send(null);
}

/**
* To Load account head depending on transaction type in payment in/out module
**/


function loadAccountHead(){
    var cboType = document.getElementById("accounthead");
   
   if(http_req_alerts.readyState==4){
   
        if (http_req_alerts.status == 200){
            var allThoseTypes = http_req_alerts.responseText;
           
            if(allThoseTypes){			
               
                cboType.options[0] = new Option("Select Account Head", "0");
             cboType.style.background ="#ffffff";
                var typeSplit =new Array();
                typeSplit = allThoseTypes.split(",");
            
             for (var i=0;i<typeSplit.length;i++){
                var tmpStr =typeSplit[i];
                if(tmpStr){
                    var tmpArray = new Array();
                    tmpArray = tmpStr.split("|");
                    var tmpName = tmpArray[0];
                    var tmpVal = tmpArray[1];
                   
                    if(tmpName){
                        cboType.options[i+1] = new Option(tmpName, tmpVal);                           
                    }
                }
            }           
            }
        }
    }else{        
        cboType.options[0] = new Option("Loading...", "");
          cboType.style.background = "#c3c3c3";
  }
}

/**
* To Toggle invoice in payment in/out module
**/


function toggleInvoice(obj) {
  	if(obj.value == '1'){
        document.getElementById('invoice_no').className="show";
    }else{
        document.getElementById('invoice_no').className="hide";
    }  
}

/**
* To Toggle bill receive in payment in/out module
**/


function toggleBill(obj) {
  	if(obj.value == '1'){
        document.getElementById('bill_no').className="show";
    }else{
        document.getElementById('bill_no').className="hide";
    }  
}

