var xmlStyle;

date = new Date();
var startTime = date.getTime();
var recalcPriceNow = false;
var handleCol = false;

/* ###########################################################

   GUI Utilities
   
 * ########################################################### */

// Redraws VML GUI elements given a form name and field name
// Will select whatever the currently selected option is by highlighting it

function redrawGuiElements(form,field) {
try {
   // Get the field object
   var fieldObj = document.forms[form].elements[field];
   if (fieldObj.type == "select-one") {
      // Go through each possible field value
      for (var i=0;i<fieldObj.length;i++) {
         layerName = "guioption__" + form + "__" + field + "__" + fieldObj[i].value;
       //alert(layerName);
         var layer = getRawObject(layerName); // Get the VML object
         if (i == fieldObj.selectedIndex) {  // If this option is selected
            layer.strokeweight="2";
            layer.strokecolor="red";
         } else {
            layer.strokeweight="1";
            layer.strokecolor="black";            
         }
         getRawObject(layer).style.visibility="visible";
      }      
   } else if (fieldObj.type == "checkbox") {

      // Lets see what the current value is (on or off)
      // If it is on, then display the tick and hide the cross.
      // If it is off, then display the cross and hide the tick
      if (getFieldValue(form,field)) {
         // The check box is on
			
			nodisplay("guibutton__" + form + "__" + field + "__1");
//			display("guibutton__" + form + "__" + field + "__0");
			var theObj = getObject("guibutton__" + form + "__" + field + "__0");
		   if (theObj) { theObj.display = "inline"; }

						
         onLayer = "guioption__" + form + "__" + field + "__1";
         var onLayer = getRawObject(onLayer);
         onLayer.fill.opacity = "1.0";
         offLayer = "guioption__" + form + "__" + field + "__0";
         var offLayer = getRawObject(offLayer);
         offLayer.fill.opacity = "0.2";
         // This is a generic way of showing/hiding a div if it exists
         if (document.getElementById("UI_div_" + form + "_" + field)) {
            var myDiv = document.getElementById("UI_div_" + form + "_" + field);
            display(myDiv);
            
         }
         
      } else {
         // The check box is off
			
			nodisplay("guibutton__" + form + "__" + field + "__0");
			//display("guibutton__" + form + "__" + field + "__1");
			var theObj = getObject("guibutton__" + form + "__" + field + "__1");
		   if (theObj) { theObj.display = "inline"; }
			
         onLayer = "guioption__" + form + "__" + field + "__1";
         var onLayer = getRawObject(onLayer);
         onLayer.fill.opacity = "0.2";
         
         offLayer = "guioption__" + form + "__" + field + "__0";
         var offLayer = getRawObject(offLayer);
         offLayer.fill.opacity = "1.0";
         // This is a generic way of showing/hiding a div if it exists
         if (document.getElementById("UI_div_" + form + "_" + field)) {
            var myDiv = document.getElementById("UI_div_" + form + "_" + field);
            nodisplay(myDiv);
         }
         
      }
      
   }
}catch(e) {
       //alert('redrawGUIelements: ' + e.message + ' for ' + form + '.' + field);
   }
    
}

// Hides VML GUI elements given a form name and field name

function hideGuiElements(form,field) {
   // Get the field object
   var fieldObj = document.forms[form].elements[field];
   if (fieldObj.type == "select-one") {
      // Go through each possible field value
      for (var i=0;i<fieldObj.length;i++) {
         layerName = "guioption__" + form + "__" + field + "__" + fieldObj[i].value;
         getRawObject(layer).style.visibility="hidden";
      }      
   }  
}



/* ###########################################################

   General Utilities
   
 * ########################################################### */

/* ****************************************************************************
*  info (level,message)
*
*  Depending upon the level, will displayed the passed in message to the
*  client on the info layer. It will not display the same message twice in a row
*
*  level      : The severity level of the message. 1 - informational. 99 - alert
*  message    : The actual message to display
*
********************************************************************************/

