﻿var CITIES_LIST_PLACEHOLDER = "cities_placeholder";
var LOCATIONS_LIST_PLACEHOLDER = "locations_placeholder";
var BUTTON_ID = "submit";
var MORE_ID = "more";
var TD_CITIES_ID = "cities_wrapper";
var TD_LOCATIONS_ID = "locations_wrapper";
var EXPLORER_USER_AGENT_STRING = "Microsoft Internet Explorer";
var USA_COUNTRY_ID = 254;
var SELECT_ONE = "Select One...";
var postCallbackEvent = null;
var agentFinder = null;
var selectedPid = "";
var openTab;
var tab_links;
var defaultTab;
var prefix;
var forPrinting;
var locationPrefix = "";
var tabCms = 0;

//Function called by every page
function els_onload()
{
    initializeCollapsableItems();
    initializePagedItems();
    initializeOverlay();
    initTabs();
    if(document.forPrinting || forPrinting)
    {
        document.getElementsByTagName("body")[0].className = "print";
        print();
    }
}

//Initializes the collapse behavior of the items with class "collapsable"
function initializeCollapsableItems()
{
    var elements = getElementsByClassName("collapsable");
    for (var i=0;i<elements.length;i++)
    {
        addEventSimple(elements[i],"click",collapseItem);
    }
}

//Collapse the next sibling or sibling child (div) with class "collapse"
function collapseItem(e)
{
    var collapsed;
    var evt = e || window.event;
    var trigger = evt.target || evt.srcElement;
    var children;

    if (trigger.className && trigger.className.indexOf("collapsed")>=0)
    {
        trigger.className = trigger.className.replace("collapsed","");
        collapsed = false;
    }
    else
    {
        trigger.className = trigger.className + " collapsed";
        collapsed = true;
    }

    while (trigger)
    {    
        trigger = trigger.nextSibling;    
        if (trigger && trigger.className && trigger.className.indexOf("collapse")>=0)
        {
            trigger.style.display = collapsed?"none":"";
            return;
        }
        else
        {
            children = getElementsByClassName("collapse","div",trigger);
            if (children[0])
            {
                children[0].style.display = collapsed?"none":"";
                return;
            }
        }        
    }
}

//Initializes the pager for item with class "paged"
function initializePagedItems()
{
    var elements = getElementsByClassName("paged");
    var pages;
    var maxHeight;
    
    for (var i=0; i<elements.length; i++)
    {
        pages = getElementsByClassName("page","div",elements[i]);
        
        elements[i].pager = createPager();
        elements[i].pager.pages = pages;       
        
        if (elements[i].pager.pages.length < 2)
        {
            elements[i].className = elements[i].className.replace("paged", "");
        }
        else
        {
            elements[i].pager.activePage = 0;
            elements[i].appendChild(elements[i].pager);
            maxHeight = 0;
            for (var j=1; j<pages.length; j++)
            {
                pages[j].style.display = "none";
            }
        }
    }
}

//Creates a pagger including the previous and next buttons
function createPager()
{
    var pager = document.createElement("div");
    var next = document.createElement("a");
    var prev = document.createElement("a");
    
    pager.className = "pager";

    next.className = "right_icon next";
    prev.className = "left_icon prev";
    
    prev.id="prev_button";
   
    prev.innerHTML = $("ctl00_hidPrevious").value;
    next.innerHTML = $("ctl00_hidNext").value;
    
    prev.onclick = function () {
            goToPage(this, -1);
        };
    next.onclick = function () {
            goToPage(this, 1);
        };
    
    pager.appendChild(prev);
    pager.appendChild(next);
    
    pager.prev = prev;
    pager.next = next;
    
    prev.style.display = "none";
    
    return pager;    
}

//Changes the selected page
function goToPage(trigger, value)
{
    var parent = trigger.parentNode;
    var newIndex = parent.activePage + value;
    
    if (newIndex<0)
        newIndex = 0;
    
    if (newIndex>=parent.pages.length)
        newIndex = parent.pages.length - 1;
        
    if (newIndex == 0)
        parent.prev.style.display="none";
    else
        parent.prev.style.display="";

    if (newIndex == (parent.pages.length-1))
        parent.next.style.display="none";
    else
        parent.next.style.display="";

    parent.pages[parent.activePage].style.display="none";
    parent.pages[newIndex].style.display="";

    parent.activePage = newIndex;
}

