 
var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object();

ModalDialog.value = '';
ModalDialog.eventhandler = '';
 

function getRadioValue(radioObj)
{
	if(!radioObj)
		{return "";}
	var radioLength = radioObj.length;
	if (radioLength === undefined)
	{
		if(radioObj.checked)
			{return radioObj.value;}
		else
			{return "";}
	}
	for(var i = 0; i< radioLength; i++) {
		if(radioObj[i].checked){
			return radioObj[i].value;
		}
	}
	return "";
		
}
function ModalDialogMaintainFocus()
{
  try
  {
    if (ModalDialogWindow.closed)
     {
        window.clearInterval(ModalDialogInterval);
        eval(ModalDialog.eventhandler);       
        return;
     }
    ModalDialogWindow.focus(); 
  }
  catch (everything) {   }
}
        
 function ModalDialogRemoveWatch()
 {
    ModalDialog.value = '';
    ModalDialog.eventhandler = '';
 }
        
 function ModalDialogShow(Title,BodyText,Buttons,EventHandler)
 {

   ModalDialogRemoveWatch();
   ModalDialog.eventhandler = EventHandler;

   var args='width=350,height=175,left=325,top=300,toolbar=0,';
       args+='location=0,status=0,menubar=0,scrollbars=1,resizable=0';  

   ModalDialogWindow=window.open("","",args); 
   ModalDialogWindow.document.open(); 
   ModalDialogWindow.document.write('<html>');
   ModalDialogWindow.document.write('<head>'); 
   ModalDialogWindow.document.write('<title>' + Title + '</title>');
   ModalDialogWindow.document.write('<script' + ' language=JavaScript>');
   ModalDialogWindow.document.write('function CloseForm(Response) ');
   ModalDialogWindow.document.write('{ ');
   ModalDialogWindow.document.write(' window.opener.ModalDialog.value = Response; ');
   ModalDialogWindow.document.write(' window.close(); ');
   ModalDialogWindow.document.write('} ');
   ModalDialogWindow.document.write('</script' + '>');        
   ModalDialogWindow.document.write('</head>');   
   ModalDialogWindow.document.write('<body onblur="window.focus();">');
   ModalDialogWindow.document.write('<table border=0 width="95%" align=center cellspacing=0 cellpadding=2>');
   ModalDialogWindow.document.write('<tr><td align=left>' + BodyText + '</td></tr>');
   ModalDialogWindow.document.write('<tr><td align=left><br></td></tr>');
   ModalDialogWindow.document.write('<tr><td align=center>' + Buttons + '</td></tr>');
   ModalDialogWindow.document.write('</body>');
   ModalDialogWindow.document.write('</html>'); 
   ModalDialogWindow.document.close(); 
   ModalDialogWindow.focus(); 
   ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5);

 }

 function NextAppointment(BodyText,EventHandler)
 {
    var Buttons=''; 
    Buttons = '<input type="button" onclick=\'CloseForm("Accept");\' value="Accept"/>  ';
    Buttons += '<input type="button" onclick=\'CloseForm("Change");\' value="Change"/>  ';
    Buttons += '<input type="button" onclick=\'CloseForm("Cancel");\' value="Cancel"/>  ';
    ModalDialogShow("Dialog",BodyText,Buttons,EventHandler);
    
 }
 function appointmentDialog(dateString,existingBoolean)
 {
 	if (existingBoolean)
 	{
 		NextAppointment('This vehicle is already scheduled for an appointment at '+dateString+' Would you like to change this time?','NextAppointmentReturnExistingMethod()');
 	}
 	else
 		NextAppointment('The next available appointment for this vehicle is '+dateString+' Would you like to change this time?','NextAppointmentReturnMethod()');
 	
 }
 function reserve(type, userid, machid, start_date, resid, scheduleid, is_blackout, read_only, pending, starttime, endtime) {  
		if (is_blackout == null) { is_blackout = 0; }
		
		if (is_blackout != 1) {
			w = (type == 'r' || type == 'm') ? 600 : 520;
			h = (type == 'm') ? 610 : 570;
		}
		else {
			w = (type == 'r') ? 600 : 425;
			h = (type == 'm') ? 460 : 420;
		}
		
		if (machid == null) { machid = ''; }
		if (start_date == null) { start_date = ''; }
		if (resid == null) { resid = ''; }
		if (scheduleid == null) { scheduleid = ''; }

		if (read_only == null) { read_only = ''; }
		if (pending == null) { pending = ''; }
		if (starttime == null) { starttime = ''; }
		if (endtime == null) { endtime = ''; }
		if (userid == null) { userid = ''; }

		nurl = "schedule/reserve.php?type=" + type + "&machid=" + machid + "&start_date=" + start_date + "&resid=" + resid + "&scheduleid=" + scheduleid + "&is_blackout=" + is_blackout + "&read_only=" + read_only + "&pending=" + pending + "&starttime=" + starttime + "&endtime=" + endtime+ "&userid=" + userid;    
		var resWindow = window.open(nurl,"reserve","width=" + w + ",height=" + h + ",scrollbars,resizable=no,status=no");     
		resWindow.focus();
		void(0);   
}

