
/* begin common FastDeploy functions */
	function chkThis(field)
	{
	     field.value = formatMAC(field.value);
	
	     if(field.createTextRange)
	     {
	          setCaretAtEnd(field);
	     }
	}
	
	function chkPK(field)
	{
	     field.value = formatPK(field.value);
	
	     if(field.createTextRange)
	     {
	          setCaretAtEnd(field);
	     }
	}
	
	function chkThisIP(field)
	{
	     field.value = formatIP(field.value);
	
	     if(field.createTextRange)
	     {
	          setCaretAtEnd(field);
	     }
	}
	
	function formatMAC(mac){
	     mac = mac.replace(/\W/g, "");
	
	     if(mac.length >= 2){
	          mac = mac.substring(0, 2) + '-' + mac.substring(2);
	
	         	if(mac.length >= 5){
	               mac = mac.substring(0, 5) + '-' + mac.substring(5);
	               
	               if(mac.length >= 8){
	               	mac = mac.substring(0, 8) + '-' + mac.substring(8);
	               	
	               	if(mac.length >= 11){
	               		mac = mac.substring(0, 11) + '-' + mac.substring(11);
	               		
	               		if(mac.length >= 14){
	               			mac = mac.substring(0, 14) + '-' + mac.substring(14);
	
	               			if(mac.length > 17)
	              	 			{
	                    			mac = mac.substring(0, 17);
	               			}
	          		}
	
	     		}
	     	    }
	          }
	     }
	
	     return mac;
	}
	
	function formatPK(pk){
	     pk = pk.replace(/\W/g, "");
	
	     if(pk.length >= 5){
	          pk = pk.substring(0, 5) + '-' + pk.substring(5);
	
	         	if(pk.length >= 11){
	               pk = pk.substring(0, 11) + '-' + pk.substring(11);
	               
	               if(pk.length >= 17){
	               	pk = pk.substring(0, 17) + '-' + pk.substring(17);
	               	
	               	if(pk.length >= 23){
	               		pk = pk.substring(0, 23) + '-' + pk.substring(23);
	               		
	               		if(pk.length > 29){
	               			pk = pk.substring(0, 29);
	               		
				}
	     		}
	     	    }
	          }
	     }
	
	     return pk;
	}
/* end common FastDeploy functions */
/* begin common Dojo functions */
	function DisplayTreeContent(){
	    this.update = function(message) {
	        var clickedTreeNode = message.node;

			var docPane = dojo.widget.byId("docpane");
			var file = clickedTreeNode.object;
			if (!file){
				docPane.setContent(""); // put an error message here?
			}else{
				docPane.setUrl(file);
			}
	    };
	    clickedTreeNode = "";
	}
	
	function getOS(id) {
		var idStr = "{\"id\":" + id + "}";
		request = {'action' : 'getOS', 'data' : idStr};
		dojo.io.bind({
			url: "add.php",
			handler: showArticle,
			mimetype: "text/json",
			content: request
		});
	}

	var myVeryCoolObject = null;
	/* var bindArgs = {
		url:  "debug.php",
		type: "text/json",
		load: function(type, data, evt){
			myVeryCoolObject = data;
	}
	};
	dojo.io.bind(bindArgs);
	*/
	function initAjax() {
        		dojo.event.connect(dojo.byId("loadIt"), "onclick", "loadRemotely");
    	}
	var displayer = new DisplayTreeContent();
          
	var nodeSelectionTopic = dojo.event.topic.getTopic("nodeSelected");

	nodeSelectionTopic.subscribe(displayer, "update");

	// display custom loadError or use built in
	// works best from live server instead of filesystem
	function contentLoadError(e){
		var chkbox = dojo.byId("defaultLoadError");
		if(chkbox && chkbox.checked){
			// use built in
			return;
		}
		e.preventDefault(); // or e.returnValue = false;
		var pane = dojo.widget.byId('docpane')
		pane.setContent("Custom Loaderror goes here<br/><img src='images/x.gif' style='float:left;'/> file not found");
		dialogHandler();// turn off loading dialog
	}

	// display custom Error(Content java/javascript eval error) or use built in method
	function contentExecError(e){
		var chkbox = dojo.byId("defaultEvalError");
		if(chkbox && chkbox.checked){
			// use built in
			return;
		}
		e.preventDefault();
		alert('Oops! error occured:'+arguments[0]);
	}

	// display loading dialog or use built in "Loading..." message
	function contentDownloadStart(e){
		var chkbox = dojo.byId("defaultLoadInfo");
		if(chkbox && chkbox.checked){
			// use built in
			return;
		}
		dialogHandler(e, true);
	}

	// show / hide loading dialog
	function dialogHandler(e, show){
		var dialog = dojo.widget.byId("statusDialog");
		if(show){
			e.preventDefault();
			dialog.show();
			return;
		}
		dialog.hide();
	}
	// create a variable that closures can relate to in addOnLoad and handleSubmits
        // that way we dont have to call dojo.widget.byId multiple times
        var cpane = null;

        // set up a listener for form submits inside cpane
        dojo.addOnLoad(function(){
            // set the reference for our ContentPane widget to the variable we created before
            cpane = dojo.widget.byId('docpane');
   
            // connect a event listener to contentpane domNode
            // If IE had decent DOM we could just settle with connecting a onsubmit event
            // and listen to that when it bubbled up to cpane.domNode,
            // but onsubmit events doesn't bubble in IE
            // so we are forced to iterate through document.forms
            // and create a new FormBind listener each time we load a new content
            dojo.event.connect(cpane, 'onLoad', 'setUpForm');

            // on page initial load cpane onLoad isn't called
            setUpForm();

        });


        // handle form submits
        function setUpForm(){

            // find out if any of document.forms is a ancestor of cpane.domNode
            var node = null;
            for(var i = 0; i < document.forms.length; i++){
                if(dojo.dom.isDescendantOf(document.forms[i],cpane.domNode)){
                    node = document.forms[i];
                    break;
                }
            }

            if(node){
                // create a new FormBind object
                new dojo.io.FormBind({
                    // evt.target is our formNode
                    formNode: node,
                    load: function(load, data, e) {
                        // relay the server response to cpane.setContent
                        cpane.setContent(data);
                    }
                });
            }
        };