//Opens a page in print view
function openPrintVersion()
{
    var win = window.open(location.href, "print_version", "width=770,height=600px,menubar=1,scrollbars=1");
    win.document.forPrinting=true;
    win.forPrinting=true;
}

//Weather temperature scale change
function switchTemperatures(scale,trigger)
{
    if (trigger.className.indexOf("inactive")>-1)
        return;
    
    var elements = getElementsByClassName("temperature");
    var triggers = getElementsByClassName("temp_handler");
    var factor;
        
    for (var i=0;i<elements.length;i++)
    {
        if (scale=='C' && !elements[i].celsius)
        {
            elements[i].farenheit = elements[i].innerHTML;
            elements[i].celsius = Math.round((elements[i].innerHTML - 32) * (5/9));
        }
            
        if (scale=='F')
             elements[i].innerHTML =  elements[i].farenheit;
        else     
             elements[i].innerHTML =  elements[i].celsius;
            
    }   
    
    for (var i=0;i<triggers.length;i++)
    {
        if (triggers[i].className.indexOf("inactive")>-1)
            triggers[i].className = triggers[i].className.replace("inactive", "active");
        else
            triggers[i].className = triggers[i].className.replace("active", "inactive");
    }
}

//Goes to a program page
function goToProgram(list)
{
   if (list.value && list.value!=0)
   {
      location.href="program_details.aspx?pid="+list.value;
   }
}

//Opens a popup window
function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'width=550,height=500,scrollbars=yes');
	//return true;
}

//Handles changes in the country selected.
function countrySelected(lstdCountries, agentSearch)
{    agentFinder = agentSearch;
    if (lstdCountries.options[lstdCountries.selectedIndex].value == USA_COUNTRY_ID)
    {
        $("stateSelection").style.display = "";
        $("zipEntry").style.display = "";
        $(CITIES_LIST_PLACEHOLDER).innerHTML = "";
        stateSelected($("lstdStates"));
    }
    else
    {
        $("lstdStates").options[0].selected = true;
        $("stateSelection").style.display = 'none';
        $("zipEntry").style.display = 'none';
            AJAXMethods.getCitiesByCountry(lstdCountries.options[lstdCountries.selectedIndex].value, 
                                        true, "lstdCities", citiesLoadCallback);
    }
}

//Handles changes in the state selected.
function stateSelected(lstdStates, locPrefix)
{
    locationPrefix = locPrefix || "";
    selectedPid = selectedPid || "";
    AJAXMethods.getCitiesByState(lstdStates.options[lstdStates.selectedIndex].value, locationPrefix+"lstdCities", selectedPid, lstdStates.onlyWithAgents == true, citiesLoadCallback );
    if (postCallbackEvent)
        postCallbackEvent();
    postCallbackEvent = null;
}

function stateSelectedShowCities(lstdStates)
{
    AJAXMethods.getLocationsByState(lstdStates.options[lstdStates.selectedIndex].value, "lstdLocations", locationsLoadCallback);
}

function citiesLoadCallback(response)
{
    var select;
    var pos;
    if (response.error!=null || response.value==null)
    {
        //alert("There was an error loading the Cities, please try again");
        return;
    }
    $(locationPrefix + TD_CITIES_ID).style.display = "";
    select = response.value;
    if (agentFinder)
    {
        pos = select.indexOf(">") + 1;
        select = select.substring(0, pos) + '<option value="0">' + SELECT_ONE + '</option>' + select.substring(pos);
    }
    $(locationPrefix + CITIES_LIST_PLACEHOLDER).innerHTML = select;    
    var cities = $(locationPrefix + "lstdCities");   
    //cities.attributes["onchange"].value = "citySelected(this, '"+locationPrefix+"')";   
    cities.locationPrefix = locationPrefix;
    addEventSimple(cities, "change", function(){ citySelected(cities, cities.locationPrefix); });
    
    citySelected(cities, locationPrefix);
    response = null;
}

