//Internal javscript below

var requiredVersion = 5;   
var useRedirect = false; 

// System globals
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var maxVersion = 6;
var actualVersion = 0;
var hasRightVersion = false;

// Netscape Navigator Resize Fix
var oldHeight;
var oldWidth;
oldHeight = window.outerHeight;
oldWidth = window.outerWidth;

//detect os
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

//detect browser
var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var isIE = (iePos !=-1) ? true : false
var isNS =  (navigator.appName == "Netscape") ? true : false

//if IE detect version
if (isIE) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);	
}

var isDhtmlNav = (isIE && isWin && (iePos !=-1) && is_minor >= 5) ? true : false
var isDynamicTable = (isNS) ? true : false
var isReloadOnResize = (isNS) ? true : false

jsVersion = 1.1;

if(isIE && isWin){
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('</SCRIPT\> \n'); 
}





//form_validation
/* 
Tridion:

Below is tha javascript array which builds either the toplevel of the standard html version or the dhtmlversion. 

Position 0 is the navigation text
Position 1 is the link (only used in the standard html version)
Position 2 is the state of each navigation item. selected/unselected. 
*/

navArray = [
	["Our Trucks","trucks/",0],
	["Our Buses","buses/",0],
	["Other Products","other/",0],
	["Services","services/",0],
	["Services Network","network/",0],
	["About Us","about/",0]
]

function writeDynamicTableTag(){
		if(isDynamicTable){
			document.write("<table width='" + (window.innerWidth-742) + "' border='0' bgcolor='#D8D8D8' cellpadding='0' cellspacing='0'>");
		} else {
			document.write('<table border="0" bgcolor="#D8D8D8" cellpadding="0" cellspacing="0" width="100%">');
		}
}

// Netscape Navigator Resize Fix
function NNreloadOnResize(){
	if (oldHeight != window.outerHeight || oldWidth != window.outerWidth){
		document.location.reload();
	}
}

// Navigates to the selected value in named dropdown and named form
function dropdownNav(formName,ddName){
	selValue = eval("document.forms[formName]." + ddName + "[document.forms[formName]." + ddName + ".selectedIndex].value")
	if (selValue != ""){
		window.open(selValue);
		//alert(selValue + "\nTridion: function found on row 70 in file script_common.js");
		//document.location = selValue;
	}
}

/* Validates any form based on the requiredFields Array
	- The E-mail field name must be passed as the second argument for e-mail validation to work.
	- The requiredFields Array is set above the form in the file that contains the form
*/
function validateForm(formName, emailFieldName){
	for (i=0; i<requiredFields.length; i++){
		if (eval("document.forms[formName]."+requiredFields[i]+".value") == null){
fieldValue = eval("document.forms[formName]."+requiredFields[i]+"[document.forms[formName]."+requiredFields[i]+".selectedIndex].value");
		} else {
			fieldValue = eval("document.forms[formName]."+requiredFields[i]+".value");
		}
		if (fieldValue == ""){
			alert("Please note that fields indicated with an asterisk (*)\nare required to complete this form.\n\nMake sure that the required fields are not empty.");
			eval("document.forms[formName]."+requiredFields[i]+".focus()");
			return;
		}
		if (requiredFields[i] == emailFieldName){
			eml = eval("document.forms[formName]." + emailFieldName + ".value");
			if (!nIsEmail(eml, true)){
				alert("Please check your e-mail formatting.");
				eval("document.forms[formName]." + emailFieldName + ".focus()");
				return;
			}
		}
	}
	document.forms[formName].submit();
		
	function nIsEmail( vEmailAddress, vAllowScandinavian ) {
		var NEC_CHAR_UNDERSCORE = new String("_");
		var NEC_CHAR_AT = new String("@");
		var NEC_CHAR_DOT = new String(".");
		var NEC_CHAR_PUNCTUATION = new String("-_");
		var NEC_CHAR_SCANDINAVIAN = new String("åÅäÄöÖ");

		var pAlphaCharacters = new RegExp("[A-Z]|[a-z]|[0-9]");
		var pWasValid;
		var pPunc;
		if( !vAllowScandinavian ) vAllowScandinavian = false;
		vEmailAddress = vEmailAddress.replace( RegExp(/^ */), "" ).replace( RegExp(/ *$/), "" );

		if( vEmailAddress.length <6 ) return false;
		if( vEmailAddress.search( NEC_CHAR_AT,"g") == -1  ) return false;
		if( vEmailAddress.charAt(0).search(pAlphaCharacters) == -1 && !vAllowScandinavian  ) return false;
		if( vEmailAddress.lastIndexOf(NEC_CHAR_DOT) < vEmailAddress.indexOf(NEC_CHAR_AT) ) return false;

		pPunc = false;
		for( var i=0; i<vEmailAddress.length; i++) {
			if( vEmailAddress.charAt(i).search(pAlphaCharacters) ==-1 ) {
				if( pPunc == false ) {
					if( vEmailAddress.charAt(i)!= NEC_CHAR_AT && vEmailAddress.charAt(i)!= NEC_CHAR_UNDERSCORE && vEmailAddress.charAt(i)!=NEC_CHAR_DOT ) {
						pWasValid = false;
						pPunc = true;
						for( var v=0; v<NEC_CHAR_PUNCTUATION.length; v++) {
							if( NEC_CHAR_PUNCTUATION.charAt(v) == vEmailAddress.charAt(i) ){
								pWasValid = true;
								if( i==0 || i==(vEmailAddress.length-1) ) return false;
							}				
						}
						if( vAllowScandinavian ) {
							for( var v=0; v<NEC_CHAR_SCANDINAVIAN.length; v++) {
								if( NEC_CHAR_SCANDINAVIAN.charAt(v) == vEmailAddress.charAt(i) ) { 
									pWasValid = true;
									pPunc = false;
								}
							}
						}
						if( !pWasValid ) return false;
					} else { 
						if( i==0 || i==(vEmailAddress.length-1) ) return false;
						pPunc = true;
					}
				} else return false;
			} else pPunc = false;
		}
		return true;
	}
}

