function KeywordSearch()
{
   var obj = window.document.getElementById( 'txtSiteSearch' );
   window.location.href = gsAppPath + '/search.aspx?k=' + obj.value;
}

var gbIsShortBio = true;

function ToggleBioDescription()
{
   var divExpandedBio = window.document.getElementById( 'divExpandedBio' );
   var divShortBio    = window.document.getElementById( 'divShortBio' );
   var img = window.document.getElementById( 'imgBioToggle' );
   
   if( gbIsShortBio )
   {
      gbIsShortBio = false;
      divExpandedBio.style.display = 'block';
      divShortBio.style.display = 'none';
      img.src = '../images/sub-pages/btn_view-bio-close.gif';
   }
   else
   {
      gbIsShortBio = true;
      divExpandedBio.style.display = 'none';
      divShortBio.style.display = 'block';
      img.src = '../images/sub-pages/btn_view-bio.gif';
   }
}

function FireButtonClickOnEnter( buttonId )
{
   if( window.layers )
   {
      return;
   }

   if( window.event.keyCode == 13 )
   {
      var obj = window.document.getElementById( buttonId );
      obj.click();
      event.returnValue = false;
   }
}

function iSwap ( id, pic ) {
   eval("document." + id + ".src = '" + pic + "'");
}

function openFlash ( )
{
   var win = window.open( "/media/tutorial.aspx", "flash", "width=600,height=400,scrollbars=no,resizable=no,location=no,toolbar=no" );
}

function closeWindow(){
   this.close();
}

function goApps( url )
{
  if ( url.length > 0 ) 
  {
   if ( url.indexOf( "www.exicor.com" ) > 0 )
         var win = window.open( url, "exicor", "width=800,height=600,scrollbars=yes,resizable=yes,location=yes,toolbar=yes" );
   else
         top.location.href = url;
   }
}

function pemTech() {
   parent.opener.top.location.href = "/PEM_Components/Technology/default.aspx";
   this.close();
}

//============================================================================
//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;
