﻿// JScript File

function $(element) {
  if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
      elements.push($(arguments[i]));
    return elements;
  }
  if (Object.isString(element))
    element = document.getElementById(element);
  return Element.extend(element);
}

/*****************************SART OF SIFR*******************************************/
/*****************************SART OF SIFR*******************************************/
/*****************************SART OF SIFR*******************************************/
/*	sIFR v2.0.7
	Copyright 2004 - 2008 Mark Wubben and Mike Davidson. Prior contributions by Shaun Inman and Tomas Jogin.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

var fontClassFilters = [];
var Font = function(){this.init.apply(this, arguments)};
Font.prototype = {
	fontPath: '/Flash/',
	init: function(swf, options){
		this.swf = this.fontPath + swf;
		this.setOptions(options || {});
		String.prototype.rgbToHex = this.rgbToHex;
		String.prototype.toHex = this.toHex;
		Array.prototype.indexOf = this.indexOf;
	},
	setOptions: function(o){
		this.options = {
			sizeAdjust: o.sizeAdjust || 0,
			color: o.color || o.sColor,
			bgcolor: o.bgcolor,
			width: o.width,
			height: o.height,
			sWmode: o.sWmode || 'transparent',
			tags: o.tags || '',
			classFilter: o.classFilter || ''
		}
		if(o.classFilter) fontClassFilters[fontClassFilters.length] = o.classFilter;
	},
	replace: function(tags){
		var tags = (tags || this.options.tags).split(',');
		for(var i=0; tag=tags[i]; i++)
		{
		
		   this.replaceTag(tag); 
		}	
	},
	replaceTag: function(tag){
		this.replaceElements(document.getElementsByTagName(tag));
	},
	replaceElements: function(els){
		for(var i=0; el=els[i]; i++)
			this.replaceElement(el);
	},
	replaceElement: function(el){
		var o = this.options;
		if(!this.hasFlash || (!o.classFilter && this.hasClassName(el, fontClassFilters)) || (o.classFilter && el.className.indexOf(o.classFilter)==-1) ) return;
		var c = this.options.color || el.style.color || document.defaultView ? document.defaultView.getComputedStyle(el, null).color : el.currentStyle ? el.currentStyle.color : '#000001';
		if(c.indexOf('rgb') > -1) c = '#'+c.rgbToHex();
		else if(c.length == 4) c = '#'+c.charAt(1)+c.charAt(1)+c.charAt(2)+c.charAt(2)+c.charAt(3)+c.charAt(3);
		var width = o.width || (el.offsetWidth + o.sizeAdjust) * .9;//fix for ie floats
		var height = o.height || el.offsetHeight;
		//check for hover element, if that element exists use it's computed style as the hover for the current element
		//the hover element has the same id as the current el with _hover is appended
		var hColor = c;
		var lColor = c;
		var hoverEl = $(el.id + '_hover');
		if (hoverEl != undefined)
		{
            if (document.defaultView!=undefined)
            {
                hColor = hoverEl.style.color || document.defaultView ? document.defaultView.getComputedStyle(hoverEl, null).color : hoverEl.currentStyle ? hoverEl.currentStyle.color : '#000001';
		    }
		    else
		    {
                hColor = hoverEl.style.color || hoverEl.currentStyle ? hoverEl.currentStyle.color : '#000001';
		    }
		    if(hColor.indexOf('rgb') > -1) hColor = '#'+hColor.rgbToHex();
		    else if(hColor.length == 4) hColor = '#'+hColor.charAt(1)+hColor.charAt(1)+hColor.charAt(2)+hColor.charAt(2)+hColor.charAt(3)+hColor.charAt(3);
		}		
		var sVars = 'txt=' + this.escapeHTMLOnly(el) + '&amp;linkcolor=' + lColor + '&amp;hovercolor=' + hColor + '&amp;textcolor=' + c + '&amp;w=' + width + '&amp;h=' + (height+o.sizeAdjust) + '';
		el.oldHTML = el.innerHTML;
		el.innerHTML = '<embed type="application/x-shockwave-flash" src="' + this.swf + '" quality="best" wmode="' + o.sWmode + '" bgcolor="' + o.bgcolor + '" flashvars="' + sVars + '" width="' + width + '" height="' + height + '" sifr="true"></embed>';
	},
	//escapHTMLOnly - extracts the inner text and replaces it after escaping the html portion
	//this is done since escaped french characters will not show up in flash
	escapeHTMLOnly: function(el){
           var finalText;
           var replaceText = 'R_E_P_L_A_C_E_TEXT';//**assumes this string will not be used
           var tempText ='';
           var e_innerHTML = el.innerHTML;
           var tempText= el.innerHTML.unescapeHTML().strip();//unescapeHTML removes the HTML
           e_innerHTML = ReplaceAll(e_innerHTML,'&amp;','&');
           e_innerHTML = ReplaceAll(e_innerHTML,'&lt;','<');
           e_innerHTML = ReplaceAll(e_innerHTML,'&gt;','>');
           e_innerHTML = escape(e_innerHTML).replace(escape(tempText),replaceText);
          // e_innerHTML = e_innerHTML.unescapeHTML().replace(escape(tempText),replaceText);
           e_innerHTML = unescape(e_innerHTML);
           //need to loop through and replace % one at a time since the ReplaceAll 
           //would result in an infinite loop
           while(tempText.indexOf('%25') < tempText.indexOf('%'))
           {
                tempText = tempText.replace('%','%25');
           }           
           tempText = ReplaceAll(tempText,'+','%2B');//our flash does not understand certain chars
           tempText = ReplaceAll(tempText,'&','%26');//so we must replace with their corresponding code
           tempText = ReplaceAll(tempText,'<','');
           tempText = ReplaceAll(tempText,'>','');
           tempText = ReplaceAll(tempText,'"','%22'); // fix quotes
           finalText = escape(e_innerHTML);
           //replace the escaped html with the unescaped inner text
           finalText = finalText.replace(replaceText,tempText);
           
           return finalText;	
	},
	hasClassName: function(el, classNames) {
		var classNames = el.className.split(' ');
		for(var i=0; cn=classNames[i]; i++)
			if(classNames.indexOf(cn)) return true;
		return false;
	},
	indexOf: function(needle){
		for(var i=0; val=this[i]; i++)
			if(val == needle) return i;
		return -1;
	},
	toHex: function(){//borrowed from mootools.net
		var N = parseInt(this);
		if (N==0 || isNaN(N)) return "00";
		N = Math.round(Math.min(Math.max(0,N),255));
		return "0123456789abcdef".charAt((N-N%16)/16) + "0123456789abcdef".charAt(N%16);
	},
	rgbToHex: function(){//borrowed from mootools.net
		var rgb = this.match(/[rgba]{3,4}\(([\d]{0,3}),[\s]([\d]{0,3}),[\s]([\d]{0,3})\)/);
		return rgb[1].toHex()+rgb[2].toHex()+rgb[3].toHex();
	},
	hasFlash: function(){//borrowed from the original sIFR
		var nRequiredVersion = 6;
		if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
			document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
			if(window.hasFlash != null)
				return window.hasFlash;
		};
		if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
			var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
			var version = parseInt(flashDescription.match(/\d+(?=.)/));
			return version >= nRequiredVersion;
		};
		return false;
	}()
}


function ReplaceAll(Source,stringToFind,stringToReplace){
    var temp = Source;
    var index = temp.indexOf(stringToFind);
    while(index != -1){
         temp = temp.replace(stringToFind,stringToReplace);
         index = temp.indexOf(stringToFind);
     }
    return temp;
}


/*****************************END OF SIFR*******************************************/
/*****************************END OF SIFR*******************************************/
/*****************************END OF SIFR*******************************************/

