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) { 
 var urlGet = url + '?'; 
 for (i=0; i<document.forms[formName].elements.length; i++) {
  urlGet = urlGet + encodeURIComponent(document.forms[formName].elements[i].name) + '=' + encodeURIComponent(document.forms[formName].elements[i].value) + '&'; 
 }
 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


