/*
  Base URL is specific to each dealer. Each dealer needs to change this URL to their dealer specific URL.
*/
        function pageloading()
{
        var value = getQueryVariable('Application');  
        var temp = getURLBasedOnAppName(value)
        var tdElement=document.getElementById("appName");
	
        if(value == 'PartStore')
        {

 //         parent.frames[1].location.href = "PartStoreUnavailable.htm"; 
           parent.frames[1].location.href=getBaseURL() + 'servlet/DSFCentralServlet?appName=PartStore';
           if(tdElement)
           {
              
	       tdElement.innerHTML ="<span class='frameTitle'>PartStore</span>"
           }
         
        } 
        else if(value == 'DocumentReview')
        {
           parent.frames[1].location.href=getBaseURL() + 'servlet/DSFCentralServlet?appName=Document Review';
           if(tdElement)
           {
	       tdElement.innerHTML ="<span class='frameTitle'>Document Review</span>"
           }        

        }

        else if(value == 'EquipmentData')
        {
           parent.frames[1].location.href=getBaseURL() + 'servlet/DSFCentralServlet?appName=Equipment Data';
           if(tdElement)
           {
	       tdElement.innerHTML ="<span class='frameTitle'>Equipment Data</span>"
           }        

        }
        else if(value == 'EquipmentManager')
        {
            parent.frames[1].location.href=getBaseURL() + 'servlet/DSFCentralServlet?appName=Equipment Manager';

           if(tdElement)
           {
	       tdElement.innerHTML ="<span class='frameTitle'>Equipment Manager</span>"
           }       

        }
         else if(value == 'UsedEquipment')
		 {
            parent.frames[1].location.href='http://dsf.catused.cat.com/dsf/index.html.arg=edocd%3DT010';
		    if(tdElement)
            {
	        	tdElement.innerHTML ="<span class='frameTitle'>CatUsed</span>"
            }

		} 
       else if(value == 'BuildAndQuote')
	   {
            parent.frames[1].location.href=getBaseURL() + 'servlet/DSFCentralServlet?appName=Build Your Own and Get a Quote';
           
           if(tdElement)
           {
	       tdElement.innerHTML ="<span class='frameTitle'>Build and Quote</span>"
           }

		}
       else if(value == 'MSDS')
	   {
            parent.frames[1].location.href ='http://catmsds.cat.com/MSDSSearch/servlet/cat.cis.ecs.msdsSearch.controller.UserIdentificationDisplayServlet';
			if(tdElement)
            {
 	       		tdElement.innerHTML ="<span class='frameTitle'>MSDS</span>"
           	}
	   }
        else if(value == 'ClaasParts')
		{
            parent.frames[1].location.href ='http://203.47.145.83/ClaasParts/default.asp';
       		if(tdElement)
            {
	       		tdElement.innerHTML ="<span class='frameTitle'>ClassParts</span>"
            }
		} 
       else if(value == 'Register')
	   {
            parent.frames[1].location.href =getBaseURL() +'dataPrivacy.do';
            if(tdElement)
            {
	       		tdElement.innerHTML ="<span class='frameTitle'>Register</span>"
            }
	   }
	   else if(value == 'SOS')
	   {
            parent.frames[1].location.href ='http://203.47.145.83/EquipCom/Login.aspx';
			if(tdElement)
            {
	       		tdElement.innerHTML ="<span class='frameTitle'>S&middot;O&middot;S Oil Commander</span>"
            }
	   }
}

function getQueryVariable(variable)
{ 
  var query = parent.location.search.substring(1); 
  var vars = query.split("="); 

   if (vars[0] == variable)
   {   
       return vars[1];
    }
  
	return "";
}

	function getBaseURL()
	{ 
	   return "https://williamadams.cat.com/DSFUnbundled/";
	}
	
	function getURLBasedOnAppName(appName)
	{
		if (appName == 'SOS')
			return 'http://203.47.145.83/EquipCom/Login.aspx';
		else if (appName == 'Used Equipment' )	
		    return 'http://dsf.catused.cat.com/dsf/index.html.arg=edocd%3DT010';
        else
              return ' ';
	}
	
	/*
	  this the method is calling when user select speicifc application  from 
      Quick Access link from select box. 
	*/
	function loadSelectBoxChanges(selectBox)
	{
		var selValue;
		var tmpValue;
		var partialURL;
		var endOfUrl;
		var selIndex = selectBox.selectedIndex;
		if (selIndex != -1) {
			selValue = selectBox.options[selIndex].value;
			if (selValue.length ==  0 ){
			      return;
			}
			tmpValue = getURLBasedOnAppName(selValue);
	        if (tmpValue != ' '){
			  selValue = tmpValue;
			}else{
				partialURL = selValue.substring(0, selValue.indexOf('=')+1);
				endOfUrl = selValue.substr(selValue.indexOf('=')+1);
				selValue = getBaseURL()+partialURL + endOfUrl;
                             
			}
			var tdElement=document.getElementById("appName");
			if(tdElement){
				tdElement.innerHTML ="<span class='frameTitle'>" +selectBox.options[selIndex].text+"</span>"
			}
  	  }
		selectBox.selectedIndex = 0;
		if (selValue != "" ){
			if(parent.frames[1] !=null) {
				parent.frames[1].location.href=selValue;
			}else{
				window.location.href=selValue;
			}
		}
	}

	//close popup window if it exists	
	function logoff()
	{
  		if (window.popupWindow)
  		{
			popupWindow.close();
  		}
	}