/*****************************START OF DROPDOWN*************************************/
/*****************************START OF DROPDOWN*************************************/
/*****************************START OF DROPDOWN*************************************/
//Chrome Drop Down Menu v2.01- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: November 14th 06- added iframe shim technique
var atag = "";
var browser=navigator.appName;

var cssdropdown={
disappeardelay: 100, //set delay in miliseconds before menu disappears onmouseout
disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no
enableiframeshim: 0, //enable "iframe shim" technique to get drop down menus to correctly appear on top of controls such as form objects in IE5.5/IE6? 1 for yes, 0 for no

//No need to edit beyond here////////////////////////
dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,

getposOffset:function(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;


return totaloffset;
},

swipeeffect:function(){
if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
}
else
return
this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 5)
},

showhide:function(obj, e){
if (this.ie || this.firefox)
this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
if (this.enableswipe==1){
if (typeof this.swipetimer!="undefined")
clearTimeout(this.swipetimer)
obj.clip="rect(0 auto 0 0)" //hide menu via clipping
this.bottomclip=0
this.swipeeffect()
}
obj.visibility="visible"
}
else if (e.type=="click")
obj.visibility="hidden"
},

iecompattest:function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
},

clearbrowseredge:function(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
},

dropit:function(obj, e, dropmenuID){
if (this.dropmenuobj!=null) //hide previous menu
this.dropmenuobj.style.visibility="hidden" //hide menu
this.clearhidemenu()
if (this.ie||this.firefox){
obj.onmouseout=function(){cssdropdown.delayhidemenu()}
obj.onclick=function(){return !cssdropdown.disablemenuclick} //disable main menu item link onclick?
this.dropmenuobj=document.getElementById(dropmenuID)
this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e)}
this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
this.showhide(this.dropmenuobj.style, e)
this.dropmenuobj.x=this.getposOffset(obj, "left")
this.dropmenuobj.y=this.getposOffset(obj, "top");
//this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge") - (this.dropmenuobj.offsetWidth - obj.scrollWidth)+"px"
//remove browser left clear
this.dropmenuobj.style.left=this.dropmenuobj.x- (this.dropmenuobj.offsetWidth - obj.scrollWidth)+"px"

