function writeCookie() 
{ 
	var today = new Date(); 
	var the_date = new Date("December 31, 2023"); 
	var the_cookie_date = the_date.toGMTString(); 
	var the_cookie = "users_info=resolution: "+ screen.width +"x"+ screen.height; 
	
	the_cookie += " platform:"+navigator.platform;

	var L = navigator.plugins.length;
	the_cookie += " plugins: " + L.toString();
	for(var i=0; i<L; i++) {
		the_cookie += " " + navigator.plugins[i].name;
		the_cookie += "_";
		the_cookie += " " + navigator.plugins[i].filename;
		the_cookie += "_";
		the_cookie += " " + navigator.plugins[i].version;
	  
	}
	
	var the_cookie = the_cookie + ";expires=" + the_cookie_date; 
	document.cookie=the_cookie 


} 
//writeCookie(); 


function unhide (thiss) {

	var tr = document.getElementById('bank-transfer');
	tr.style.display = 'none';
	var tr = document.getElementById('paypal');
	tr.style.display = 'none';
	var tr = document.getElementById('moneybookers');
	tr.style.display = 'none';
	var tr = document.getElementById('western-union');
	tr.style.display = 'none';
	
	var tr = document.getElementById(thiss);
	tr.style.display = '';
	
}

function dynamicSelect()
{
	this.selects = new Array();
	
	this.addSelect = function(name)
	{
		this.selects[name] = new selectObj();
	}



	this.updateOptions = function(source, target)
	{
		var form = source.form;
		var target = form.elements[target];
		var value = source.options[source.selectedIndex].value;
		
		while(target.options.length) target.remove(0);
		
		if(!this.selects[source.name].options[value])
		{
			//alert('Invalid selection.'); //For debugging while you set it up
			return;
		}
		
		var data = this.selects[source.name].options[value].options;
		
		for(var x=0; x<data.length; x++)
		{
			try
			{
				target.add(data[x]);
			}
			catch(e)
			{
				target.add(data[x], null);
			}
		}
		
		target.selectedIndex = 0;
	}

}



function selectObj()
{
	this.options = new Array();
	
	this.addOption = function(value)
	{
		this.options[value] = new optionObj();
	}
}



function optionObj()
{
	this.options = new Array();
	
	this.createOption = function(name, value)
	{
		this.options[this.options.length] = new Option(name, value);
	}
}

function ajax_call(url, f)
{
     if (url != 0) {
        if (window.ActiveXObject) {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(f); } ;
        httpRequest.send(null);
      } else {
        document.getElementById(f).innerHTML = "";
      }
}

function processRequest(f)
{
  if (httpRequest.readyState == 4) {
    if(httpRequest.status == 200) {
      var insertion = document.getElementById(f);
      insertion.innerHTML = httpRequest.responseText;
    } else {
        alert("ERROR on a page loading"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}

function json_call(url) {
	$.getJSON(url,
        function(data){
          $.each(data, function(i,item){
            $("#"+i).html(item);
           });
        });
}

function checkAll(field) {
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field) {
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function chk_num() {
	if(document.num_list.check_ctr.checked==true){	
		for (i = 0; i < document.num_list.elements.length; i++)
			if (document.num_list.elements[i].type == 'checkbox')
				document.num_list.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.num_list.elements.length; i++)
			if (document.num_list.elements[i].type == 'checkbox')
				document.num_list.elements[i].checked = 0 ;
	}
}

function chk_holdback() {
	if(document.holdback_list.check_ctr.checked==true){	
		for (i = 0; i < document.holdback_list.elements.length; i++)
			if (document.holdback_list.elements[i].type == 'checkbox')
				document.holdback_list.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.holdback_list.elements.length; i++)
			if (document.holdback_list.elements[i].type == 'checkbox')
				document.holdback_list.elements[i].checked = 0 ;
	}
}

function chk_order() {
	if(document.order.check_ctr.checked==true){	
		for (i = 0; i < document.order.elements.length; i++)
			if (document.order.elements[i].type == 'checkbox')
				document.order.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.order.elements.length; i++)
			if (document.order.elements[i].type == 'checkbox')
				document.order.elements[i].checked = 0 ;
	}
}

function chk_pdf_more500() {
	if(document.more500.check_ctr.checked==true){
		for (i = 0; i < document.more500.elements.length; i++)
			if (document.more500.elements[i].type == 'checkbox')
				document.more500.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.more500.elements.length; i++)
			if (document.more500.elements[i].type == 'checkbox')
				document.more500.elements[i].checked = 0 ;
	}
}
function chk_pdf_less500() {
	if(document.less500.check_ctr.checked==true){
		for (i = 0; i < document.less500.elements.length; i++)
			if (document.less500.elements[i].type == 'checkbox')
				document.less500.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.less500.elements.length; i++)
			if (document.less500.elements[i].type == 'checkbox')
				document.less500.elements[i].checked = 0 ;
	}
}
function chk_pdf_paid() {
	if(document.paid.check_ctr.checked==true){
		for (i = 0; i < document.paid.elements.length; i++)
			if (document.paid.elements[i].type == 'checkbox')
				document.paid.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.paid.elements.length; i++)
			if (document.paid.elements[i].type == 'checkbox')
				document.paid.elements[i].checked = 0 ;
	}
}
function chk_acc_invoice() {
	if(document.account_invoice_list.check_ctr.checked==true){
		for (i = 0; i < document.account_invoice_list.elements.length; i++)
			if (document.account_invoice_list.elements[i].type == 'checkbox' && document.account_invoice_list.elements[i].disabled == 0)
				document.account_invoice_list.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.account_invoice_list.elements.length; i++)
			if (document.account_invoice_list.elements[i].type == 'checkbox')
				document.account_invoice_list.elements[i].checked = 0 ;
	}
}
function chk_refnum() {
	if(document.reference_number_list.check_ctr.checked==true){	
		for (i = 0; i < document.reference_number_list.elements.length; i++)
			if (document.reference_number_list.elements[i].type == 'checkbox')
				document.reference_number_list.elements[i].checked = 1 ;
	} else {
		for (i = 0; i <  document.reference_number_list.elements.length; i++)
			if (document.reference_number_list.elements[i].type == 'checkbox')
				document.reference_number_list.elements[i].checked = 0 ;
	}
}

