function Len(str)
{  return String(str).length;  }

function chkObject(theVal) {
	if (document.getElementById(theVal) != null) {
		return true;
	} else {
		return false;
	}
}


function AJAXInteraction(url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      // readyState of 4 signifies request is complete
      if (req.readyState == 4) {
	// status of 200 signifies sucessful HTTP call
        if (req.status == 200) {
          if (callback) callback(req.responseXML);
        }
      }
    }

    this.doGet = function() {
      // make a HTTP GET request to the URL asynchronously
      req.open("GET", url, true);
      req.send(null);
    }
}

//****************************************//
// PRINT
function sendGenerateRequest(str_guid) {
    var url = "/generator.asp?fn=" + str_guid; 
   	var ajax = new AJAXInteraction(url, validateGenerateRequest); 
    ajax.doGet();
}

function validateGenerateRequest(responseXML) {

   var msg = responseXML.
       getElementsByTagName("s")[0].firstChild.nodeValue;

   if (msg == "1") {

       var progressbar = document.getElementById("progress_bar");
	   var donetx = document.getElementById("done_tx");

       // set the style on the div to invalid

       progressbar.className = "hide";
	   donetx.className = "show";

    } else {

		// failed
       
    }  
}
//****************************************//

//****************************************//
// TRANSACTIONS
function sendGenerateRequestForTransactions(str_fileid) {
    var url = "code/?pg=transactions&fileid=" + str_fileid; 
   	var ajax = new AJAXInteraction(url, validateGenerateRequestForTransactions); 
    ajax.doGet();
}

function validateGenerateRequestForTransactions(responseXML) {

   var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

	   var fileid = responseXML.
       getElementsByTagName("id")[0].firstChild.nodeValue;

   if (msg == "1") {

       var progressbar = document.getElementById("progress_bar");
	   //var donetx = document.getElementById("done_tx");

       // set the style on the div to invalid

       //progressbar.className = "hide";
	   //donetx.className = "show";
	   
	   //progressbar.innerHTML = "http://www.billdo.si?pg=ebank&type=analyze&id=" + fileid
	   
	   window.location.replace( "?pg=ebank&type=analyze&id=" + fileid );

    } else {

		// failed
       
    }  
}
//****************************************//

//****************************************//
// REGISTRATION, COMPANY CHECK
function sendGenerateRequestForBSICheck() {

	document.regform.Send.disabled = true;
	var target = document.getElementById("f_entry_company_vat");
	if (target.value == "" ) {
		return false;
	} else {
	
		if (Len(target.value) == 8) {
	
			var progressbar = document.getElementById("indicator1");
				progressbar.className = "show";
			
			var progressbar = document.getElementById("regform_errormsg");
				progressbar.className = "hide";
			
		    var url = "../code/autocomplete.asp?pg=bsi&vat=" + encodeURIComponent(target.value); 
		   	var ajax = new AJAXInteraction(url, validateGenerateRequestForBSICheck); 
		    ajax.doGet();
		}
	}

}

function validateGenerateRequestForBSICheck(responseXML) {

   var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

   if (msg == "1") {
   
   		var str_cname = responseXML.
			getElementsByTagName("cname")[0].firstChild.nodeValue;
   		document.regform.company_name.value = str_cname;
		
		var str_caddress = responseXML.
			getElementsByTagName("caddress")[0].firstChild.nodeValue;
   		document.regform.company_address.value = str_caddress;
		
		var str_cpostcode = responseXML.
			getElementsByTagName("cpostcode")[0].firstChild.nodeValue;
   		document.regform.company_postcode.value = str_cpostcode;
		
		var str_ccity = responseXML.
			getElementsByTagName("ccity")[0].firstChild.nodeValue;
   		document.regform.company_city.value = str_ccity;
		
		var str_creg = responseXML.
			getElementsByTagName("creg")[0].firstChild.nodeValue;
   		document.regform.f_company_reg.value = str_creg;
		
		var str_cvatstatus = responseXML.
			getElementsByTagName("cvatstatus")[0].firstChild.nodeValue;
   		document.regform.f_company_is_vat.value = str_cvatstatus;
		
		if (str_cvatstatus == "1") {
			document.regform.company_is_vat_tx.value = "DA";
		} else {
			document.regform.company_is_vat_tx.value = "NE";
		}
		
		var f_source_data = document.getElementById("f_entry_company_vat");
		//var f_target_data = document.getElementById("f_company_vat");
		
		document.regform.f_company_vat.value = f_source_data.value;
		document.regform.Send.disabled = false;

       //var progressbar = document.getElementById("progress_bar");
	   //var donetx = document.getElementById("done_tx");

       // set the style on the div to invalid

       //progressbar.className = "hide";
	   //donetx.className = "show";
	   
	   //progressbar.innerHTML = "http://www.billdo.si?pg=ebank&type=analyze&id=" + fileid

    } else {

   		document.regform.company_name.value = "";
   		document.regform.company_address.value = "";
   		document.regform.company_postcode.value = "";
   		document.regform.company_city.value = "";
		document.regform.f_company_vat.value = "0";
		document.regform.f_company_reg.value = "0";
		document.regform.f_company_is_vat.value = "0";
		document.regform.company_is_vat_tx.value = "";
	
		// failed
		var progressbar = document.getElementById("regform_errormsg");
		progressbar.className = "show";
       
    }

	var progressbar = document.getElementById("indicator1");
	progressbar.className = "hide";  
}
//****************************************//