this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight + "px"
//atag.className = 'menuHeader'
//obj.className = "menuHeader menuHover"

//atag = obj
this.positionshim() //call iframe shim function
}
},

positionshim:function(){ //display iframe shim function
if (this.enableiframeshim && typeof this.shimobject!="undefined"){
if (this.dropmenuobj.style.visibility=="visible"){
this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
this.shimobject.style.left=this.dropmenuobj.style.left
this.shimobject.style.top=this.dropmenuobj.style.top
}
this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
}
},

hideshim:function(){
if (this.enableiframeshim && typeof this.shimobject!="undefined")
this.shimobject.style.display='none'
},

contains_firefox:function(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
},

dynamichide:function(e){
var evtobj=window.event? window.event : e
if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
this.delayhidemenu()
else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
this.delayhidemenu()
},

delayhidemenu:function(){
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden';atag.className = 'menuHeader'; cssdropdown.hideshim()",this.disappeardelay) //hide menu
},

clearhidemenu:function(){

if (this.delayhide!="undefined")
{
    clearTimeout(this.delayhide)
}
},

startchrome:function(){
for (var ids=0; ids<arguments.length; ids++){
var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
for (var i=0; i<menuitems.length; i++){
if (menuitems[i].getAttribute("rel")){
var relvalue=menuitems[i].getAttribute("rel")
menuitems[i].onmouseover=function(e){
var event=typeof e!="undefined"? e : window.event
cssdropdown.dropit(this,event,this.getAttribute("rel"))
}
}
}
}
if (window.createPopup && !window.XmlHttpRequest){ //if IE5.5 to IE6, create iframe for iframe shim technique
//document.write('<IFRAME id="iframeshim"  src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"> </IFRAME>')
this.shimobject=document.getElementById("iframeshim") //reference iframe object
}
}

}

function switchHeaderON(headerID)
{
	if ($(headerID) != undefined)
    	$(headerID).src=$(headerID).src.replace('_Off_','_Hover_');
}
function switchHeaderOFF(headerID)
{
	if ($(headerID) != undefined)
	    $(headerID).src=$(headerID).src.replace('_Hover_','_Off_');
}
/*********************************END OF DROPDOWN**********************************************/
/*********************************END OF DROPDOWN**********************************************/
/*********************************END OF DROPDOWN**********************************************/






var modelCardsDisplayed  = false;

var mouseEvent;
function showModelCard(ModelCardID,modelID,modelYear,e)
{
    var MC = $('ModelCard_' + ModelCardID);
    
    $(ModelCardID + '_' + langid).className='nav_item_hover';
    if (modelCardsDisplayed == false)
    {
        //setModelCardFlash();
        MyModelCards.setImagePaths();
    }    
    //check if this model card has been display, if not adjust the x position
    if (MC.style.left == "-1000px")
        adjustModelCardXPosition(e,MC);           
    MC.style.bottom='20px';		

    
    modelCardsDisplayed = true;
}
function setModelCardFlash()
{
	var vwBlack = new Font
					('VWHeadline_Black.swf',{
					tags:'h2',
					classFilter:'vwModelCards'
					});
				vwBlack.replace(); 
	//delay the opening of the model card to give flash time to load
				
}
//adjustModelCardXPosition: adjust the pop up depending on position of the mouse, only the first
//time it's hovered, after that it maintains the same coordinates
function adjustModelCardXPosition(e,MC)
{
    var MC_OFFSET = 130;
    var x_axis = Event.pointerX(e);
   
    var adjustedPos = x_axis - $('mainbanner').offsetLeft - MC_OFFSET;
    //widthDiff = width of screen - width of model card 
    var widthDiff = $('mainbanner').offsetWidth - MC.offsetWidth - 2;
    if (adjustedPos > widthDiff)
        adjustedPos = widthDiff;
    else if (adjustedPos < MC_OFFSET)
        adjustedPos = 0;	
    MC.style.left = adjustedPos.toString() + 'px';
}