//Handles changes in the city selected.
function citySelected(lstdCity, locPrefix)
{
    locationPrefix = locPrefix || "";
    if ($(locationPrefix + LOCATIONS_LIST_PLACEHOLDER) != null)
        AJAXMethods.getLocationsByCity(lstdCity.options[lstdCity.selectedIndex].value, locationPrefix + "lstdLocations", selectedPid, locationsLoadCallback );
  //  if (postCallbackEvent)
    //    postCallbackEvent();
    postCallbackEvent = null;
}

function locationsLoadCallback(response)
{
       
    if (response.error!=null || response.value==null)
    {
        //alert("There was an error loading the Locations, please try again");
         $(locationPrefix + TD_LOCATIONS_ID).style.display="none";  
        return;
    }
    if ($(locationPrefix + TD_LOCATIONS_ID))
    {
      //  $(locationPrefix + TD_LOCATIONS_ID).style.display = ""
       
    }
    $(locationPrefix + LOCATIONS_LIST_PLACEHOLDER).innerHTML = response.value;
    if ($(locationPrefix + MORE_ID))
    {
        $(locationPrefix + MORE_ID).style.display = "";
     }
    response = null;
    if ($(locationPrefix + "lstdLocations") && $(locationPrefix + "lstdLocations").options.length==1)
       { 
            $(locationPrefix + TD_LOCATIONS_ID).style.display="none";
       }else 
       {
           if ($(locationPrefix + "lstdLocations").options.length>1)
                $(locationPrefix + TD_LOCATIONS_ID).style.display="";
       }
}


//Handles changes in the state selected.
function ajaxCountrySelected(lstdCountries, onlyWithAgents)
{
    AJAXMethods.getCitiesByCountry(lstdCountries.options[lstdCountries.selectedIndex].value, onlyWithAgents, "lstdCities", citiesLoadCallback );
    if (postCallbackEvent)
        postCallbackEvent();
    postCallbackEvent = null;
}

function controlEnable(idControl, enable)
{
    var control = $(idControl);
    if (control != null)
    {
        if (enable)
            control.disabled = '';
        else
            control.disabled = 'disabled';
    }
}

//Toggles the visibility of a part of the CMS
function toggleVisibility(elementId, visibility, header)
{
    var element = $(elementId);
    var hidden = $(elementId+'Hidden');
    if(element.style.display == 'none')
    {
        hidden.value = element.style.display = visibility;               
    }
    else
    {
        hidden.value = element.style.display = 'none';
    }
    changeIcon(element.style.display, header);
}

//Loads the visibility of a part of the CMS
function loadVisibility(elementId)
{
    var element = $(elementId);
    var hidden = $(elementId+'Hidden');
    var header = $(elementId+'Header');

    if (element && hidden && header)
    {
        element.style.display = hidden.value;
        changeIcon(element.style.display, header);
    }
}

//Looks for the divs of the CMS that needs to be displayed
function loadCMSVisibility()
{
    var elements = document.getElementsByTagName('div');
    var divs = "";
    for (i=0;i<elements.length;i++)
    {
        if (elements[i].attributes['class'] != undefined && 
            elements[i].attributes['class'].value == 'cmsSection')
        {            
            loadVisibility(elements[i].id);
           
        }
    }
}

//Changes the icon of the header according to the visibility of the section
function changeIcon(visibility, header)
{
    if (header)
    {
        if (visibility == 'none')
        {
            header.style.backgroundImage="url('../assets/images/more.gif')";    
        }
        else
        {
            header.style.backgroundImage="url('../assets/images/less.gif')";    
        }
    }
}

