debug=true;
//onerror = handleErrors;
var javascript_err_msg = "";

function handleErrors(errorMessage, url, line)
{
javascript_err_msg += "Javascript Error message: " + errorMessage + "\n";
javascript_err_msg += "URL: " + url + "\n";
javascript_err_msg += "Line #: " + line;
if (debug) alert(javascript_err_msg);
var newWindow = window.open("/cgi-bin/messages.cgi?action=send_error_message&message="+errorMessage+url+line,"Javascript Debug",'height=1,width=1,toolbar=no,directories=no,menubar=no,scrollbars=0,resizable=no,modal=yes');
newWindow.close();
return true
}

function OpenPopup4FormSubmit (form,w,h) {
if (!validateForm(form)) return false;

//Centering the Window
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
var newWindow = window.open("/en/templates/ask_popup.html","FormSubmit","height=200,width=400,left=" + wleft + ",top=" + wtop + ",toolbar=no,directories=no,menubar=no,scrollbars=1,resizable=no,modal=1");
if (newWindow == null) {
	alert("Attention!!!\n\nYour browser is blocking Pop-up Windows important the behaviour of the application!!!\nPlease deactivate your browser POP-UP Blocker for this site.");
	return 1;
}

newWindow.focus();
}

function DoWin(URL,WindowName,w,h) {
//Centering the Window
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
var newWindow = window.open(URL,WindowName,"resizable=no,left=" + wleft + ", top=" + wtop + ",width=" + w + ",height=" + h + ",scrollbars=1,alwaysRaised=yes,modal=yes");
if (newWindow == null) {
	alert("Attention!!!\n\nYour browser is blocking Pop-up Windows important the behaviour of the application!!!\nPlease deactivate your browser POP-UP Blocker for this site.");
	return 1;
}
newWindow.focus();
}

function DoObjectWin(URL,WindowName) {
//Opens a resizable modal window of the full screen width and 3/4 of height to be used with Object Item Manipulations.

maxWidth = window.screen.availWidth;
maxHeight = window.screen.availHeight*3/4;

//Centering the Window
wleft = (screen.width - maxWidth) / 2;
wtop = (screen.height - maxHeight) / 2;

if (window.showModalDialog) {
	var newWindow = window.showModalDialog(URL,WindowName,"dialogWidth:"+maxWidth+"px;dialogHeight:"+maxHeight+"px");
} else {
	var newWindow = window.open(URL,WindowName,'height='+maxHeight+',left=" + wleft + ", top=" + wtop + ",width='+maxWidth+',toolbar=no,directories=no,menubar=no,scrollbars=1,resizable=yes,modal=yes');
}

newWindow.focus();
}


function openFrame(location1,fileName1) {
eval("parent."+location1+".location.href=fileName1");
//Sentence above loads HTML from filename1 in Frame location1
}


function open1Frame(frameName,frameLocation) {
eval('window.frames[frameName].location = frameLocation');
}

function open2Frame(frameName1,frameLocation1,frameName2,frameLocation2) {
eval('window.frames[frameName1].location = frameLocation1')
eval('window.frames[frameName2].location = frameLocation2')
}


//This function works together with the call made from the template page like imgPreload("images/i1_2.gif,images/i2_2.gif,images/i3_2.gif")
//Useful for loading images used alot in a document
function imgPreload(imgP){

imgPrArrT=(imgP+",").split(",");
for (i in imgPrArrT){
   if (imgPrArrT[i]!=""){
	imgPrArr[imgPrArrT[i]]= new Image();
	imgPrArr[imgPrArrT[i]].src=imgPrArrT[i];
   }
}
}


function AskOpenWindow(message,destination,windowname,w,h) {
	if (!window.confirm(message)) {
		return false;
        }
	if (destination != "") {
		//Centering the Window
		wleft = (screen.width - w) / 2;
		wtop = (screen.height - h) / 2;
	    	var newWindow = window.open(destination,windowname,'left=' + wleft + ', top=' + wtop + ',height='+h+',width='+w+',toolbar=no,directories=no,menubar=no,scrollbars=1,resizable=no,modal=1');
		if (newWindow == null) {
			alert("Attention!!!\n\nYour browser is blocking Pop-up Windows important the behaviour of the application!!!\nPlease deactivate your browser POP-UP Blocker for this site.");
			return 1;
		}
	    	newWindow.focus();
	}
	return true;
}