function hideModelCard(ModelCardID)
{
    $('ModelCard_' + ModelCardID).style.bottom='1000px';
    $(ModelCardID + '_' + langid).className='nav_item';
}

// ------------------------------------------------------------------
function showModelCard2(ModelCardID,modelID,modelYear,xpos)
{
    var MC_OFFSET = 130;
    var MC = $('ModelCard_' + ModelCardID);

    $(ModelCardID + '_' + langid).className='nav_item_hover';
    if (modelCardsDisplayed == false)
        MyModelCards.setImagePaths();
     
    //check if this model card has been display, if not adjust the x position
    if (MC.style.left == "-1000px")
    {
        var adjustedPos = xpos - $('mainbanner').offsetLeft - MC_OFFSET;
        var widthDiff = $('mainbanner').offsetWidth - MC.offsetWidth - 2;
        if (adjustedPos > widthDiff)
            adjustedPos = widthDiff;
        else if (adjustedPos < MC_OFFSET)
            adjustedPos = 0;	
        MC.style.left = adjustedPos.toString() + 'px';    
    }
         
    MC.style.bottom='20px';		
   
    modelCardsDisplayed = true;
}
// ------------------------------------------------------------------
var ModelCards = Class.create();
ModelCards.prototype = {
    ModelCardList: [],
    
    initialize: function(ModelCardList) 
    {
        this.ModelCardList = ModelCardList;
    },
    //setImagePaths: used to set all the images for the model cards 
    setImagePaths: function()
    {
        var t_ModelCard= {};
        for (x = 0; x < this.ModelCardList.length; x++)
        {
            var currModelCard = this.ModelCardList[x];
            var mainImg = $(currModelCard.trimID + '_' +  currModelCard.modelYear +'_mainImage');
            mainImg.src = currModelCard.mainImagePath;
            
            for (y = 0; y < currModelCard.thumbPaths.length; y ++)
            {
                var currColorChip = currModelCard.thumbPaths[y];
                var currThumb = $(currModelCard.trimID + '_' + currModelCard.modelYear + '_' + currColorChip.colorID + '_' + currModelCard.modelID);
                currThumb.style.backgroundImage = 'url(' + currColorChip.imagePath + ')';
            }
         }
        return t_ModelCard;
    }    
}

var ModelCard = Class.create();
ModelCard.prototype = {
    mainImagePath:'',
    modelYear:'',
    modelID:'',
    trimID:'',
    thumbPaths:[],
    initialize: function(trimID,modelID,modelYear,firstColor,thumbImages)   {
        this.trimID = trimID;
        this.modelID = modelID;
        this.modelYear = modelYear;
        this.mainImagePath = "/media/ModelCardPopUp/" + modelYear + "/Model" + modelID + "/" + trimID + "_Year_" + modelYear + "_Colour_" + firstColor + "_Shot1.jpg";
        this.thumbPaths = thumbImages;
    }
}

var ColorChip = Class.create();
ColorChip.prototype = {
    colorID: '',
    imagePath: '',
    initialize: function(colorID) {
        this.colorID = colorID;
        this.imagePath = '/media/ModelCardPopUp/ExteriorSwatches/' + colorID + '.jpg';
    }
}
//checkForOpenModelCards checks to see if model cards are open
//before opening the first one
/*
function checkForOpenModelCards(ModelCardID)
{
   
    var MCards = $('mainbanner').getElementsByClassName('ModelCard');
    //check to see if any cards are currently open
    var shouldOpen = true;
    for (x=0;x<MCards.length;x++)
    {
        if(MCards[x].style.bottom =='20px')
        {
            shouldOpen = false;
        }
    }
    if (shouldOpen)
        $('ModelCard_' + ModelCardID).style.bottom='20px';
}
*/
function changeModelNavToYear(year)
{
    setCookie(ModelYearCookie,year,365);
	var allModelNavs = $('mainbanner').getElementsByClassName('ModelNav');
	for (x = 0; x < allModelNavs.length;x++)
	{
		allModelNavs[x].hide();
								
	}
	var allModelNavYearSelectors = $('mainbanner').getElementsByClassName('ModelNavYearSelector_active');
	for (x = 0; x < allModelNavYearSelectors.length; x++)
	{
	    allModelNavYearSelectors[x].id = allModelNavYearSelectors[x].id.replace('_active','');
		allModelNavYearSelectors[x].className = allModelNavYearSelectors[x].className.replace('_active','');
		
	}
	$('ModelNav_' + year).show();
	$('ModelNavYearSelector_' + year).className+='_active';
	$('ModelNavYearSelector_' + year).id+='_active';
}