//****************************************//
// ADD COMPANY, VAT CHECK
function sendGenerateRequestForCompanyCheck() {

	var target = document.getElementById("search_by_vat");
	if (target.value == "" ) {
		return false;
	} else {
	
		if (Len(target.value) == 8) {
	
			var progressbar = document.getElementById("indicator_s1");
				progressbar.className = "show";
			
			var progressbar = document.getElementById("companyform_errormsg");
				progressbar.className = "hide";
			
		    var url = "code/autocomplete.asp?pg=bsi&vat=" + encodeURIComponent(target.value); 
		   	var ajax = new AJAXInteraction(url, validateGenerateRequestForCompanyCheck); 
		    ajax.doGet();
		}
	}

}

function validateGenerateRequestForCompanyCheck(responseXML) {

   var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

   if (msg == "1") {
   
   		var str_cname = responseXML.
			getElementsByTagName("cname")[0].firstChild.nodeValue;
   		document.companyform.company_name.value = str_cname;
		
		var str_caddress = responseXML.
			getElementsByTagName("caddress")[0].firstChild.nodeValue;
   		document.companyform.company_address.value = str_caddress;
		
		var str_cpostcode = responseXML.
			getElementsByTagName("cpostcode")[0].firstChild.nodeValue;
   		document.companyform.company_postcode.value = str_cpostcode;
		
		var str_ccity = responseXML.
			getElementsByTagName("ccity")[0].firstChild.nodeValue;
   		document.companyform.company_city.value = str_ccity;
		
		var str_creg = responseXML.
			getElementsByTagName("creg")[0].firstChild.nodeValue;
   		document.companyform.company_reg.value = str_creg;
		
		var str_cvatstatus = responseXML.
			getElementsByTagName("cvatstatus")[0].firstChild.nodeValue;
   		//document.regform.f_company_is_vat.value = str_cvatstatus;
		
		var f_source_data = document.getElementById("search_by_vat");
		
		if (str_cvatstatus == "1") {
			//document.companyform.company_is_vat_tx.value = "DA";
			document.companyform.company_vat.value = "SI" + f_source_data.value;
		} else {
			document.companyform.company_vat.value = "";
		}
		
		//var f_source_data = document.getElementById("f_entry_company_vat");
		//var f_target_data = document.getElementById("f_company_vat");
		
		//document.regform.f_company_vat.value = f_source_data.value;
		//document.regform.Send.disabled = false;

       //var progressbar = document.getElementById("progress_bar");
	   //var donetx = document.getElementById("done_tx");

       // set the style on the div to invalid

       //progressbar.className = "hide";
	   //donetx.className = "show";
	   
	   //progressbar.innerHTML = "http://www.billdo.si?pg=ebank&type=analyze&id=" + fileid

    } else {

		// failed
		var progressbar = document.getElementById("companyform_errormsg");
		progressbar.className = "show";
       
    }

	var progressbar = document.getElementById("indicator_s1");
	progressbar.className = "hide";  
}
//****************************************//

//****************************************//
// DELETE USER
function sysadmin_delete_user(str_user_id) {
	var url = "code/inline.asp?pg=users&type=delete&id=" + encodeURIComponent(str_user_id); 
   	var ajax = new AJAXInteraction(url, sysadmin_effect_user(str_user_id)); 
    ajax.doGet();
}

function sysadmin_effect_user(str_user_id) {
	Effect.Fade('row_user_' + str_user_id);
}
//****************************************//

//****************************************//
// RESET CUSTOMER DATA
function sysadmin_reset_customer(str_customer_id) {
	var url = "code/admin.asp?pg=customer&type=reset&id=" + encodeURIComponent(str_customer_id); 
   	var ajax = new AJAXInteraction(url, sysadmin_reset_customer_done(str_customer_id)); 
    ajax.doGet();
}