var previousMessage = '';
var info_timerid = 0;
function info (level,message) {
   
   var theclass = "error";

   if (parseInt(level) < 11) { 
      theclass="info";
   } else if (parseInt(level) < 21) {
      theclass="warn";
   }
//	debugMessage('100', 'info', message);
   // If the current message is exactly the same as the previous message, then do nada
   var messageDiv = getRawObject("messageDiv");
	//If the level is less than 0 then we will strip remove the message from display
	if (level < 0) {
		
		if (message != previousMessage) {
				//Don't know why, but calling this twice in a row causes the message div to stay visible, hence the check
				fadeOut(messageDiv,0.5);
				messageDiv.filters.blendTrans.enabled = false;
		}
		previousMessage = message;
		hide("messageDiv");				
		return;

	}
	//If we can see the same message as is currently showing, do nada
	if ((message == previousMessage) && (messageDiv.visibility != "hidden")) {
      return;
   } else {
      messageDiv.className = theclass;
      previousMessage = message;
		messageDiv.innerHTML = message;
		if (level >= 1000) alert(message);
		if (info_timerid > 0) clearTimeout(info_timerid);
		show("messageDiv");
		info_timerid = setTimeout("fadeOut(messageDiv,2)",15000);
		//debugMessage('100', 'info', 'will show it');
   }

}



var previous_ring_message = '';
var ring_message_timerid = 0;
function ring_message (action,status,message) {
   
	var ring_message_div = getRawObject(action + "_ring_message");   
   var theclass = "error";
	if (status == 1) theclass="info";
	
   if (parseInt(status) < 0) { 
      //If the level is less than 0 then we will strip remove the message from display
		
		if (message != previous_ring_message) {
				// If the current message is exactly the same as the previous message, then do nada
				//Don't know why, but calling this twice in a row causes the message div to stay visible, hence the check
				fadeOutNoDisplay(action + "_ring_message",0.5);
				ring_message_div.filters.blendTrans.enabled = false;
		}
		previous_ring_message = message;
		nodisplay(ring_message_div);				
		return;

	} else {
		
		//If we can see the same message as is currently showing, do nada
		if ((message == previous_ring_message) && (ring_message_div.style.display == "block")) {
			return;
		} else {
		
			ring_message_div.className = theclass;
			previous_ring_message = message;
			replaceContent(ring_message_div,message);
			if (ring_message_timerid  > 0) clearTimeout(ring_message_timerid);
			display(ring_message_div);
			ring_message_timerid = setTimeout("fadeOutNoDisplay(" + action + "_ring_message,2)",10000);
			//debugMessage('100', 'info', 'will show it');
		}
	
	}

}


function fadeOutNoDisplay(obj,time) {
   
	obj.style.filter="blendTrans(duration=" + time + ")";
   // Make sure filter is not playing.
	if ((obj.display != "none")) {
	   obj.filters.blendTrans.Apply();
   	obj.style.display="none";
	   obj.filters.blendTrans.Play();
	}
	
}

function fadeInDisplay(obj,time) {
	
	obj.style.filter="blendTrans(duration=" + time + ")";
	// Make sure filter is not playing.
	if ((obj.style.display != "block")) {
		obj.filters.blendTrans.Apply();
		obj.style.display="block";
		obj.filters.blendTrans.Play();
	}
	
}

function debugMessage (level, func, message) {
   if (level) {
     dDiv.style.visibility = "visible";
     var dateObj = new Date();
     dForm.dField.value = (dateObj.getHours()) + ":" + (dateObj.getMinutes()) + ":" + (dateObj.getSeconds()) + " " + func + "\t\t" + message + "\r\n" + dForm.dField.value;
   }
}


function fadeOut(obj,time) {
   
	obj.style.filter="blendTrans(duration=" + time + ")";
   // Make sure filter is not playing.
	if ((obj.visibility != "hidden")) {
	   obj.filters.blendTrans.Apply();
   	obj.style.visibility="hidden";
	   obj.filters.blendTrans.Play();
	}
	
}

function fadeIn(obj,time) {
	
	obj.style.filter="blendTrans(duration=" + time + ")";
	// Make sure filter is not playing.
	if ((obj.visibility != "visible")) {
		obj.filters.blendTrans.Apply();
		obj.style.visibility="visible";
		obj.filters.blendTrans.Play();
	}
	
}