function group_number_edit() {
	if (document.num_list.group_operation.value == 'delete') {
		return confirm("Really delete selected numbers?");
	}
	if (document.num_list.group_operation.value == 'return') {
		return confirm("Really return selected numbers?");
	}
} 

function group_invoice_more500_edit() {
	if (document.more500.group_operation.value == 'delete_invoice') {
		return confirm("Really delete invoice?");
	}
	if (document.more500.group_operation.value == 'send_invoice') {
		return confirm("Really send invoice on user email?");
	}
	if (document.more500.group_operation.value == 'recreate_invoice') {
		return confirm("Really re-create invoice?");
	}
	if (document.more500.group_operation.value == 'paid_invoice') {
		return confirm("Really set invoice as paid?");
	}
	if (document.more500.group_operation.value == 'set_paid') {
		return confirm("Really set invoice as paid?");
	}
	if (document.more500.group_operation.value == 'add_into_refnum') {
		return confirm("Really add selected invoices into reference numer table?");
	}
	
	return true;
}
function group_invoice_less500_edit() {	
	if (document.less500.group_operation.value == 'delete_invoice') {
		return confirm("Really delete invoice?");
	}
	if (document.less500.group_operation.value == 'send_invoice') {
		return confirm("Really send invoice on user email?");
	}
	if (document.less500.group_operation.value == 'recreate_invoice') {
		return confirm("Really re-create invoice?");
	}
	if (document.less500.group_operation.value == 'paid_invoice') {
		return confirm("Really set invoice as paid?");
	}
	if (document.less500.group_operation.value == 'set_paid') {
		return confirm("Really set invoice as paid?");
	}
	if (document.less500.group_operation.value == 'add_into_refnum') {
		return confirm("Really add selected invoices into reference numer table?");
	}
	return true;
} 
function group_invoice_paid_edit() {	
	if (document.paid.group_operation.value == 'delete_invoice') {
		return confirm("Really delete invoice?");
	}
	if (document.paid.group_operation.value == 'send_invoice') {
		return confirm("Really send invoice on user email?");
	}
	if (document.paid.group_operation.value == 'recreate_invoice') {
		return confirm("Really re-create invoice?");
	}
	if (document.paid.group_operation.value == 'paid_invoice') {
		return confirm("Really set invoice as paid?");
	}
	if (document.paid.group_operation.value == 'set_unpaid') {
		return confirm("Really set invoice as unpaid?");
	}
	if (document.paid.group_operation.value == 'add_into_refnum') {
		return confirm("Really add selected invoices into reference numer table?");
	}
	return true;
} 

function group_order_edit() {
	if (document.order.group_operation.value == 'delete') {
		return confirm("Really delete selected orders?");
	}
	if (document.order.group_operation.value == 'assign') {
		return confirm("Really assign numbers for selected orders?");
	}
}
function group_holdback_edit() {
	if (document.holdback_list.group_operation.value == 'delete') {
		return confirm("Really delete selected holdbacks?");
	}
	if (document.holdback_list.group_operation.value == 'set_paid') {
		return confirm("Really set selected holdbacks as PAID?");
	}
	if (document.holdback_list.group_operation.value == 'set_received') {
		return confirm("Really set selected holdbacks as RECEIVED?");
	}
	if (document.holdback_list.group_operation.value == 'set_holdback') {
		return confirm("Really set holdback on selected CLI?");
	}
}
function group_account_invoice() {
	if (document.account_invoice_list.group_operation.value == 'report_as_unpaid') {
		return confirm("Really report selected invoice as UNPAID?");
	}
}