function switchColor(colorChipID)
{
	var colorCode = colorChipID.split("_")[2];
	var trimID = colorChipID.split("_")[0];
	var modelYear = colorChipID.split("_")[1];
	var modelID = colorChipID.split("_")[3];
	$(trimID + '_' + modelYear + '_mainImage').src='/media/ModelCardPopUp/' + modelYear + '/Model' + modelID + '/' + trimID + '_Year_' + modelYear + '_Colour_' + colorCode + '_Shot1.jpg';
	var selectedEl = $(trimID + '_' + modelYear + '_mainImageWrapper').getElementsByClassName('selectedColor');
	selectedEl[0].className = 'unselectedColor';
	$(colorChipID + '_selectedColor').className = 'selectedColor';
	//$('routan_image').style.backgroundImage='url(/Images/temp/GalleryFull_20203_Year_2009_Colour_10450.jpg)';
}

function loadPreOwnedImages()
{
	if (!preOwnedImagesAreLoaded)
	{
	    for (x=0;x<preOwnedImages.length; x++)
	    {
	       if ($('image_' + preOwnedGuid[x]) != undefined && preOwnedImages[x] != '')
	        $('image_' + preOwnedGuid[x]).src = preOwnedImages[x];
	    }
		preOwnedImagesAreLoaded = true
	}
}



function addHover(el)
{
    el.className += '_hover';
}
function removeHover(el)
{
    el.className = el.className.replace('_hover','');
}
function addHoverID(el)
{
    el.id += '_hover';
}
function removeHoverID(el)
{
    el.id = el.id.replace('_hover','');
}

//checkForFlash is used on the homepage, if no flash is installed, put in image
function checkForFlash(langid)
{
    var isValid = false;
    try
    {
	    var version = getFlashVersion().split(','); 
	    if (version[0] > 9)
		    isValid = true;
	    else if(version[0]==9)
	    {
	        if(version[1]>0)
	            isValid = true;
	        else if(version[1]==0)
	        {
	            if(version[2] >=115)
	                isValid = true;
	        }        
	    }
	}
	catch(err){}
	if (!isValid)
	    $('HeroFlash').innerHTML = '<img src="Images/Home/noFlashHero_' + langid + '.jpg" onerror="this.src=\'Images/Home/noFlashHero_2.jpg\'" //>';	
}
/**************PopUps START**************************/
/**************PopUps START**************************/
function openPopUp(link,name,height)
{
    window.open(link, name,"width=850,height=" + height + ",scrollbars=yes,resizable=1");
}
/**************PopUps END**************************/
/**************PopUps END**************************/
function addOuterHTML(e)
{
    if (document.body.__defineGetter__) {
           if (HTMLElement) {
                  var element = HTMLElement.prototype;
                  if (element.__defineGetter__) {
                         element.__defineGetter__("outerHTML",
                               function () {
                                      var parent = e.parentNode;
                                      var el = document.createElement(parent.tagName);
                                      el.appendChild(e);
                                      var shtml = el.innerHTML;
                                      parent.appendChild(e);
                                      return shtml;
                               }
                         );
                  }
           }
    }
}


//submitLang is used by the language selector to switch the language 
//and resubmit the page.  Takes into account there possibly being
//other query params, so it won't affect those
function submitLang(lng)
{
	var queryParams = document.location.href.toQueryParams();
	
	//if it isn't in the query string add it
	if (queryParams.lng == undefined)
	{
		if (document.location.href.include('?'))
		{
			document.location = document.location.href + '&lng=' + lng ;
		}
		else
		{
			document.location = document.location.pathname + '?lng=' + lng;
		}
	}
	else //else change the query param to the correct lang
	{
		queryParams.lng=lng;
		document.location = document.location.pathname + '?' + Object.toQueryString(queryParams);
	}
}


/************* Cookie functoins start ******************/ 
/************* Cookie functoins start ******************/ 
 
function getCookie(c_name)
{
    var _c = "";
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
            _c=unescape(document.cookie.substring(c_start,c_end));
            
        }
      }
    //alert("getting: cookie " + c_name + " value: " + _c);
    return _c;
}

function setCookie(c_name,value,expiredays)
{
    delete_cookie(c_name);
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString() + "; path=/");
    //alert("setting: " + document.cookie);
}

function delete_cookie(cookie_name)
{
  var cookie_date = new Date();  // current date & time
  cookie_date.setTime(cookie_date.getTime() - 1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

/************* Cookie functoins start ******************/ 
/************* Cookie functoins start ******************/ 

function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
}