function loadBaseStyleJS () {
   
   document.write('<script Language="JavaScript" src="js/style' + global_style + '.js"><\/script>');
   document.write('<xml id="xslSelectOptionsList" type="text/xsl" src="styles/style' + global_style + '.xsl" />');
   document.write('<xml id="xmlStyleSource" src="styles/style' + global_style + '.xml" />');

}

function loadDesignXML () {

   var manage_script;
   manage_script = "manage.php";
   /* COMMENTED OUT 28/6/2005 by Andrew. I cant see what we need this for anymore and it effects oddysee domains.
   if (document.domain.substr(document.domain.length-15,document.domain.length) == 'gilletts.com.au') {
      //alert('calling local manage script');
      manage_script = "manage.php";
   } else {
      //alert('calling remote manage script');
      manage_script = "http://www.gilletts.com.au/design/manage.php";
   }      
   */

   document.write('<xml id="xmlDesign" src="' + manage_script + '?action=load&ring_design=' + global_ring_design + '&username=' + global_username + '&password=' + global_password + '" />');
}


/* ****************************************************************************
*  getZoomFactor (normalWidth,normalHeight,maxWidth,maxHeight)
*
*  Returns the appropriate zoom factor to use.
*
*  normalWidth  : At a zoom factor of 1, this is the normal width
*  normalHeight : At a zoom factor of 1, this is the normal height
*  maxWidth     : The maximum width we have work with
*  maxHeight    : The meximum height we have to work with
*  increment    : The increment the zoom factor supports. e.g. 0.25, 0.5, 1 etc
*
********************************************************************************/

function getZoomFactor (normalWidth,normalHeight,maxWidth,maxHeight,increment) {

   // We do this to ensure that the widths and heights passed in are in fact integers
   normalWidth  = parseFloat(normalWidth);
   normalHeight = parseFloat(normalHeight);
   maxWidth     = parseFloat(maxWidth);
   maxHeight    = parseFloat(maxHeight);

   // Lets look at the width first.
   // We do the plus one as we work down from this amount using the increment
   widthFactor = parseInt(maxWidth/normalWidth) + 1; 

   var calcWidth = normalWidth * widthFactor;

   while (calcWidth > maxWidth) {
      widthFactor = widthFactor - increment;
      calcWidth = parseInt(normalWidth * widthFactor);
   }

   //alert("Max: " + maxWidth + " caclWidth:" + calcWidth + " widthFactor:" + widthFactor);   

   // Now look at the height
   heightFactor = parseInt(maxHeight/normalHeight) + 1; 

   var calcHeight = normalHeight * heightFactor;

   while (calcHeight > maxHeight) {
      heightFactor = heightFactor - increment;
      calcHeight = parseInt(normalHeight * heightFactor);
   }

   //alert("Max: " + maxHeight + " caclHeight:" + calcHeight + " heightFactor:" + heightFactor);   

   // We always have to return the minimum zoom factor
   return (widthFactor < heightFactor) ? widthFactor : heightFactor;

}

/* ###########################################################

   Image resizing and draging

 * ########################################################### */

function movetopInlay(){

   var debug=0;

   if (event.button==1 && dragapproved){

      zoom  = getFieldValue("goForm","zoom");
      xmove = parseInt((oldClientX - event.clientX)/zoom);
      ymove = parseInt((oldClientY - event.clientY)/zoom);
      var layer = getRawObject(layerToMove);

      var fieldObj = document.forms["inlayForm"].elements["topinlayOffset"];

      if ((ymove < -1) && (fieldObj.selectedIndex < (fieldObj.length-1))) {
         // Move the inlay downwards
         incDropdown("inlayForm","topinlayOffset");         
         var newTop = fetchAttributeFromSelectedFormElement("inlayForm","topinlayOffset","height");
         setObjectTop(layer,newTop);
         oldClientX=event.clientX;
         oldClientY=event.clientY;
      } else if ((ymove > 1) && (fieldObj.selectedIndex > 0)) {
         // Move the inlay upwards
         decDropdown("inlayForm","topinlayOffset");
         var newTop = fetchAttributeFromSelectedFormElement("inlayForm","topinlayOffset","height");
         setObjectTop(layer,newTop);
         oldClientX=event.clientX;
         oldClientY=event.clientY;
      }

      positionLayerTop("resizer_tit_inlayForm_topinlayWidth",layer,0);
      positionLayerBottom("resizer_tib_inlayForm_topinlayWidth",layer,0);

            
      //debugMessage(debug,"movetopInlay","left:" + currentx + " top:" + currenty + " xmove:" + xmove + " ymove:" + ymove);

      return false;
   }
}