function group_reference_number_edit() {
	if (document.reference_number_list.group_operation.value == 'send_reference_number') {
		return confirm("Really send selected reference numbers?");
	}
	if (document.reference_number_list.group_operation.value == 'delete_reference_number') {
		return confirm("Really delete selected reference numbers?");
	}
}

function showBox(text, obj, e) {
	node = document.getElementById('popBox');
	if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else isIE = false;
	if (navigator.appName == "Opera") isIE = true;

	isIE = false;
	
	if (isIE) { 
		x = e.x; y = e.y; 
	} else {
		x = e.clientX;
		y = e.clientY;
	}

	//navigator.appVersion.indexOf("MSIE 8")

	
	node.setAttribute('class','popBoxVisible');
	node.setAttribute('align','left');
	node.style.top = y + 10 + "px";
	node.style.left = x + 15 + "px";

	node.className='popBoxVisible';
	node.innerHTML = text;
}

function showBoxP(text, css_class, obj, e) {
	node = document.getElementById('popBox');
	if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else isIE = false;
	if (navigator.appName == "Opera") isIE = true;

	isIE = false;
	
	if (isIE) { 
		x = e.x; y = e.y; 
	} else {
		x = e.clientX;
		y = e.clientY;
	}

	//navigator.appVersion.indexOf("MSIE 8")

	
	node.setAttribute('class',css_class);
	node.style.top = y + 10 + "px";
	node.style.left = x + 15 + "px";

	node.className=css_class;
	node.innerHTML = text;
}

function hideBox() {	
	node = document.getElementById('popBox');
	node.setAttribute('class','popBoxInvisible');
	node.className='popBoxInvisible';
}

function showWindow(id, template, css_class, xp, yp, w, h) {
	node = document.getElementById(id);
	if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else isIE = false;
	if (navigator.appName == "Opera") isIE = true;

	isIE = false;
	
	node.setAttribute('class',css_class);
	node.className=css_class;
	
	//position
	if (xp >= 0) { 
		x = xp; 
	} else {
		x = (winSizeX() - w ) / 2;		
	}
	if (yp >= 0) { 
		y = yp; 
	} else {
		y = (winSizeY() - h ) / 2;
	}
	
	//size
	if (w >= 0) { 
		ww = w; 
	}
	if (h >= 0) { 
		hw = h; 
	}
	
	node.style.width = ww + "px";
	node.style.height = hw + "px";
	
	node.style.top = y + "px";
	node.style.left = x + "px";

	node.innerHTML = template;
}

function hideWindow(id, css_class) {	
	node = document.getElementById(id);
	node.setAttribute('class',css_class);
	node.className=css_class;
}

function winSizeX() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  return myWidth;
}
function winSizeY() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  return myHeight;
}

function showSelectBox(id, vis_class, sel_box_edit_id, height) {
	
	var selBoxEdit = document.getElementById(sel_box_edit_id + "_name");
	var selBox = document.getElementById(id);
	
	//find lower edge of edit widget:
	pos = findPosSelBox(selBoxEdit);
	
	if (selBoxEdit.offsetHeight) {
		  pos.top += selBoxEdit.offsetHeight;
	} else {
		pos.top += selBoxEdit.clientHeight;
	};

	if (document.all) {
		// IE
		selBox.style.posTop = pos.top;
		selBox.style.posLeft = pos.left;
	} else {
		// Mozilla
		selBox.style.position = 'absolute';
		selBox.style.top = pos.top + "px";
		selBox.style.left = pos.left + "px";
	};
	
	selBox.setAttribute('class',vis_class);
	selBox.className=vis_class;
}
function hideSelectBox(id, invis_class) {	
	node = document.getElementById(id);
	node.setAttribute('class',invis_class);
	node.className=invis_class;
	node.innerHTML = "";
}

function findPosSelBox(obj) {
	var pos = new Object;
	pos.left = 0;
	pos.top = 0;
	if (obj.offsetParent) {
		do {
			pos.left += obj.offsetLeft;
			pos.top += obj.offsetTop;
		
		} while (obj = obj.offsetParent);
	} 
	
	return pos;
};

function unhidehide (thiss) {
	if ((document.getElementById(thiss).className == "unhidden") || (document.getElementById(thiss).className == "")) {
		document.getElementById(thiss).className = "hidden";
	} else {
		document.getElementById(thiss).className = "unhidden"; 
	}
}

function rawurlencode (str) {
    str = (str+'').toString(); 
    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