function sysadmin_reset_customer_done(str_customer_id) {
	//Effect.Fade('row_user_' + str_customer_id);
	window.location.replace( "?pg=home" );
}
//****************************************//

//****************************************//
// DOCUMENT PRINT QUEUE FUNCTIONS

function printqueue_addtoqueue_document(str_document_id, str_uid, str_cid) {

	var url = "code/admin.asp?pg=printqueue&type=add&id=" + encodeURIComponent(str_document_id) + "&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, printqueue_addtoqueue_document_done); 
    ajax.doGet();
	//printqueue_addtoqueue_document_done(str_document_id);
}

function printqueue_addtoqueue_document_done(responseXML) {
	//Effect.Fade('row_user_' + str_customer_id);
	//window.location.replace( "?pg=home" );
	
	var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

	if (msg == "1") {
	
		var str_id = responseXML.
	       getElementsByTagName("id")[0].firstChild.nodeValue;
		
		var str_uid = responseXML.
	       getElementsByTagName("uid")[0].firstChild.nodeValue;
		
		var str_cid = responseXML.
	       getElementsByTagName("cid")[0].firstChild.nodeValue;
		
		Effect.Fade('docdrag_' + str_id);
		printqueue_show(str_cid, str_uid);

	}
}

function printqueue_removefromqueue_document(str_document_id, str_uid, str_cid) {

	var url = "code/admin.asp?pg=printqueue&type=remove&id=" + encodeURIComponent(str_document_id) + "&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, printqueue_removefromqueue_document_done); 
    ajax.doGet();
	//printqueue_addtoqueue_document_done(str_document_id);
}

function printqueue_removefromqueue_document_done(responseXML) {

	var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

	if (msg == "1") {
	
		var str_id = responseXML.
	       getElementsByTagName("id")[0].firstChild.nodeValue;
		
		var str_uid = responseXML.
	       getElementsByTagName("uid")[0].firstChild.nodeValue;
		
		var str_cid = responseXML.
	       getElementsByTagName("cid")[0].firstChild.nodeValue;
		
		Effect.DropOut('printqueue_item_' + str_id);
		
		if(chkObject('docdrag_' + str_id)) {
			Effect.Appear('docdrag_' + str_id);
		}
	}
}

function printqueue_show(str_cid, str_uid) {

	document.getElementById("indicator_printqueue").className = "show";

	var url = "code/admin.asp?pg=printqueue&type=view&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, printqueue_show_pushhtml); 
    ajax.doGet();
}

function printqueue_show_pushhtml(responseXML) {

	var str_uid = responseXML.
       getElementsByTagName("uid")[0].firstChild.nodeValue;
	
	var str_cid = responseXML.
       getElementsByTagName("cid")[0].firstChild.nodeValue;
	
	var str_html = responseXML.
       getElementsByTagName("htmlresponse")[0].firstChild.nodeValue;

	document.getElementById('printqueue_container').innerHTML = str_html;
	new Effect.Highlight('printqueue_container', {startcolor:'#FFFFE0', endcolor:'#ffffff'});
	
	document.getElementById("indicator_printqueue").className = "hide";
	
	var str_itemcount = responseXML.
       getElementsByTagName("itemcount")[0].firstChild.nodeValue;
	   
	if (str_itemcount > "0") {
		document.getElementById("printqueue_toolbar").className = "show";
	}
}

//****************************************//

//****************************************//
// DOCUMENT EBANK QUEUE FUNCTIONS

function ebankqueue_addtoqueue_document(str_document_id, str_uid, str_cid) {

	var url = "code/admin.asp?pg=ebankqueue&type=add&id=" + encodeURIComponent(str_document_id) + "&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, ebankqueue_addtoqueue_document_done); 
    ajax.doGet();
	//printqueue_addtoqueue_document_done(str_document_id);
}

function ebankqueue_addtoqueue_document_done(responseXML) {
	//Effect.Fade('row_user_' + str_customer_id);
	//window.location.replace( "?pg=home" );
	
	var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

	if (msg == "1") {
	
		var str_id = responseXML.
	       getElementsByTagName("id")[0].firstChild.nodeValue;
		
		var str_uid = responseXML.
	       getElementsByTagName("uid")[0].firstChild.nodeValue;
		
		var str_cid = responseXML.
	       getElementsByTagName("cid")[0].firstChild.nodeValue;
		
		Effect.Fade('docdrag_' + str_id);
		ebankqueue_show(str_cid, str_uid);

	}
}