function movebottomInlay(){

   var debug=0;

   if (event.button==1 && dragapproved){

      zoom  = getFieldValue("goForm","zoom");
      xmove = parseInt((oldClientX - event.clientX)/zoom);
      ymove = parseInt((oldClientY - event.clientY)/zoom);
      var layer = getRawObject(layerToMove);

      var fieldObj = document.forms["inlayForm"].elements["bottominlayOffset"];

      if ((ymove < -1) && (fieldObj.selectedIndex > 0)) {
         // Move the inlay downwards
         decDropdown("inlayForm","bottominlayOffset");
         var newTop = fetchAttributeFromSelectedFormElement("inlayForm","bottominlayOffset","height");
         var baseHeight  = getObjectHeight("base");
         var inlayHeight = getObjectHeight("bottominlay");
         setObjectTop(layer,baseHeight - inlayHeight - newTop);
         oldClientX=event.clientX;
         oldClientY=event.clientY;
         //debugMessage(debug,"movebottomInlay","newTop:" + newTop + " baseHeight:" + baseHeight + " inlayheight:" + inlayHeight);
      } else if ((ymove > 1) && (fieldObj.selectedIndex < (fieldObj.length-1))) {
         // Move the inlay upwards
         incDropdown("inlayForm","bottominlayOffset");
         var newTop = fetchAttributeFromSelectedFormElement("inlayForm","bottominlayOffset","height");
         var baseHeight = getObjectHeight("base");
         var inlayHeight = getObjectHeight("bottominlay");
         setObjectTop(layer,baseHeight - inlayHeight - newTop);
         oldClientX=event.clientX;
         oldClientY=event.clientY;
         //debugMessage(debug,"movebottomInlay","newTop:" + newTop + " baseHeight:" + baseHeight + " inlayheight:" + inlayHeight);
      }

      positionLayerTop("resizer_bit_inlayForm_bottominlayWidth",layer,0);
      positionLayerBottom("resizer_bib_inlayForm_bottominlayWidth",layer,0);

      return false;
   }
}




var dragapproved=false;
var oldClientX,oldClientY,currentx,currenty,layerToMove,settingNumber;
var resizerForm,resizerField;