//func_flash
/*
Tridion

This function embeds an flash if the user has flash or else it shows a gif.
The function needs to be included on every page that uses flash

*/

function placeFlash(flashFile,alternateFile,fileWidth,fileHeight,alternateLink,altText){
	
	detectFlash(); //detect Flash version
	
	if(hasRightVersion) {  // if we've detected an acceptable version
	    var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	    + 'WIDTH="' + fileWidth + '" HEIGHT="' + fileHeight + '"'
	    + 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
	    + '<PARAM NAME="MOVIE" VALUE="' + flashFile + '">'
	    + '<PARAM NAME="PLAY" VALUE="true">'
	    + '<PARAM NAME="LOOP" VALUE="false">'
	    + '<PARAM NAME="QUALITY" VALUE="high">'
	    + '<PARAM NAME="MENU" VALUE="false">'
		+ '<PARAM NAME="WMODE" value="transparent">'
	    + '<EMBED SRC="' + flashFile + '"'
	    + 'WIDTH="' + fileWidth + '" HEIGHT="' + fileHeight + '"'
	    + 'PLAY="true"'
	    + 'LOOP="false"'
	    + 'QUALITY="high"'
	    + 'MENU="false"'
	    + 'TYPE="application/x-shockwave-flash"'
	    + 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
	    + '</EMBED>'
	    + '</OBJECT>';
	
	    document.write(oeTags); 
	  } else {
	    var alternateContent = '<a href="' + alternateLink + '"><img src="images/' + alternateFile + '" width="' + fileWidth + '" height="' + fileHeight + '" alt="' + altText + '" border="0"></a>' 											
	    document.write(alternateContent); 
	}
}	

function detectFlash() {  
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
      
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
     
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
  
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  
	
  if (actualVersion >= requiredVersion) {
    hasRightVersion = true;                
  }
}

function sisMoveToNextPage()
{
	sida = document.theForm.resultPageSel1.options[document.theForm.resultPageSel1.selectedIndex].value;
	document.location.href=sida;
}
		
function sisMoveToNextPage2()
{
	sida = document.theForm.resultPageSel2.options[document.theForm.resultPageSel2.selectedIndex].value;
	document.location.href=sida;
}
		
function sisValidateForm()
{
	for(i=0; i<document.form1.checkSearch.length; i++){
		if(document.form1.checkSearch[i].checked){
			return true;
		}
	}
	alert("To be able to search please select a checkbox!");
	return false;
}

function sisDropdownNav()
{
	page = document.sisSelectForm.sisDealerSelect.options[document.sisSelectForm.sisDealerSelect.selectedIndex].value;
	document.location.href=page;
}

function zoek()
{
	document.forms.item("search").submit();
}

function klik()
{
    if (document.all.item("divopties").style.display="none")
	{
    	divopties.style.display="";
    } 
	else 
	{
    	divopties.style.display="none";
	}
}

function melding(txt)
{
        alert(txt);
}

function GeneralSearchNextPage()
{
	sida = document.search.resultPageSel1.options[document.search.resultPageSel1.selectedIndex].value;
	document.location.href=sida;
}
		
function GeneralSearchNextPage2()
{
	sida = document.search.resultPageSel2.options[document.search.resultPageSel2.selectedIndex].value;
	document.location.href=sida;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
