var div_id;

function load_ajax_loader(url,bla,thisvalue,div) {
 
 var txt=document.getElementById(div); 
 txt.innerHTML='<p style="text-align: center;"><img src="javascript/ajax-loader.gif" alt="Loading..." title="Loading..."></p>';

 // alert(url);
 
 load_ajax(url,bla,thisvalue,div); 
 return true; 
} 
 
function load_ajax(url,bla,thisvalue,div)
{
if (bla != "" ) {
	url = url+"?"+bla+"="+thisvalue;
}
	div_id=div;
	if (window.XMLHttpRequest)
	{
		try{
			req= new XMLHttpRequest();
		}
		catch (e) {
			req = false;
		}
		}else if(window.ActiveXObject) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				req = false;
			}
		}
	}
	if (req) {
		req.onreadystatechange=processReqChangeX;
		req.open("GET", url, true);
		req.send(null);
	}
}
function processReqChangeX()
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			window.document.getElementById(div_id).innerHTML = req.responseText;
		}
	}
}

function CheckFormFields (formName, doHighlight) {
 var MyIsOk = 1; 
 for (i=0; i<document.forms[formName].elements.length; i++) {
  if (document.forms[formName].elements[i].value == '') {
   if (doHighlight) {
    var styleObj = getStyleObject(document.forms[formName].elements[i].name);
    styleObj.border = '1px solid red';
   } 
   MyIsOk = 0;
  } // if
 } // for
 return MyIsOk;
 
} // CheckFormFields

function CheckSetOfFormFields (formName, setOfFields, doHighlight) {
 var styleObj;
 MyIsOk = 1; 
 for (i=0; i<setOfFields.length; i++) {
  if (document.forms[formName].elements[setOfFields[i]].value === '') {
   MyIsOk = 0; 
   if (doHighlight) {
    styleObj = getStyleObject(document.forms[formName].elements[setOfFields[i]].name);
    styleObj.border = '1px solid red';
   } 
   
  } // if
 } // for

  return MyIsOk;
 
 
} // CheckFormFields



function GetFormByAjax (url,formName, noQm, valUncheckedChBx) { 
 if (noQm) var urlGet = ''; else var urlGet = url + '?'; 
 for (i=0; i<document.forms[formName].elements.length; i++) {
  urlGet = urlGet + encodeURIComponent(document.forms[formName].elements[i].name) + '=';
  if (document.forms[formName].elements[i].type == "checkbox") {
   if (document.forms[formName].elements[i].checked)
    urlGet = urlGet + encodeURIComponent(document.forms[formName].elements[i].value);
   else	
    urlGet = urlGet + encodeURIComponent(valUncheckedChBx);
  } else
   urlGet = urlGet + encodeURIComponent(document.forms[formName].elements[i].value);
  urlGet = urlGet + '&'; 
 }
 return urlGet;
 
} // function GetFormByAjah

function FormResultByAjax (url, formName, div) {
   load_ajax_loader(GetFormByAjax(url, formName), '', '',div);
} // function GetFormByAjah


function load_window_open(url, div, theW, theH, show, scrollOff, topDoc, lowIfMore) {

 if (lowIfMore) {
 var inH; 
 if (top.window.innerHeight)
  inH = top.window.innerHeight;
 else if (top.document.documentElement.clientHeight) 
  inH = top.document.documentElement.clientHeight;  
 if (theH > (inH - 50) && inH) theH = inH - 50; 
 }
 
 
 if (topDoc) {
  if (show) {
  var ele = topDoc.getElementById(show);
  ele.style.visibility = 'visible';
  ele.display = "";
 } 
 var closeDiv = topDoc.getElementById('winOpenClose' + show);
 if (closeDiv) {
  closeDiv.style.left = '50%'; 
  closeDiv.style.marginLeft = (Math.round(theW/2) - 20) + 'px';
 }
 
 } else { // no top doc
 
 if (show) {
  ShowAnyDiv(show);
  DisplayDiv(show);
 } 
 var closeDiv = document.getElementById('winOpenClose' + show);
 if (closeDiv) {
  closeDiv.style.left = '50%'; 
  closeDiv.style.marginLeft = (Math.round(theW/2) - 20) + 'px';
 } 
 }
 load_ajax_loader('iframe_load.php?load=' + escape(url) + '&theW=' + theW + '&theH=' + theH + '&scrollOff=' + scrollOff, '','', div, topDoc);
} // function load_window_open


function ShowAnyDiv(who)
{

    var menuId = who;
    if(changeObjectVisibility(menuId, 'visible')) {
	return true;
    } else {
	return false;
    }
}


function ChangeDivClass (who, newClass) {
   var theObject = document.getElementById(who);
   if (theObject)
    theObject.className = newClass; 
}


function ShowAnyDivPos(who, Xpos, Ypos)
{

    var menuId = who;
	var theObject = getStyleObject(who);
	
    if(changeObjectVisibility(menuId, 'visible')) {
	 theObject.left = Xpos.toString() + 'px';
	 theObject.top = Ypos.toString() + 'px';
	 return true;
    } else {
	return false;
    }
}

function HideAnyDiv(who, Xoffset, Yoffset)
{
 var id = who;
 if (who) {
  changeObjectVisibility(id, 'hidden');
  // document.forms['test'].debug.value = 'HideMenu ' + id;
 }  
} // function HideMenu

function DisplayDiv(who) {
 var which = getStyleObject (who); 
 which.display = "";
}

function UndisplayDiv(who) {
 var which = getStyleObject (who); 
 which.display = "none";
}


// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object s style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this will not find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we could not find the object, so we can not change its visibility
	return false;
    }
} // changeObjectVisibility


 function ConstructAjaxString (theForm, inElement) {
   var theString = ''; 
   for (i = 0; i < document.forms[theForm].elements.length; i++) 
    theString = theString + document.forms[theForm].elements[i].name +  '=' + document.forms[theForm].elements[i].value + '&';  
  inElement.value = theString; 
 } // function ConstructAjaxString
 
 function write2div (theDiv, theCode) {
 var txt=document.getElementById(theDiv); 
 txt.innerHTML = theCode;
} // function write2div

function html2divAfter (theDiv, theCode) {
 var txt=document.getElementById(theDiv); 
 txt.innerHTML = txt.innerHTML + theCode;
} // function html2divAfter

function html2divBefore (theDiv, theCode) {
 var txt=document.getElementById(theDiv); 
 txt.innerHTML = theCode + txt.innerHTML;
} // function html2divBefore


function number_format (number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/number_format    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
} 