function drags(){
   
   resetTimer();
   if (!document.all)
      return
   //To allow for user freindly messages get the attribute info from whatever was clicked, if we have text, we will call tbe info function
   
	var message = event.srcElement.getAttribute("info");
   if (message) info(1,message);
	
   // Generic way of catching a person moving a setting. The id will be setting1, setting2 etc
   // This is why we do a substr match on it.
   if (event.srcElement.id.substr(0,17) == "selector_setting_") {
      settingNumber = parseFloat(event.srcElement.id.substr(17,2)); // the substring is the number
      layerToMove = "settingGroup" + settingNumber; 
      var layer   = getRawObject(layerToMove);
      dragapproved=true
      oldClientX = event.clientX;
      oldClientY = event.clientY;
      currentx = getObjectLeft(layer);
      currenty = getObjectTop(layer);
      document.onmousemove=moveSetting;
      
      SetGemstone(settingNumber);
      //opentab('options-gemstone');
        
   }

   if (event.srcElement.id.substr(0,14) == "selector_inlay") {
      var components  = event.srcElement.id.split("_");
      var inlayName = components[2];
      //If the inlay is on, let's open the options tab for it
      if(getFieldValue('inlayForm',inlayName + 'ShowInlay')) opentab('options-' + inlayName + 'inlay');

      // Catch them if they wish to move the top or bottom inlay up or down
      if (inlayName == "top" || inlayName == "bottom") {
         layerToMove = inlayName + "inlay"; 
         var layer   = getRawObject(layerToMove);
         dragapproved=true
         oldClientX = event.clientX;
         oldClientY = event.clientY;
         currentx = getObjectLeft(layer);
         currenty = getObjectTop(layer);

         if (inlayName == "top") {
            document.onmousemove=movetopInlay;
         } else {
            document.onmousemove=movebottomInlay;
         }
      
      }

   }

   if (event.srcElement.id.substr(0,8) == "resizer_") {
      dragapproved=true
      oldClientX = event.clientX;
      oldClientY = event.clientY;
      // Extract the form name and field name
      //                           0       1   2        3
      // id will be in the format: resizer_REF_FORMNAME_FIELDNAME
      var id = event.srcElement.id;
      var components  = id.split("_");
      resizerForm  = components[2];
      resizerField = components[3];
      document.onmousemove=genericLayerResizer;
   }
          
    // This particular check is to see if a GUI VML object has been clicked
   
   if (event.srcElement.id.substr(0,11) == "guioption__" || event.srcElement.id.substr(0,11) == "guibutton__") {
      // Extract the form name, field name and field value
      //                           0          1         2          3
      // id will be in the format: guioption__FORMNAME__FIELDNAME__VALUE
      var id = event.srcElement.id;
      var components  = id.split("__");
      var form = components[1];
      var field = components[2];
      var value = components[3];
      
      // Track the previous value of this option, to support the undo function
      trackFieldForUndo(form,field);

      setFieldValue(form,field,value);
      redraw();
      redrawGuiElements(form,field);
      
      // If it is a checkbox and on the inlayForm, then we need to switch to the
      // correct tab so that the redraw code is executed
      if (form == "inlayForm") {
         if (field == "topShowInlay") {
            opentab("options-topinlay");
         } else if (field == "middleShowInlay") {
            opentab("options-middleinlay");
         } else if (field == "bottomShowInlay") {
            opentab("options-bottominlay");
         }
         
      }      
      
   }   

   // If they click on the base image then we will set the tab to be the base options tab
   if (event.srcElement.id == "base_overlay") {
      opentab('options-base');
   }
   
//   window.status=event.srcElement.id;

}

function dragsFinished() {

   var debug=0;

   if (dragapproved) {
      //debugMessage(debug,"dragsFinished","Redrawing after mouse button up and drag approved");
      redraw();
      opentab(getFieldValue("UI_goForm","currentTab")); // We do this to set the GUI with the latest values
      dragapproved=false;
   }   

}