//Funtions to put Flash movies
function putMap(experience)
{
    var so = new SWFObject("../assets/media/els_map_home.swf", "LocationsMaps", "530", "400", "8", "#FFFFFF");
    var holder = $("mapHolder");
    holder.innerHTML = 'To access special site features, please click <a href="http://www.adobe.com/go/getflashplayer" title="Get Adobe Flash Player">here</a> to download the latest version of Adobe&reg; Flash Player.';
    if (experience)
    {
        so.addParam("FlashVars", "experienceBuilder=1");
    }
    so.write("mapHolder");    
}


function putHeader(url)
{
    var so = new SWFObject(url, "header", "750", "159", "8", "#F0F0F0");
    var holder = $("bannerHolder");
    holder.innerHTML = 'To access special site features, please click <a href="http://www.adobe.com/go/getflashplayer" title="Get Adobe Flash Player">here</a> to download the latest version of Adobe&reg; Flash Player.';
    so.addParam("wmode", "transparent");
	so.write("bannerHolder");  
}

function putSlideShow(div, url)
{
    var fo = new SWFObject("../assets/media/photoVideoGallery.swf", "photoVideoGallery_swf", "371", "335", "8", "#ffffff");
    fo.addParam("allowScriptAccess", "sameDomain");
    fo.addParam("wmode", "transparent");
    fo.addVariable("imgPath", "../assets/locations/images/");
    fo.addVariable("vidPath", "../locations/videos/");
    fo.addVariable("thPath", "../assets/locations/thumbs/");
    fo.addVariable("xmlPath", "../xml/xml_query.aspx"+escape(url));
    fo.addVariable("imgFile", "../interface/thumbnail.aspx");
    fo.write(div);
}

//Studen Tube page//
function putSmallPlayer(player_url)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="150" height="114" align="middle">\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
    document.write('<param name="movie" value="'+player_url+'" />\n');
    document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
    document.write('<embed wmode="transparent" quality="high" width="152" height="114" src="'+player_url+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
    document.write('</object>\n');
}

