var appPath = '';

function LoadPopupImage(img_src)
{
	window.open(
		img_src,
		"BigRigRedo",
		whtl(600, 600) +
			"toolbar=no,location=no" +
			",status=no,menubar=no" +
			",scrollbars=yes,resizable=no");
}

function ShowFlyerLocationsBoth(area)
{
	var affiliationId = "C9F46D62-DA10-4F18-A7ED-F0D9C7399305";
	var conduitSite = "www.dealersdesktop.com";
	var adType = "product,other";
	var graphicType = "PDF";
	var queryString =
		"?adType=" + adType +
		"&affiliationId=" + affiliationId +
		"&area=" + area +
		"&graphicType=" + graphicType;
	var popupPage =
		"http://" +
		conduitSite +
		"/webAds/showLocations.jsp";

	window.open(
		popupPage + queryString,
		"showLocations",
		whtl(550, 600) +
			"toolbar=no,location=no" +
			",status=no,menubar=no" +
			",scrollbars=yes,resizable=no");
}

function ShowFlyerLocations(area)
{
	var affiliationId = "C9F46D62-DA10-4F18-A7ED-F0D9C7399305";
	var conduitSite = "www.dealersdesktop.com";
	var adType = "other";
	var graphicType = "PDF";
	var queryString =
		"?adType=" + adType +
		"&affiliationId=" + affiliationId +
		"&area=" + area +
		"&graphicType=" + graphicType;
	var popupPage =
		"http://" +
		conduitSite +
		"/webAds/showLocations.jsp";

	window.open(
		popupPage + queryString,
		"showLocations",
		whtl(550, 600) +
			"toolbar=no,location=no" +
			",status=no,menubar=no" +
			",scrollbars=yes,resizable=no");
}

function RetailFlyerSearch()
{
	var drop_down = window.document.getElementById( 'drpDwnState' );
	var sc_value = drop_down[drop_down.selectedIndex].value;
	ShowFlyerLocationsBoth(sc_value);
}

function ShowServiceLocations(area)
{
	var affiliationId = "C9F46D62-DA10-4F18-A7ED-F0D9C7399305";
	var conduitSite = "www.dealersdesktop.com";
	var adType = "other";
	var graphicType = "JPEG";
	var queryString =
		"?adType=" + adType +
		"&affiliationId=" + affiliationId +
		"&area=" + area +
		"&graphicType=" + graphicType;
	var popupPage =
		"http://" +
		conduitSite +
		"/webAds/showLocations.jsp";

	window.open(
		popupPage + queryString,
		"showLocations",
		whtl(550, 600) +
			"toolbar=no,location=no" +
			",status=no,menubar=no" +
			",scrollbars=yes,resizable=no");
}

function ServiceSpecialSearch()
{
	var drop_down = window.document.getElementById( 'drpDwnState' );
	var sc_value = drop_down[drop_down.selectedIndex].value;
	ShowServiceLocations(sc_value);
}

function whtl(width, height)
{
   var left = (screen.availWidth - width) / 2;
   var top = (screen.availHeight - height) / 2;

   var result = "";

   result += "width=" + width + ",";
   result += "height=" + height + ",";
   result += "top=" + top + ",";
   result += "left=" + left + ",";

   return result;
}

function FireButtonClickOnEnter( myEvent )
{
   if( myEvent.keyCode == 13 )
   {
	  SiteSearch();		
      myEvent.returnValue = false;
   }
}

function SiteSearch()
{
   var objText = window.document.getElementById( 'txtSiteSearch' );
   var sTerm = escape( objText.value );
   window.location.href = appPath + '/search.aspx?sp-q=' + sTerm + '&sp-m=0';
}

function FirePodcastSearch( myEvent )
{
   if( myEvent.keyCode == 13 )
   {
      PodcastSearch();
      myEvent.returnValue = false;
   }
}

function FireAtbsPodcastSearch( myEvent )
{
   if( myEvent.keyCode == 13 )
   {
      AtbsPodcastSearch();
      myEvent.returnValue = false;
   }
}