function keyPressed() {
   var debug = 0;   
   var kc    = event.keyCode;   

   if (!document.forms["UI_goForm"] || !document.forms["UI_goForm"].elements["currentTab"]) return;

   var tab   = getFieldValue("UI_goForm","currentTab");

   var pleaseRedraw = 0;

   resetTimer();

   // topinlay tab - up and down is for moving inlay. left and right for size of inlay
   // gemstone controls are left, right, up and down
   if (tab == "options-topinlay" || 
       tab == "options-bottominlay" || 
       tab == "options-middleinlay" ||
       tab == "options-gemstone"
       ) {
      
      switch (tab) {
         case "options-topinlay"    : var field = "topinlay";break;
         case "options-bottominlay" : var field = "bottominlay";break;
         case "options-middleinlay" : var field = "middleinlay";break;
         case "options-gemstone"    : var field = "gemstone"; var gNum = getFieldValue("UI_gemstoneForm","suffix");;break;
      }
      
      
      switch (kc) {
         case 38:  // up
         case 104: // up keypad
            
            if ((field == "topinlay") || (field == "bottominlay")) {
               var fieldObj = document.forms["inlayForm"].elements[field + "Offset"];
               if ( (field == "topinlay") && (fieldObj.selectedIndex > 0) ) {
                  decDropdown("inlayForm",field + "Offset"); pleaseRedraw = 1;
               } else if ((field == "bottominlay") && (fieldObj.selectedIndex < (fieldObj.length-1)) ) {
                  incDropdown("inlayForm",field + "Offset"); pleaseRedraw = 1;
               }
            } else if (field == "gemstone") {
               var oldValue = getFieldValue("gemstoneForm","positionTopGemstone" + gNum);
               var newValue = parseInt(oldValue) - 1;
               trackFieldForUndo("gemstoneForm","positionTopGemstone" + gNum);
               setFieldValue("gemstoneForm","positionTopGemstone" + gNum,newValue);
               pleaseRedraw = 1;
            }
            
            
            break;

         case 40: // down
         case 98: // down keypad

            if ((field == "topinlay") || (field == "bottominlay")) {
               var fieldObj = document.forms["inlayForm"].elements[field + "Offset"];
               if ( (field == "topinlay") && (fieldObj.selectedIndex < (fieldObj.length-1)) ) {  
                  incDropdown("inlayForm",field + "Offset"); pleaseRedraw = 1;            
               } else if ((field == "bottominlay") && (fieldObj.selectedIndex > 0)) {
                  decDropdown("inlayForm",field + "Offset"); pleaseRedraw = 1;
               }
            } else if (field == "gemstone") {
               var oldValue = getFieldValue("gemstoneForm","positionTopGemstone" + gNum);
               var newValue = parseInt(oldValue) + 1;
               trackFieldForUndo("gemstoneForm","positionTopGemstone" + gNum);
               setFieldValue("gemstoneForm","positionTopGemstone" + gNum,newValue);
               pleaseRedraw = 1;
            }
            
            break;

         case 37:  // left
         case 100: // left keypad

            if ((field == "topinlay") || (field == "bottominlay") || (field == "middleinlay")) {            
               var fieldObj = document.forms["inlayForm"].elements[field + "Width"];
               if (fieldObj.selectedIndex > 0) {
                  decDropdown("inlayForm",field + "Width");pleaseRedraw = 1;
               }
            } else if (field == "gemstone") {
               var oldValue = getFieldValue("gemstoneForm","positionLeftGemstone" + gNum);
               var newValue = parseInt(oldValue) - 1;
               trackFieldForUndo("gemstoneForm","positionLeftGemstone" + gNum);
               setFieldValue("gemstoneForm","positionLeftGemstone" + gNum,newValue);
               pleaseRedraw = 1;
            }
            
            break;

         case 39:  // right
         case 102: // right keypad

            if ((field == "topinlay") || (field == "bottominlay") || (field == "middleinlay")) {            
               var fieldObj = document.forms["inlayForm"].elements[field + "Width"];
               if (fieldObj.selectedIndex < (fieldObj.length-1)) {
                  incDropdown("inlayForm",field + "Width");pleaseRedraw = 1;            
               }
            } else if (field == "gemstone") {
               var oldValue = getFieldValue("gemstoneForm","positionLeftGemstone" + gNum);
               var newValue = parseInt(oldValue) + 1;
               trackFieldForUndo("gemstoneForm","positionLeftGemstone" + gNum);
               setFieldValue("gemstoneForm","positionLeftGemstone" + gNum,newValue);
               pleaseRedraw = 1;
            }

            break;

      }
      
   }

   if (pleaseRedraw) {
     //debugMessage(debug,"keyPressed","Redrawing after a key has been pressed: " + kc + " on tab:" + tab);
     redraw();
     opentab(getFieldValue("UI_goForm","currentTab")); // We do this to set the GUI with the latest values
   }
   
   
   //debugMessage(debug,"keyPressed","key has been pressed: " + kc + " on tab:" + tab);

}

function resetTimer () {
   var date = new Date();
   startTime = date.getTime();
}

function elapsedTime () {
   var presenttime,elapsed,selasped,melapsed;
   present = new Date();
   presenttime = present.getTime();
   elapsed = (presenttime - startTime) / 1000;
   melapsed  = Math.floor(elapsed / 60);
   selapsed  = Math.floor(elapsed -(melapsed * 60));
   return(selapsed);
}