function putPlayer(player_url, video_url)
{
    var completeURL = player_url + "?videoPath=" + video_url;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="280" align="middle">\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
    document.write('<param name="movie" value="'+completeURL+'" />\n');
    document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
    document.write('<embed wmode="transparent" quality="high" width="320" height="280" src="'+completeURL+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
    document.write('</object>\n');
}

function putFlash(flash_url, width, height)
{
    var completeURL = flash_url;
	var flash_height = height;
	var flash_weight = width;
	document.write('<object clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+flash_weight+'" height="'+flash_height+'" align="middle">\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
    document.write('<param name="movie" value="'+completeURL+'" />\n');
    document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
    document.write('<embed wmode="transparent" quality="high" width="'+flash_weight+'" height="'+flash_height+'" src="'+completeURL+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" />\n');
    document.write('</object>\n');
}

function putAlbum(albumID, userID, authKey)
{
	var id = albumID;
	var user = userID;
	var auth = authKey;
	document.write('<embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="400" height="267" flashvars="host=picasaweb.google.com&captions=1&hl=en_US&feat=flashalbum&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F'+userID+'%2Falbumid%'+albumID+'%3Falt%3Drss%26kind%3Dphoto%26authkey%'+authKey+'%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
}

function putVideoAlbum(videoId){
	var id = videoId;
	document.write('<object width="400" height="267"><param name="movie" value="http://www.youtube.com/p/'+id+'&amp;hl=en"></param><embed src="http://www.youtube.com/p/'+id+'&amp;hl=en" type="application/x-shockwave-flash" width="400" height="267"></embed></object>');
}

function validateVideoForm()
{
	error = "";	
	if($("name").value == ""){ error += "- Name is required\n"; }
	if($("email").value != ""){
		if($("email").value.indexOf("@") == -1){
			error += "- Invalid email\n";
		}
	}else{
		error += "- E-mail is required\n";
	}
	if($("video_miArchivo").value == ""){ error += "- You must select a video\n"; }	
	if(!$("agree").checked){ error += "- You must accept the Terms & Conditions\n"; }
	if(!error == ""){
		alert("Please check the following errors:\n" + error);
		return false;
	}else{
		return true;
	}	
}

function validatePhotoForm()
{
	error = "";	
	if($("name2").value == ""){ error += "- Name is required\n"; }
	if($("email2").value != ""){
		if($("email2").value.indexOf("@") == -1){
			error += "- Invalid email\n";
		}
	}else{
		error += "- E-mail is required\n";
	}
	if($("testimonial").value == ""){ error += "- Testimonial is required\n"; }
	//if($("video_miArchivo").value == ""){ error += "- You must select a video\n"; }	
	if(!$("agree2").checked){ error += "- You must accept the Terms & Conditions\n"; }
	if(!error == ""){
		alert("Please check the following errors:\n" + error);
		return false;
	}else{
		return true;
	}	
}
//end Student Tube page
//IELST
function centerPopup(popup){
	var arrayPageSize = getPageSize();
    var w = (arrayPageSize[0]);
	popup.style.position = "absolute";
    if(popup){
       popup.style.top = (getScrollXY()[1] + 100) + "px";
	   var positionW = (w/2)-(popup.clientWidth/2);
	   var finalPercentage = Math.round((positionW*100)/w) + "%";
	   //popup.style.left = (w/2)-(popup.clientWidth/2) + "px";
		popup.style.left = finalPercentage;
	}
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
         scrOfY = window.pageYOffset;
         scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
function showContactInformation(action)
{
	if(action){
		$("contactInformation").style.display = "inline";
		centerPopup($("contactInformation"));
	}else{
		$("contactInformation").style.display = "none";
	}
}
//IELST
function goToSearchPage(queryString)
{
    var path = location.href.substring(0, location.href.lastIndexOf("/")+1);
    if (!queryString)
        queryString = "";
    location.href = "agent_search.aspx" + queryString;
}

function loadSearchState()
{
    var lstdCountries = $("lstdCountries");
    var lstdCities = $("lstdCities");
    var lstdStates = $("lstdStates");
    var txtZip = $("txtZip");
    var id;
    
    //lstdCountries.selectedIndex = 0;
    
    //Country
    id = extractQueryStringValue("country");
    if (id && lstdCountries.value != id)
    {
        lstdCountries.value = id;
        postCallbackEvent = loadSearchState;
        lstdCountries.onchange();
        return;
    }
    if (id && id==USA_COUNTRY_ID)
    {
        id = extractQueryStringValue("state");
        if (id && lstdStates.value != id)
        {
            lstdStates.value = id;
            postCallbackEvent = loadSearchState;
            lstdStates.onchange();                
            return;
        }                                        
    }

    id = extractQueryStringValue("city");
    if (id && lstdCities && lstdCities.value != id)
    {
        lstdCities.value = id;
    }

    id = extractQueryStringValue("zip");
    if (id && txtZip && txtZip.value != id)
    {
        txtZip.value = id;
    }
}

function extractQueryStringValue(key)
{
    var value;
    var portion;
    if (!location.search)
        return;
    portion = location.search.indexOf("&"+key+"=");
    if (portion == -1)
        portion = location.search.indexOf("?"+key+"=");
    if (portion != -1)
    {
        portion = location.search.substring(portion+1);
        portion = portion.split("=")[1].split("&")[0];
        if (portion)
            return portion;
    }
    return null;
}

function validateAgentSearch()
{
    var lstdCountries = $("lstdCountries");
    var lstdStates = $("lstdStates");
    var lstdCities = $("lstdCities");
    var txtZip = $("txtZip");
    if (lstdCountries.value == USA_COUNTRY_ID)
    {
        if (txtZip.value)
        {
            return true;
        }else
        {
            return lstdStates.value != 0 && lstdCities.value != 0;
        }
    }else
    {    
        return lstdCountries.value != 0 && lstdCities.value != 0;
    }    
}

function checkEmail(email)
{
    var re = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
    return (email.match(re) != null);
}

/*********************************************************************/
/************************HELPER FUNCTIONS*****************************/
/*********************************************************************/

//Taken from the book "PPK on Javascript"
function addEventSimple(obj, evt, fn)
{
    if (obj.addEventListener)       
        obj.addEventListener(evt, fn, false);
    else if (obj.attachEvent)
        obj.attachEvent('on'+evt, fn);
}

function $(id)
{
    var element;
    if (!prefix)
        prefix = "";
    element = document.getElementById(prefix + id) || document.getElementById(id); 
    return element;
}

function getPageSize(){	
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

/*********************************************************************/
/*************************TABS HANDLING*******************************/
/*********************************************************************/

//window.onload = initTabs;

function initTabs()
{
    var tabs_wrapper = $("tabs_wrapper");
    if (!tabs_wrapper)
        return;

    tab_links = tabs_wrapper.getElementsByTagName("a");

    if (location.hash)
    {
        switchTabByHash(location.hash);
    }
    else {
        if (tabCms == 0)
            showDefaultTab();
    }
}

function showDefaultTab()
{
    if (defaultTab)
    {
       switchTab(defaultTab); 
    }
    else
    {
        for (var i=0;i<tab_links.length;i++)
        {
            if (tab_links[i].className.indexOf("tab_on")>-1)
            {
                switchTab(tab_links[i]);
                return;
            }
        }
    }
}

function switchTab(source)
{
    if (source.href)
        switchTabByHash(source.href); 
}

function switchTabByHash(hash)
{
    var id, hashIndex;
    hashIndex = hash.lastIndexOf("#els_");
    if (hashIndex > -1)
    {
        id = hash.substring(hashIndex+5);
    }
    if (id)
    {
        switchTabById(id);
        location.hash = "#els_"+id;
    }
    else
    {
        showDefaultTab();
    }
}

function switchTabById(id)
{
    var anchors;
    var anchorsWrapper = $("tab_anchors_wrapper");
    if (openTab)
    {
        openTab.className="tab_content"; 
        anchors = $(openTab.id+"_anchors");
        if (anchors)
            anchors.style.display="";
    }
    openTab = $(id);
    if (openTab && openTab.className!="tab_content")
    {
        openTab = null;
        showDefaultTab();
    }
    else if (openTab)
    {
        anchors = $(openTab.id+"_anchors");
        openTab.className="tab_content_visible";
        if (anchors)
        {
            anchors.style.display="";
            anchorsWrapper.style.display="block";
        }
        else
        {
            if (anchorsWrapper)
                anchorsWrapper.style.display="none";
        }
        setActiveTab(id);
    }
}

function setActiveTab(id)
{
    for (var i=0;i<tab_links.length;i++)
    {
        if (tab_links[i].href.indexOf(id)>-1)
        {
            tab_links[i].className = "tab_on";
            if (!defaultTab)
                defaultTab = tab_links[i];
        }
        else
            tab_links[i].className = "tab_off";
    }
}

/*********************************************************************/
/***********************LOCATIONS FUNCTIONS***************************/
/*********************************************************************/
function showDescription(source)
{
    var spans = source.parentNode.getElementsByTagName("span");
    var divs = source.parentNode.getElementsByTagName("div");
    var hiddens = source.parentNode.getElementsByTagName("input");
    var showMessage, hideMessage;   
    source.visible = !source.visible;
    for (var i = 0; i<spans.length; i++)
    {
        if (source.visible)        
            spans[i].style.display = "inline";
        else 
            spans[i].style.display = "none";                    
    }
    for (var i = 0; i<divs.length; i++)
    {
        if (divs[i].className == "description")
        {            
            if (source.visible)
                divs[i].style.display = "block";
            else 
                divs[i].style.display = "none";                    
        }
    }
    for (var i = 0; i<hiddens.length; i++)
    {
        if (hiddens[i].className == "show_message")
            showMessage = hiddens[i].value;
        if (hiddens[i].className == "hide_message")
            hideMessage = hiddens[i].value;         
    }
    if (source.visible)
    {
        source.className = "right_icon up_arrow";
        if (showMessage)
            source.innerHTML = hideMessage;
    }
    else
    {
        source.className = "right_icon down_arrow";        
        if (hideMessage)
            source.innerHTML = showMessage;
    }       
}

function showLocationMap(latitude, longitude, center, address, address2)
{
    mapInfo = new Object();
    mapInfo.latitude = latitude;
    mapInfo.longitude = longitude;
    mapInfo.center = center;
    mapInfo.address = address;
    mapInfo.address2 = address2;
}

function showLocationMapDelay()
{
    setTimeout(function()
        {
            if (GBrowserIsCompatible() && mapInfo) {
               map = new GMap2($("map_canvas"));
               var center = new GLatLng(mapInfo.latitude,mapInfo.longitude);
               var marker = new GMarker(center);
               var myHtml = "<strong>"+mapInfo.center+"</strong><br />"+
                            mapInfo.address+"<br />"+mapInfo.address2;
               map.setCenter(center, 13);
               map.addOverlay(marker);
               map.addControl(new GLargeMapControl());
               map.addControl(new GMapTypeControl());
               map.openInfoWindowHtml(center, myHtml);
               GEvent.addListener(marker,"click", function() {
                 map.openInfoWindowHtml(center, myHtml);
               });
            }
        }, 200);
}


/* OVERLAY */

//Initialize the div to opaque the page when opening overlay
function initializeOverlay()
{
    var objBody = document.getElementsByTagName("body").item(0);

    overlayBack = document.createElement("div");
  	overlayBack.onclick = function () {closeOverlay(); return false;}
	overlayBack.style.display = 'none';
	overlayBack.style.position = 'absolute';
	overlayBack.style.top = '0';
	overlayBack.style.left = '0';
	overlayBack.style.zIndex = '90';
 	overlayBack.style.width = '100%';
 	overlayBack.style.backgroundColor = '#323232';
 	overlayBack.style.filter = 'alpha(opacity=90)';
 	overlayBack.style.MozOpacity = '0.90';
 	overlayBack.style.opacity = '0.90';
 
    objBody.insertBefore(overlayBack, objBody.firstChild);
}



function showOverlay(content)
{
    var dimensions = getPageSize();
    var toHide, toShow;
    
    overlayBack.style.height = dimensions[1]+"px";
    overlayBack.content = $(content);
    overlayBack.content.style.zIndex="100";
    overlayBack.content.style.position = 'absolute';
    overlayBack.content.style.display = overlayBack.style.display="block";
    
    overlayBack.content.style.top="80px";
    overlayBack.content.style.left = dimensions[0]/2 - overlayBack.content.clientWidth/2 + "px"; 
    
    scrollTo(0,0);        
    
    //The function is complete, but the following code is needed for IE support
    toHide = document.getElementsByTagName("select");
    for (var i=0; i<toHide.length; i++)
    {
        toHide[i].previousDisplay = toHide[i].parentNode.style.display;
        toHide[i].parentNode.style.display = "none";
    }

    toHide = document.getElementsByTagName("object");
    for (var i=0; i<toHide.length; i++)
    {
        toHide[i].previousDisplay = toHide[i].parentNode.style.display;
        toHide[i].parentNode.style.display = "none";
    }

    toShow = overlayBack.content.getElementsByTagName("select");
    for (var i=0; i<toShow.length; i++)
    {
         toShow[i].parentNode.style.display = toShow[i].previousDisplay;
    }

    toShow = overlayBack.content.getElementsByTagName("object");
    for (var i=0; i<toShow.length; i++)
    {
         toShow[i].parentNode.style.display = toShow[i].previousDisplay;
    }    
}

function closeOverlay()
{
    overlayBack.content.style.display = overlayBack.style.display = "none";

    //The function is complete, but the following code is needed for IE support
    toHide = document.getElementsByTagName("select");
    for (var i=0; i<toHide.length; i++)
    {
         toHide[i].parentNode.style.display = toHide[i].previousDisplay;
    }

    toHide = document.getElementsByTagName("object");
    for (var i=0; i<toHide.length; i++)
    {
        toHide[i].parentNode.style.display = toHide[i].previousDisplay;
    }
}


/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
    //JM : Disable native implementations
	if (document.getElementsByClassName && false) {
		getElementsByClassName = function (className, tag, elm) {
			    alert(elm + "\n" + elm.getElementsByClassName)
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
}