function PodcastSearch()
{
   var objText = window.document.getElementById( 'podcastsearch' );
   var sTerm = escape( objText.value );
   window.location.href = appPath + '/inside-freightliner/podcasts.aspx?search=' + sTerm;
}

function AtbsPodcastSearch()
{
   var objText = window.document.getElementById( 'podcastsearch' );
   var sTerm = escape( objText.value );
   window.location.href = appPath + '/inside-freightliner/atbs.aspx?search=' + sTerm;
}

function OpenQTWindow( url, options )
{   
   var winUrl     = '/media/feature/quicktime/' + url;
   var winName    = '';
   window.open( winUrl, winName, options );
}

function OpenNewWindow( url, options )
{   
   var winName    = '';
   window.open( url, winName, options );
}

function ShowImage( imageUrl, imageID )
{
   var largeImage
   if (imageID != null)
      largeImage = window.document.getElementById( imageID );
   else
      largeImage = window.document.getElementById( 'imgLargePhoto' );
   largeImage.src = imageUrl;
}

function OpenGalleryWindow( truckName )
{
   window.open( '../gallery.aspx?truck=' + truckName , 'newwin', 'width=800,height=700,resizable=yes,scrollbars=yes,toolbars=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function Open360Tour( truckName )
{
   window.open( '../360-tour.aspx?truck=' + truckName , 'newwin', 'width=800,height=700,resizable=yes,scrollbars=yes,toolbars=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function OpenBrochureWindow( truckName )
{
   var pdf = '';

   switch( truckName )
   {
      case 'argosy' :
         pdf = 'argosy_brochure.pdf';
         break;
      case 'century' :
         pdf = 'century_brochure.pdf';
         break;
      case 'classic' :
         pdf = 'classicxl_brochure.pdf';
         break;
      case 'columbia' :
         pdf = 'columbia_brochure.pdf';
         break;
      case 'condor' :
         pdf = 'condor_brochure.pdf';
         break;
      case 'coronado' :
         pdf = 'coronado_brochure.pdf';
         break;         
      case 'coronado-sd' :
         pdf = 'coronado_sd_brochure.pdf';
         break;
      case 'original-coronado' :
         pdf = 'original-coronado_brochure.pdf';
         break;
      case 'scr' :
         pdf = 'FTC_SCR_Brochure.pdf';
         break;
      case 'fld' :
         pdf = 'fld120sd_brochure.pdf';
         break;
      case 'm2' :
         pdf = 'M2_Brochure.pdf';
         break;
      case 'm2-hybrid' :
         pdf = 'M2eHybrid-Brochure.pdf';
         break;
      case 'm2106v112v' :
         pdf = 'FTL_M2_106V_and_112V.pdf';
         break;
      case 'cascadia' :
         pdf = 'CascadiaBrochure.pdf';
         break;
      case 'zonar' :
         pdf = 'Virtual-Tech-Sell-Sheet.pdf';
         break;
      case 'kiaf' :
         pdf = 'KIAF_Brochure.pdf';
         break;
      case 'allison' :
         pdf = 'Allison-Dump-Sell-Sheet.pdf';
         break;
      case 'natural_gas' :
         pdf = 'Natural-Gas-Sell-Sheet.pdf';
         break;
   }
   
   if( pdf.length < 1 )
   {
      return;
   }
   
   window.open( appPath + '/media/pdf/' + pdf, 'newwin', 'width=800,height=600,resizable=yes,scrollbars=yes,toolbars=no,location=no,directories=no,status=no,menubar=no,copyhistory=no' );
   //window.open( 'http://media.staging.popart.com/freightlinertrucks2005/pdf/' + pdf );
}

function OpenPDFWindow( file )
{
   if( file.length < 1 )
   {
      return;
   }
   
   window.open( appPath + '/media/pdf/' + file, 'newwin', 'width=800,height=600,resizable=yes,scrollbars=yes,toolbars=no,location=no,directories=no,status=no,menubar=no,copyhistory=no' );
}

function PopUp(id, width, height, text)
{ 
    height = parseInt(height) + 70;
    window.open("viewer.aspx?id=" + id + "&ref=ownersgallery", "GalleryViewer", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=" + width + ",height=" + height  + ",left=100,top=100")
}

var FormReqFieldsArray= new Array('FIRST_NAME', 'Please enter your first name','',
            'LAST_NAME', 'Please enter your last name','',
            'COMPANY', 'Please enter a your company name.','',
            'ADDRESS_LINE1', 'Please enter your address','',
            'CITY', 'Please enter your city','',
            'STATE', 'Please select your state','select',
            'ZIP', 'Please enter your zip code','')

// simple routine to validate and submit the form
function OnNotificationSubmit()
{
    if( formCheck('Form1', FormReqFieldsArray) )
    {
	    document.Form1.submit();
    }
}

//============================================================================
//function: formCheck(FormName,requiredFields,status)
//
//description:        this function checks a form based on a 'required fields'
//                    which contains a field name, an error message, and a 
//                    special case handler.
//
//args: FormName       - name attribute of <form> tag
//      requiredFields - an array containing field name, error message, 
//                       and special type id.
//      status         - optional, used to disable form checking
// eg. requiredFields = 'first_name','Please enter your first Name','',
//                   'phonenumber','please enter a valid phone number','phone'
//
//usage: <form onSubmit="return formCheck('someName',requredFields)">
//============================================================================
function formCheck(FormName,requiredFields)
{   
   for(var i=0; i<requiredFields.length; i+=3)
   {
      var thirdelement = requiredFields[i+2]
      if (thirdelement == 'special'){
        //handle special checkbox cases
         if (!document.dealerContact.INTEREST_NEWTRUCKS.checked &&
             !document.dealerContact.INTEREST_USEDTRUCKS.checked &&
             !document.dealerContact.INTEREST_SERVICE.checked &&
             !document.dealerContact.INTEREST_PARTS.checked &&
             !document.dealerContact.INTEREST_OTHER.checked ) {               
                alert("Please check at least one area in which you are interested");     
                document.dealerContact.INTEREST_NEWTRUCKS.focus()
                return  false;
         }            
       
      }

      else {
      //-------------------------------------------------- identify input type
      if(!document.forms[FormName].elements[requiredFields[i]].type)
      {
         var inputType = document.forms[FormName].elements[requiredFields[i]][0].type;        
      }
      else
      var inputType = document.forms[FormName].elements[requiredFields[i]].type;

      if ((inputType == 'text') || (inputType == 'textarea'))
      {
         //-------------------------------------------------- special cases
         if ( requiredFields[i+2] == "email" )
         {
            if( !isEmail(document.forms[FormName].elements[requiredFields[i]]) )
            {
               alert(requiredFields[i+1])
               document.forms[FormName].elements[requiredFields[i]].focus();
               return  false;
            }
         }
         else if (requiredFields[i+2] == "phone")
         {
            if(!isPhone(document.forms[FormName].elements[requiredFields[i]]) )
            {
               if (document.forms[FormName].elements[requiredFields[i]].value == "" ) {
               alert("Please enter your phone number")
               document.forms[FormName].elements[requiredFields[i]].focus();
               return  false;
               }
               else {                                           
               alert(requiredFields[i+1])
               document.forms[FormName].elements[requiredFields[i]].focus();
               return  false;
               }
            }
         }
         else if ( requiredFields[i+2] == "zip" )
         {
            if(!isZIP(document.forms[FormName].elements[requiredFields[i]]) )
            {
               alert(requiredFields[i+1])
               document.forms[FormName].elements[requiredFields[i]].focus();
               return  false;
            }
         }
         else if ( requiredFields[i+2] == "num" )
         {
            if(!isNumber(document.forms[FormName].elements[requiredFields[i]]) )
            {
               alert(requiredFields[i+1])
               document.forms[FormName].elements[requiredFields[i]].focus();
               return  false;
            }
         }
         //----------------------------------------------------general case
         else if( document.forms[FormName].elements[requiredFields[i]].value == '')
         {
           alert(requiredFields[i+1])
           document.forms[FormName].elements[requiredFields[i]].focus();
           return false;
         }
      }
      else if (inputType == 'radio')
      {
        
        var isChecked = false;
        for(var n = 0; n < document.forms[FormName].elements[requiredFields[i]].length; n++)
        {
          if(document.forms[FormName].elements[requiredFields[i]][n].checked == true)
             var isChecked = true;
        }
        if(!isChecked)
        {
           alert(requiredFields[i+1])
           document.forms[FormName].elements[requiredFields[i]][0].focus();
           return false;            
        }
      }
      else if (inputType == 'select-one')      {   
         
         if( document.forms[FormName].elements[requiredFields[i]].selectedIndex==0)
         {
           alert(requiredFields[i+1])
           document.forms[FormName].elements[requiredFields[i]].focus();
           return false;
         }
      }
      else if (inputType == 'checkbox')
      {
         if(requiredFields[i+2] == "mustBeChecked")
         {
            if( !document.forms[FormName].elements[requiredFields[i]].checked)
            {
               alert(requiredFields[i+1]);
               document.forms[FormName].elements[requiredFields[i]].focus();
               return false;
            }
         }
      }
   }
   }
   return( true );
}


//*******************************************************************
//  function: isEmail -This script checks the user's input and cancels 
//                 the submission if the e-mail has an invalid syntax
//
//  input: email field
//
//  output: true/false
//
//*******************************************************************
function isEmail(field) {
  var str = field.value;
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)) {
      return true;
    }
    field.focus();
    field.select();
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    field.focus();
    field.select();
    return false;
  }
}


//*******************************************************************
//  function: isNumber - ensures a number
//
//  input: number field
//
//  output: true/false
//
//*******************************************************************
function isNumber(field) {
   var str = field.value;
   var valid = "0123456789";

   if (str.length == 0) {
      return false;
   }
   for (var i=0; i < str.length; i++) {
      temp = "" + str.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") {
         return false;
      }
   }

   return true;
}


//*******************************************************************
//  function: isZIP - ensures a valid 5 or 9 digit zip code
//
//  input: email field
//
//  output: true/false
//
//*******************************************************************
function isZIP(field) {
   var str = field.value;
   var valid = "0123456789-";
   var hyphencount = 0;

   if (str.length!=5 && str.length!=10) {
      return false;
   }
   for (var i=0; i < str.length; i++) {
      temp = "" + str.substring(i, i+1);
      if (temp == "-") hyphencount++;
      if (valid.indexOf(temp) == "-1") {
         return false;
   }
   if ((hyphencount > 1) || ((str.length==10) && ""+str.charAt(5)!="-")) {
      return false;
      }
   }
   return true;
}


//*******************************************************************
//  function: isPhone - ensures a valid 3 digit area code
//
//  input:  Phone field
//
//  output: true/false
//
//*******************************************************************
function isPhone(field) 
{
   var valid = "0123456789";
   var str = field.value;
   var temp = "";
   var phoneString = "";
   for (var i=0; i < str.length; i++) 
   {
      temp = "" + str.substring(i, i+1);
      if (valid.indexOf(temp) != "-1") 
      {
         phoneString += temp;  	
      }
   }

   if (phoneString.length!=7 && phoneString.length!=10) {
      return false;
   }
   else return true;
}


/**
 * FlashObject v1.2.3: Flash detection and embed - http://blog.deconcept.com/flashobject/
 *
 * FlashObject is (c) 2005 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
if(typeof com.deconcept.FlashObjectUtil == "undefined") com.deconcept.FlashObjectUtil = new Object();
com.deconcept.FlashObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, redirectUrl, detectKey){
   this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
   this.skipDetect = com.deconcept.util.getRequestParameter(this.DETECT_KEY);
   this.params = new Object();
   this.variables = new Object();
   this.attributes = new Array();

   if(swf) this.setAttribute('swf', swf);
   if(id) this.setAttribute('id', id);
   if(w) this.setAttribute('width', w);
   if(h) this.setAttribute('height', h);
   if(ver) this.setAttribute('version', new com.deconcept.PlayerVersion(ver.toString().split(".")));
   if(c) this.addParam('bgcolor', c);
   var q = quality ? quality : 'high';
   this.addParam('quality', q);
   this.setAttribute('redirectUrl', '');
   if(redirectUrl) this.setAttribute('redirectUrl', redirectUrl);
   if(useExpressInstall) {
   // check to see if we need to do an express install
   var expressInstallReqVer = new com.deconcept.PlayerVersion([6,0,65]);
   var installedVer = com.deconcept.FlashObjectUtil.getPlayerVersion();
      if (installedVer.versionIsValid(expressInstallReqVer) && !installedVer.versionIsValid(this.getAttribute('version'))) {
         this.setAttribute('doExpressInstall', true);
      }
   } else {
      this.setAttribute('doExpressInstall', false);
   }
}
com.deconcept.FlashObject.prototype.setAttribute = function(name, value){
	this.attributes[name] = value;
}
com.deconcept.FlashObject.prototype.getAttribute = function(name){
	return this.attributes[name];
}
com.deconcept.FlashObject.prototype.getAttributes = function(){
	return this.attributes;
}
com.deconcept.FlashObject.prototype.addParam = function(name, value){
	this.params[name] = value;
}
com.deconcept.FlashObject.prototype.getParams = function(){
	return this.params;
}
com.deconcept.FlashObject.prototype.getParam = function(name){
	return this.params[name];
}
com.deconcept.FlashObject.prototype.addVariable = function(name, value){
	this.variables[name] = value;
}
com.deconcept.FlashObject.prototype.getVariable = function(name){
	return this.variables[name];
}
com.deconcept.FlashObject.prototype.getVariables = function(){
	return this.variables;
}
com.deconcept.FlashObject.prototype.getParamTags = function(){
   var paramTags = ""; var key; var params = this.getParams();
   for(key in params) {
        paramTags += '<param name="' + key + '" value="' + params[key] + '" />';
    }
   return paramTags;
}
com.deconcept.FlashObject.prototype.getVariablePairs = function(){
	var variablePairs = new Array();
	var key;
	var variables = this.getVariables();
	for(key in variables){
		variablePairs.push(key +"="+ variables[key]);
	}
	return variablePairs;
}
com.deconcept.FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
        flashHTML += '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') + '" name="'+ this.getAttribute('id') +'"';
		var params = this.getParams();
        for(var key in params){ flashHTML += ' '+ key +'="'+ params[key] +'"'; }
		pairs = this.getVariablePairs().join("&");
        if (pairs.length > 0){ flashHTML += ' flashvars="'+ pairs +'"'; }
        flashHTML += '></embed>';
    } else { // PC IE
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') +'">';
        flashHTML += '<param name="movie" value="' + this.getAttribute('swf') + '" />';
		var tags = this.getParamTags();
        if(tags.length > 0){ flashHTML += tags; }
		var pairs = this.getVariablePairs().join("&");
        if(pairs.length > 0){ flashHTML += '<param name="flashvars" value="'+ pairs +'" />'; }
        flashHTML += '</object>';
    }
    return flashHTML;
}
com.deconcept.FlashObject.prototype.write = function(elementId){
	if(this.skipDetect || this.getAttribute('doExpressInstall') || com.deconcept.FlashObjectUtil.getPlayerVersion().versionIsValid(this.getAttribute('version'))){
		if(document.getElementById){
		   if (this.getAttribute('doExpressInstall')) {
		      this.addVariable("MMredirectURL", escape(window.location));
		      document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		      this.addVariable("MMdoctitle", document.title);
		   }
			document.getElementById(elementId).innerHTML = this.getHTML();
		}
	}else{
		if(this.getAttribute('redirectUrl') != "") {
			document.location.replace(this.getAttribute('redirectUrl'));
		}
	}
}
/* ---- detection functions ---- */
com.deconcept.FlashObjectUtil.getPlayerVersion = function(){
   var PlayerVersion = new com.deconcept.PlayerVersion(0,0,0);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new com.deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (window.ActiveXObject){
	   try {
   	   var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
   		PlayerVersion = new com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
	   } catch (e) {}
	}
	return PlayerVersion;
}
com.deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) || 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
com.deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
com.deconcept.util.getRequestParameter = function(param){
	var q = document.location.search || document.location.href.hash;
	if(q){
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) {
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}

/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use / backwards compatibility */
var getQueryParamValue = com.deconcept.util.getRequestParameter;
var FlashObject = com.deconcept.FlashObject;