function Ask(message,destination) {
	if (!window.confirm(message)) {
            return false;
        }
	if (destination != "") document.location=destination;
	return true;
}


function AskForm(message) {
	if (!window.confirm(message)) {
            return false;
        }
return true;
}


//Automatic Populate DropDown
function autoDropDown(control, controlToPopulate, ItemArray, GroupArray, ValueArray, FirstElement, FirstElementValue)
{

var myEle ;
var x ;
var i=1;
	//Setting for the first use ofthe function. The case where there's no parent
if (control == "root") {
		control = new Option();
		control.name = "root";
		control.value = 1;
	}
  // Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;

if (control.name == "firstChoice") {
    // Empty the third drop down box of any choices
	for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = new Option();
myEle.value = FirstElementValue ;
myEle.text = FirstElement;
controlToPopulate.options[0]=myEle;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box

for ( x = 0 ; x < ItemArray.length  ; x++ )
    if ( GroupArray[x] == control.value )
    	{
        myEle = new Option();
        myEle.value = ValueArray[x] ;
	//Fix for the HTML translation characters stored in the Database...
	myEle.text = ItemArray[x].replace(/\&#(\d+)\;/g,function($1) {return String.fromCharCode($1.match(/\d+/))});
        controlToPopulate.options[i]=myEle;
	i++;
    }
}

function activateDropdownSelectionFromArray(obj,form) {
//Picks key in the array and searchs for the drop-down element whose name matches, it then picks the key value and activates the dropdown to that value.
for (var key in obj) {
    control = document.forms[form].elements[key];

	for ( x = 0 ; x < control.options.length  ; x++ )
		if ( control.options[x].value == obj[key] )
	        control.options[x].selected = true;
}

}	

function activateDropdownSelectionFromVars(form,dropdown,dropdown_value) {
// For a dropdown item in a form, this function activates as selected the item whose dropdown value matches dropdown_value

control = document.forms[form].elements[dropdown];

if (control!=undefined)
	for ( x = 0 ; x < control.options.length  ; x++ )
		if ( control.options[x].value == dropdown_value )
	        control.options[x].selected = true;
}	


function fixWindow() {
var wsize = new checkWindowSize;
<!-- This is my desired width e height of the Total window considering that it is the visible window. Meanning that if FireFox the display area will be smaller because of the size of the Toolbars-->
var mywidth=852; 
var myheight=650;
<!-- these 2 values 12 & 125 are the diference between the (x,y) reads from CheckWindowsize and self.resizeto -->
wsize.x+=12;wsize.y+=125;

if (wsize.x<mywidth || wsize.y<myheight) {
	self.resizeTo(mywidth,myheight);
	//alert ("wsize.x="+wsize.x+" mywidth="+mywidth+"wsize.y="+wsize.y+" myheight="+myheight);
}
}


function adjustMenu() {
	<!-- 68 is the size of the small upper right logo plus a fex pixels -->
	var xpos=68;
	var ypos=50;
	var wsize = new checkWindowSize;
	<!-- Its the minnimum window size for the whole Menu -->
	absoluteMenuBar.moveTo(xpos,ypos);
}


function checkWindowSize (mywidth,myheight)
{
<!-- Returns object with (x,y) pair -->
var x,y;
if (self.innerHeight) // all except Explorer
{
	x = self.innerWidth;
	y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	x = document.documentElement.clientWidth;
	y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	x = document.body.clientWidth;
	y = document.body.clientHeight;
}
this.x=x;
this.y=y;
}

//Function to write content loaded from VERSION file
function displayVersion() {
	document.write(version);
}

function CleanDropDown(dropdown) {
control=document.getElementById(dropdown);

if (control!=undefined)
	control.length = 0;
	
}

function sleep(seconds) {
setTimeout('return',seconds*1000)
}

function removeDropdownOption(form,dropdown,element) {
control = document.forms[form].elements[dropdown];
control.options[element] = null;
}

function checkDoubleClickSelectItem(idx) {
if (idx==-1)
	return false
return true
}