/* end common Dojo functions */
function dispHandle(obj) 
{
	if (obj.style.visibility == "hidden")
		obj.style.visibility = "visibile";
	else
		obj.style.visibility = "hidden";
}

function visi(nr)
{
	if (document.layers)
	{
		vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
		document.layers[nr].visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all[nr].style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(nr).style.visibility = vista;

	}
}

function blocking(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function flipit(nr,ns) { 
	/*
	 * handles flipping display of DIV layers by SELECT fields
	 */
	if (document.all[ns].value == 'static') {	
		blocking('staticset'); 
	}	
	else if (document.all[ns].value == 'dynamic') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
	else if (document.all[ns].value == '') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function flipit_hd(nr,ns) { 
	/*
	 * handles flipping display of DIV layers by SELECT fields
	 */
	if (document.all[ns].value == 'setup') {	
		blocking('hd_setup'); 
	}	
	else if (document.all[ns].value == 'auto') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
	else if (document.all[ns].value == '') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function flipit_hd_scheme(nr,ns) { 
	/*
	 * handles flipping display of DIV layers by SELECT fields
	 */
	if (document.all[ns].value == 'standard') {	
		blocking('hd_setup'); 
	}	
	else if (document.all[ns].value == 'auto') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
	else if (document.all[ns].value == '') { 
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function go()
{
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

/* code to handle running PHP functions inside Javascript */
function javaFunction(os_name,os_version,os_subversion){
        // In the varArray are all the variables you want to give with the function
        hostname = document.displayForm.hostname.value;
        domain = document.displayForm.domain.value;
        mac= document.displayForm.mac.value;
        addr_type= document.displayForm.addr_type.value;
        ipaddr= document.displayForm.ipaddr.value;
        netmask= document.displayForm.netmask.value;
        gateway= document.displayForm.gateway.value;
        dns_1= document.displayForm.dns_1.value;
        dns_2= document.displayForm.dns_2.value;
        password  = document.displayForm.password.value;
        password_confirm = document.displayForm.password_confirm.value;
        lang = document.displayForm.lang.value;
        tz = document.displayForm.tz.value;
        cpu = document.displayForm.cpu.value;
        hd = document.displayForm.hd.value;
        notify = document.displayForm.notify.value;
        pre_install = document.displayForm.pre_install.value;
        post_install = document.displayForm.post_install.value;
        var url="javascript:dojo.widget.byId('docpane').setUrl('edit.php?os_name="+os_name+"&os_version="+os_version+"&os_subversion="+os_subversion+"&mac="+mac+"&hostname="+hostname+"&domain="+domain+"&addr_type="+addr_type+"&ipaddr="+ipaddr+"&netmask="+netmask+"&gateway="+gateway+"&dns_1="+dns_1+"&dns_2="+dns_2+"&password="+password+"&password_confirm="+password_confirm+"&lang="+lang+"&tz="+tz+"&cpu="+cpu+"&hd="+hd+"&notify="+notify+"&pre_install="+pre_install+"&post_install="+post_install+"')";
        window.open(url, "_self");
}

/* used to toggle visibility of table row text elements in-line */
function applyDisplay(toggle,id) {
                        //document.getElementById(id).style.visibility = value;
    	if (toggle == "off") {
         		document.getElementById(id).style.display = "none";
         	}
          else if (toggle == "on") {
         		document.getElementById(id).style.display = "inline";
       	}
}



/* dojo dijit UI functions */

/* event handler for hiding links */
/*
window.onload = applyEvents;
function applyEvents(){
    if(document.getElementById && document.getElementsByTagName){
        var arrAllLinks = document.getElementsByTagName("a");
        var oLink;
        for(var i=0; i<arrAllLinks.length; i++){
            oLink = arrAllLinks[i];
            if(oLink.className.search(/fixLayer/) != -1){
                oLink.onclick = function (oEvent){
                    var oEvent = (typeof oEvent != "undefined")? oEvent : event;
                    oEvent.returnValue = false;
                    if(oEvent.preventDefault){
                        oEvent.preventDefault();
                    }
                    document.getElementById("check").className = "display-block";
                }
            }
        }
    }
}

*/