function ebankqueue_removefromqueue_document(str_document_id, str_uid, str_cid) {

	var url = "code/admin.asp?pg=ebankqueue&type=remove&id=" + encodeURIComponent(str_document_id) + "&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, ebankqueue_removefromqueue_document_done); 
    ajax.doGet();
	//printqueue_addtoqueue_document_done(str_document_id);
}

function ebankqueue_removefromqueue_document_done(responseXML) {

	var msg = responseXML.
       getElementsByTagName("status")[0].firstChild.nodeValue;

	if (msg == "1") {
	
		var str_id = responseXML.
	       getElementsByTagName("id")[0].firstChild.nodeValue;
		
		var str_uid = responseXML.
	       getElementsByTagName("uid")[0].firstChild.nodeValue;
		
		var str_cid = responseXML.
	       getElementsByTagName("cid")[0].firstChild.nodeValue;
		
		Effect.DropOut('ebankqueue_item_' + str_id);
		
		if(chkObject('docdrag_' + str_id)) {
			Effect.Appear('docdrag_' + str_id);
		}
	}
}

function ebankqueue_show(str_cid, str_uid) {

	document.getElementById("indicator_ebankqueue").className = "show";

	var url = "code/admin.asp?pg=ebankqueue&type=view&cid=" + encodeURIComponent(str_cid) + "&uid=" + encodeURIComponent(str_uid); 
   	var ajax = new AJAXInteraction(url, ebankqueue_show_pushhtml); 
    ajax.doGet();
}

function ebankqueue_show_pushhtml(responseXML) {

	var str_uid = responseXML.
       getElementsByTagName("uid")[0].firstChild.nodeValue;
	
	var str_cid = responseXML.
       getElementsByTagName("cid")[0].firstChild.nodeValue;
	
	var str_html = responseXML.
       getElementsByTagName("htmlresponse")[0].firstChild.nodeValue;

	document.getElementById('ebankqueue_container').innerHTML = str_html;
	new Effect.Highlight('ebankqueue_container', {startcolor:'#FFFFE0', endcolor:'#ffffff'});
	
	document.getElementById("indicator_ebankqueue").className = "hide";
	
	var str_itemcount = responseXML.
       getElementsByTagName("itemcount")[0].firstChild.nodeValue;
	   
	if (str_itemcount > "0") {
		document.getElementById("ebankqueue_toolbar").className = "show";
	}
}

//****************************************//

//****************************************//
// OTHER FUNCTIONS, NON-AJAX
function show_tooltip_confirmdelete(str_tooltip_id) {
	var tooltip_confirmdelete = document.getElementById("tooltip_delete_" + str_tooltip_id);
	var tooltip_options = document.getElementById("options_" + str_tooltip_id);

	tooltip_options.className = "hide";
	tooltip_confirmdelete.className = "show";
	
	//delayed return to original state
	setTimeout("hide_tooltip_confirmdelete('" + str_tooltip_id + "');", 2000);
}

function hide_tooltip_confirmdelete(str_tooltip_id) {
	var tooltip_confirmdelete = document.getElementById("tooltip_delete_" + str_tooltip_id);
	var tooltip_options = document.getElementById("options_" + str_tooltip_id);

	tooltip_confirmdelete.className = "hide";
	tooltip_options.className = "show";
}
//****************************************//

function show_divViaId(str_div_id) {
	Effect.BlindDown('details_data_' + str_div_id);
	document.getElementById("details_data_plus_" + str_div_id).className = "hide";
	document.getElementById("details_data_minus_" + str_div_id).className = "show";
}

function hide_divViaId(str_div_id) {
	Effect.BlindUp('details_data_' + str_div_id);
	document.getElementById("details_data_minus_" + str_div_id).className = "hide";
	document.getElementById("details_data_plus_" + str_div_id).className = "show";
}

function toggle_divViaId(str_div_id) {
	Effect.toggle(str_div_id, 'blind');
	//Effect.BlindDown('details_data_' + str_div_id);
	//document.getElementById("details_data_plus_" + str_div_id).className = "hide";
	//document.getElementById("details_data_minus_" + str_div_id).className = "show";
}

//****************************************//

var simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
 
function simpleEncode(valueArray,maxValue) {

	var chartData = ['s:'];
	  for (var i = 0; i < valueArray.length; i++) {
	    var currentValue = valueArray[i];
	    if (!isNaN(currentValue) && currentValue >= 0) {
	    chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * currentValue / maxValue)));
	    }
	      else {
	      chartData.push('_');
	      }
	  }
	return chartData.join('');
}

//****************************************//