function scroll(obj){
	var theObj = getRawObject(obj);
	var theDiv = getRawObject("help-generalhelp_div");
	if (theObj && theDiv) theDiv.scrollTop=theObj.offsetTop;
}

function sendChickTo(tolayer, toposition, offset) {
	
	if (toposition == "top") {
		
		positionLayerRealTop ("helpchick", tolayer, offset);
		positionLayerRealXCenter ("helpchick", tolayer, 0);
	
	} else if (toposition == "bottom") {
	
		positionLayerRealBottom ("helpchick", tolayer, offset);
		positionLayerRealXCenter ("helpchick", tolayer, 0);
			
	} else if (toposition == "left") {
	
		positionLayerRealLeft ("helpchick", tolayer, offset);
		positionLayerRealYCenter ("helpchick", tolayer, 0);
	
	} else {
		
		positionLayerRealRight ("helpchick", tolayer, offset);
		positionLayerRealYCenter ("helpchick", tolayer, 0);				
	}

}

function sendChickHome() {
	sendChickTo("hcIcon","bottom",-20);
}
var maximisehelp = false;

function toggleHelp() {
	
	if (maximisehelp) {
		maximisehelp = false;
		nodisplay("minimise_help_button");
		display("maximise_help_button");
	} else {
		maximisehelp = true;
		nodisplay("maximise_help_button");
		display("minimise_help_button");
	}
	resizeLayers();
	
}

function toggleRuler() {
	
   if (rulerverticle.style.visibility == "visible") {
      rulerverticle.style.visibility = "hidden";
   } else {
      rulerverticle.style.visibility = "visible";
   }
   	
}

/* ###########################################################

   Finger Sizes

 * ########################################################### */


function setFingerSizes() {

var brsizes = Array('H','H.5','I','I.5','J','J.5','K','K.5','L','L.5','M','M.5','N','N.5','O','O.5','P','P.5','Q','Q.5','R','R.5','S','S.5','T','T.5','U','U.5','V','V.5','W','W.5','X','X.5','Y','Y.5','Z','Z.5','Z+1','Z+1.5','Z+2','Z+2.5','Z+3','Z+3.5','Z+4','Z+4.5');
var eusizes = Array('47','47','48','49','49','50','50','51','51','52','52','53','54','55','55','56','56','57','57','58','59','60','60','61','61','62','62','63','63','64','65','65','66','66','67','68','69','69','70','70','71','71','72','72','73','73');
var ussizes = Array('4','4.25','4.5','4.75','5','5.25','5.5','5.75','6','6.25','6.5','6.75','7','7.25','7.5','7.75','7.75','8','8.25','8.5','8.75','9','9.25','9.5','9.75','10','10.25','10.5','10.75','11','11.25','11.5','11.75','12','12.25','12.5','12.75','13','13.25', '13.5','13.75', '14','14.25', '14.5','14.75', '15');

var euSizeCountries = Array('EUR','DEM','FRF','ITL','CHF','ATS','BEF','DKK','ESP','NLG','FIM','HUF','ISK','LUF','NOK','PLZ','PTE','ROL','RUB','SAR','SDD','SEK','CZK');
var usSizeCountries = Array('USD','JPY','CAD','ZAR','ARS','BRL','CLP','CNY','INR','IDR','ILS','JMD','JOD','KRW','MXP','THB','NGN','XOF');

   if (inArray(cur_isocode,usSizeCountries)) {
      loadDropdown("UI_goForm","UI_ringSize",ussizes,ussizes);
   } else if (inArray(cur_isocode,euSizeCountries)) {
      loadDropdown("UI_goForm","UI_ringSize",ussizes,eusizes);
   } else {
      loadDropdown("UI_goForm","UI_ringSize",ussizes,brsizes);
   }

}

function inArray(val,arr) {
  for(i=0;i<arr.length;i++) {
    if(val.toLowerCase() == arr[i].toLowerCase()){ return true; }
  }
  return false;
}

// Global stuff to set that must be done last

document.onmousedown=drags;
document.onmouseup=dragsFinished;

document.onkeydown=keyPressed;