function getMarkup(unitCost, type)
{
	if (type == 'Jobber')
	{
		mult = .2535;
		ex = .051;
		min = .2;
		return min + (1/(mult+(ex*Math.log(unitCost))));
	}
	if (type == 'Dealer')
	{
		mult = 1.879;
		ex = -.0227;
		min = 1.6;
		return min + (mult*Math.exp(ex*unitCost));
	}
	if (type == 'Wholesale Distributor')
	{
		mult = .13;
		ex = .035;
		min = 0;
		return min + (1/(mult+(ex*Math.log(unitCost))));
	}
}


 function getSectionXML(url, tabID)
        {
        var xmlhttp=false;

        // branch for IE/Windows ActiveX version
        if(window.ActiveXObject) {//alert("window.ActiveX");
            try {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                   // alert("msxml");
            } catch(e) {
                    try {
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                            //alert("Microsoft");
                    } catch(e) {
                            xmlhttp = false;
                    }
                    }
        }
        // branch for native XMLHttpRequest object

        else if(window.XMLHttpRequest) {
        try {
        	//alert("window.XMLHttpRequest");
                        xmlhttp = new XMLHttpRequest();
                        xmlhttp.overrideMimeType('text/xml');
                        
        } catch(e) {
                        xmlhttp = false;
        }
        }


         if(xmlhttp)
         {

                 xmlhttp.open("GET", url,true);
                 xmlhttp.onreadystatechange=function() {
                  if (xmlhttp.readyState==4) {
                        document.getElementById(tabID).innerHTML = xmlhttp.responseText;
                  }
                 }
                xmlhttp.send(null);

         }
         else
	 {
                alert("xmlhttp unsuccessful!");
         }
        }

 function getHTTPXML(url, id)
 {
 var xmlhttp=false;

 // branch for IE/Windows ActiveX version
 if(window.ActiveXObject) {//alert("window.ActiveX");
     try {
             xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            // alert("msxml");
     } catch(e) {
             try {
                     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                     //alert("Microsoft");
             } catch(e) {
                     xmlhttp = false;
             }
             }
 }
 // branch for native XMLHttpRequest object

 else if(window.XMLHttpRequest) {
 try {
 	//alert("window.XMLHttpRequest");
                 xmlhttp = new XMLHttpRequest();
                 xmlhttp.overrideMimeType('text/xml');
                 
 } catch(e) {
                 xmlhttp = false;
 }
 }


  if(xmlhttp)
  {

          xmlhttp.open("GET", url,true);
          xmlhttp.onreadystatechange=function() {
           if (xmlhttp.readyState==4) {
                 document.getElementById(id).value= xmlhttp.responseText;
           }
          }
         xmlhttp.send(null);

  }
  else
{
      alert("xmlhttp unsuccessful!");
  }
 }

