/*
  Base URL is specific to each dealer. Each dealer needs to change this URL to their dealer specific URL.
*/
	function getBaseURL(){
	   return "https://johnsonpower.cat.com/DSFUnbundled/";
	}




	function getURLBasedOnAppName(appName)	{

		if (appName == 'Industrial Wizard')
			return 'http://industrialwizard.catmms.com/catwizards/industrialWizard/jsp/dealerStoreFront.jsp';
		else if (appName == 'Marine Spec Sheet Wizard' )
		    return 'http://marinewizard.catmms.com/catwizards/marineWizard/jsp/dealerStoreFront.jsp';
		else if (appName == 'Electric Power Wizard')
		    return 'http://vidswizard.catmms.com/catwizards/vidswizard/jsp/dealerStoreFront.jsp';
		else if (appName == 'Invoices and Statements Online')
		    return 'https://www.eipp01.com/Johnson/login.aspx';
		else if (appName == 'Blanchard')
			return "http://dsfunbundledt3.ecorp.cat.com/blanchard";
		else if (appName == 'Portal Lite' )
			return "http://dsfunbundledt3.ecorp.cat.com/portal-lite";
		else if (appName == 'newbuildnquote')
                  return "http://buildnquote-rp.cat.com";
        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 (selValue == 'https://www.eipp01.com/Johnson/login.aspx') {
				top.location.href=selValue;
			}else{
				if(parent.frames[1] !=null) {
					parent.frames[1].location.href=selValue;
				}else{
					window.location.href=selValue;
				}
			}
		}
	}

	function getApp(selValue,title){
		//alert(selValue);
		var tmpValue;
		var partialURL;
		var endOfUrl;
		//var selIndex = selectBox.selectedIndex;
		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'>"+title+"</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();
  		}
	}

	//runwindow if there is a var sent
	function runWin(appName) {
		 	//
		 	loadSelectBoxChanges("servlet/DSFCentralServlet?appName=" + appName);
		 	}
