function addEvent(obj, evType, fn)
{
    try
    {
		if (obj.addEventListener)
		{ 
			obj.addEventListener(evType, fn, false); 
			return true; 
		} 
		else if (obj.attachEvent)
		{ 
			var r = obj.attachEvent("on"+evType, fn); 
			return r; 
		}
		else
		{ 
			return false;
		}
    } catch(e){}
}

try
{
	addEvent(window, 'load', windowOnload);
} catch (e) { }



function windowOnload()
{
	RunOnLoadScripts();
}

var OnLoadScripts = [];
var scriptCount = 0;

function RunOnLoadScripts()
{	
	for(var i=0;i<OnLoadScripts.length;i++)
	{
		eval(OnLoadScripts[i]);
	}
}

function showHide(s) {
    var q = document.getElementById(s);
    if (q.style.display == '')
        q.style.display = 'none';
    else
        q.style.display = '';
}


function AddOnLoadScript(s,first)
{
	if(first)
	    OnLoadScripts.unshift(s);
	else
	    OnLoadScripts.push(s); 	
}

function SetAnchorOnloadScript(name,script)
{   
    if(window.location.hash.substring(1) == name)
        AddOnLoadScript(script);
}

AddOnLoadScript("removeMNPBottomElements();");

function removeMNPBottomElements()
{
	try
	{
		var ftr = document.getElementById("msviFooter");    
	  
		if (ftr != null)
		{
			// remove the br tag befor the MNP footer
			var br = ftr.previousSibling;
	        
			if(br != null && br.nodeName == "BR")
			{
				br.parentNode.removeChild(br);
			}        
	        
			// remove everything below the MNP footer
			while(ftr.nextSibling != null)
			{
				ftr.nextSibling.parentNode.removeChild(ftr.nextSibling);
			}
	        
			// remove the MNP footer
			ftr.parentNode.removeChild(ftr);
		}
    } catch(e){}
}


function removeMNPStyleSheets()
{
    try
    { 
        //remove MNP stylesheets (last 3)
        for(i=document.styleSheets.length-3;i<document.styleSheets.length;i++)
        {
            document.styleSheets[i].cssText = "";
        }
    	
    } catch(e){}
}

function promoHover(sender,hover)
{
	if(hover)
		sender.style.backgroundImage = "url(" + sender.attributes["bgImgHover"].value + ")";
	else
		sender.style.backgroundImage = "url(" + sender.attributes["bgImg"].value + ")";
}

function loadVideo(videosource) {

    $get("SLVidPlush").content.CurrentPage.LoadVideo(videosource);
}

//// BEGIN: functions for Image Rotator
//function ImgRot_SwapImage(src, thumbsrc) {
//    var CurrentImage = document.getElementById("ImgRotCurrentImage");
//    if (CurrentImage != null && src != null) {
//        CurrentImage.setAttribute("src", src);
//    }
//}
//function ImgRot_CursorHand(obj) {
//    obj.style.cursor = 'hand';
//    obj.style.cursor = 'pointer';
//}
//function ImgRot_CursorAuto(obj) {
//    obj.style.cursor = 'auto';
//}
//function ImgRot_ManageSelected(Selected) {
//    // SET: which caption to show and which to hide
//    var ImgRotSelected1 = document.getElementById("ImgRotSelected1");
//    var ImgRotSelected2 = document.getElementById("ImgRotSelected2");
//    var ImgRotSelected3 = document.getElementById("ImgRotSelected3");

//    var ImgSelected = "ImgRotThumbnailContainer ImgRotSelected";
//    var ImgNotSelected = "ImgRotThumbnailContainer ImgRotNotSelected";
//    
//    if (Selected == "ImgRotSelected1") {
//        if (ImgRotSelected1) {
//            ImgRotSelected1.className = ImgSelected;
//        }
//        if (ImgRotSelected2) {
//            ImgRotSelected2.className = ImgNotSelected;
//        }
//        if (ImgRotSelected3) {
//            ImgRotSelected3.className = ImgNotSelected;
//        }
//    }
//    else if (Selected == "ImgRotSelected2") {
//        if (ImgRotSelected1) {
//            ImgRotSelected1.className = ImgNotSelected;
//        }
//        if (ImgRotSelected2) {
//            ImgRotSelected2.className = ImgSelected;
//        }
//        if (ImgRotSelected3) {
//            ImgRotSelected3.className = ImgNotSelected;
//        }
//    }
//    else if (Selected == "ImgRotSelected3") {
//        if (ImgRotSelected1) {
//            ImgRotSelected1.className = ImgNotSelected;
//        }
//        if (ImgRotSelected2) {
//            ImgRotSelected2.className = ImgNotSelected;
//        }
//        if (ImgRotSelected3) {
//            ImgRotSelected3.className = ImgSelected;
//        }
//    }
//}
//function ImgRot_ManageCaption(SelectedImageId) {
//    // SET: which caption to show and which to hide
//    var ImgRotCurrentImageCaption1 = document.getElementById("ImgRotCurrentImageCaption1");
//    var ImgRotCurrentImageCaption2 = document.getElementById("ImgRotCurrentImageCaption2");
//    var ImgRotCurrentImageCaption3 = document.getElementById("ImgRotCurrentImageCaption3");

//    var ImgRotCurrentImageCaptionShow = "ImgRotCurrentImageCaptionShow ImgRotCurrentCaption";
//    var ImgRotCurrentImageCaptionHide = "ImgRotCurrentImageCaptionHide ImgRotCurrentCaption";

//    if (SelectedImageId == "ImgRotCurrentImageCaption1") {
//        if (ImgRotCurrentImageCaption1) {
//            ImgRotCurrentImageCaption1.className = ImgRotCurrentImageCaptionShow;
//        }
//        if (ImgRotCurrentImageCaption2) {
//            ImgRotCurrentImageCaption2.className = ImgRotCurrentImageCaptionHide;
//        }
//        if (ImgRotCurrentImageCaption3) {
//            ImgRotCurrentImageCaption3.className = ImgRotCurrentImageCaptionHide;
//        }
//    }
//    else if (SelectedImageId == "ImgRotCurrentImageCaption2") {
//        if (ImgRotCurrentImageCaption1) {
//            ImgRotCurrentImageCaption1.className = ImgRotCurrentImageCaptionHide;
//        }
//        if (ImgRotCurrentImageCaption2) {
//            ImgRotCurrentImageCaption2.className = ImgRotCurrentImageCaptionShow;
//        }
//        if (ImgRotCurrentImageCaption3) {
//            ImgRotCurrentImageCaption3.className = ImgRotCurrentImageCaptionHide;
//        }
//    }
//    else if (SelectedImageId == "ImgRotCurrentImageCaption3") {
//        if (ImgRotCurrentImageCaption1) {
//            ImgRotCurrentImageCaption1.className = ImgRotCurrentImageCaptionHide;
//        }
//        if (ImgRotCurrentImageCaption2) {
//            ImgRotCurrentImageCaption2.className = ImgRotCurrentImageCaptionHide;
//        }
//        if (ImgRotCurrentImageCaption3) {
//            ImgRotCurrentImageCaption3.className = ImgRotCurrentImageCaptionShow;
//        }
//    }
//    // SET: Alt Text of current image
//    if (document.getElementById("ImgRotCurrentImage") != null && document.getElementById(SelectedImageId) != null) {
//        document.getElementById("ImgRotCurrentImage").setAttribute('alt', document.getElementById(SelectedImageId).innerHTML);
//    }
//}
//// END: functions for Image Rotator

// BEGIN: SL video player

//function loadVideo(videosource, previewImage) {
//    var sl = document.getElementById("SLVID");
//    if (sl) {
//        if (sl.content)
//            sl.content.CurrentPage.LoadVideo(videosource, previewImage);
//    }
//}

//function loadVideo(videosource, previewImage) {
//    var sl = document.getElementById("SLVID");
//    try{
//        if (sl.content)
//            sl.content.CurrentPage.LoadVideo(videosource, previewImage);
//    }
//    catch(e){}
//}


//function stopVideo() {
//    var sl = document.getElementById("SLVID");
//    if (sl.content)
//        sl.content.CurrentPage.StopVideo();
//}

//function showCaseStudy(videosource, previewImage, idToShow)
//{
//    var divs = document.getElementById("caseStudiesTextArea").childNodes;    
//    
//    // hide all of them
//    for(var i=0;i<divs.length;i++)
//    {
//        divs[i].style.display = "none";
//    }
//    
//    //load video
//    loadVideo(videosource, previewImage);
//    
//    // show selected
//    document.getElementById(idToShow).style.display = "block";
//    
//}

//// END: SL video player

//// BEGIN: Thumbnail Support Functions
//function Thumb_ManageSelected(thumbkey, thumbid, count) {
//    var ImgSelected = "ImgRotThumbnailContainer ImgRotSelected";
//    var ImgNotSelected = "ImgRotThumbnailContainer ImgRotNotSelected";
//    var ThumbTest;
//    //LOOP: through all thumbs in thumbcontainer
//    for (var i = 1; i <= count; i++) {
//        ThumbTest = document.getElementById(thumbkey + i);
//        //SET: Selected Item
//        if(ThumbTest){
//            if (document.getElementById(thumbkey + i).id == thumbid.id) {
//                document.getElementById(thumbkey + i).className = ImgSelected;
//            }
//            else {
//                document.getElementById(thumbkey + i).className = ImgNotSelected;
//            }
//        }
//    }
//}
//// END: Thumbnail Support Functions

// ShowWidgetDataSmart() 
// 1. loops through all data divs
// 2. hides all of them
// 3. shows div and highlights link based on passed id
// author: jibby b.
// date: 1.27.09
function ShowWidgetDataSmart(idToShow)
{

    stopVideo();
    // main widget div
    var divWidget = document.getElementById("divWidget");
    
    // divs inside main widget div
    var dataDivs = divWidget.getElementsByTagName("div");
    
    // get link and data objects to show
    var toShowLink = document.getElementById("widgetLink" + idToShow);
    var toShowData = document.getElementById("widgetData" + idToShow);
    
    // loop thru all data divs
    for (var i=1; i < dataDivs.length; i++)
    {
        // current div
        var dataDiv = dataDivs.item(i);
        
        if(dataDiv != null)
        {   
            // id of current div
            var id = new String(dataDiv.id);
            
            // hide all divs and reset all links
            if(id.indexOf("widgetData") != -1)
                dataDiv.style.display = "none";
            else if(id.indexOf("widgetLink") != -1)
                dataDiv.className = "pbtn";
        }
    }
    
    // show the correct div 
    if(toShowData != null)
        toShowData.style.display = "block";

    // show the correct link
    if(toShowLink != null)
        toShowLink.className = "pbtn psel";

    // need to show a different style on the previous link
    var prevId = idToShow - 1;
    if(prevId > 0)
    {
        var prevLink = document.getElementById("widgetLink" + prevId);
        if(prevLink != null)
            prevLink.className = "pbtn nobtmbdr";
    }

    
}

//    
//function ShowWidgetData(idToShow)
//{
//    // get the divs
//    var divProd1 = document.getElementById("prod1");
//    var divProd2 = document.getElementById("prod2");
//    var divProd3 = document.getElementById("prod3");
//    var divProd4 = document.getElementById("prod4");
//    var divProd5 = document.getElementById("prod5");
//    var divProd6 = document.getElementById("prod6");
//    
//    // get the links
//    var lnkProd1 = document.getElementById("prodLink1");
//    var lnkProd2 = document.getElementById("prodLink2");
//    var lnkProd3 = document.getElementById("prodLink3");
//    var lnkProd4 = document.getElementById("prodLink4");
//    var lnkProd5 = document.getElementById("prodLink5");
//    var lnkProd6 = document.getElementById("prodLink6");
//    
//    if(idToShow == 1)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "block";
//        if(divProd2 != null)
//            divProd2.style.display = "none";
//        if(divProd3 != null)
//            divProd3.style.display = "none";
//        if(divProd4 != null)
//            divProd4.style.display = "none";
//        if(divProd5 != null)
//            divProd5.style.display = "none";
//        if(divProd6 != null)
//            divProd6.style.display = "none";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn psel";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn";
//    }
//    else if(idToShow == 2)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "none";
//        if(divProd2 != null)
//            divProd2.style.display = "block";
//        if(divProd3 != null)
//            divProd3.style.display = "none";
//        if(divProd4 != null)
//            divProd4.style.display = "none";
//        if(divProd5 != null)
//            divProd5.style.display = "none";
//        if(divProd6 != null)
//            divProd6.style.display = "none";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn nobtmbdr";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn psel";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn";
//    }
//    else if(idToShow == 3)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "none";
//        if(divProd2 != null)
//            divProd2.style.display = "none";
//        if(divProd3 != null)
//            divProd3.style.display = "block";
//        if(divProd4 != null)
//            divProd4.style.display = "none";
//        if(divProd5 != null)
//            divProd5.style.display = "none";
//        if(divProd6 != null)
//            divProd6.style.display = "none";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn nobtmbdr";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn psel";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn";
//    }
//    else if(idToShow == 4)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "none";
//        if(divProd2 != null)
//            divProd2.style.display = "none";
//        if(divProd3 != null)
//            divProd3.style.display = "none";
//        if(divProd4 != null)
//            divProd4.style.display = "block";
//        if(divProd5 != null)
//            divProd5.style.display = "none";
//        if(divProd6 != null)
//            divProd6.style.display = "none";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn nobtmbdr";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn psel";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn";
//    }
//    else if(idToShow == 5)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "none";
//        if(divProd2 != null)
//            divProd2.style.display = "none";
//        if(divProd3 != null)
//            divProd3.style.display = "none";
//        if(divProd4 != null)
//            divProd4.style.display = "none";
//        if(divProd5 != null)
//            divProd5.style.display = "block";
//        if(divProd6 != null)
//            divProd6.style.display = "none";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn nobtmbdr";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn psel";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn";
//    }
//    else if(idToShow == 6)
//    {
//        // show / hide divs
//        if(divProd1 != null)
//            divProd1.style.display = "none";
//        if(divProd2 != null)
//            divProd2.style.display = "none";
//        if(divProd3 != null)
//            divProd3.style.display = "none";
//        if(divProd4 != null)
//            divProd4.style.display = "none";
//        if(divProd5 != null)
//            divProd5.style.display = "none";
//        if(divProd6 != null)
//            divProd6.style.display = "block";
//        
//        // set class on link
//        if(lnkProd1 != null)
//            lnkProd1.className = "pbtn";
//        if(lnkProd2 != null)
//            lnkProd2.className = "pbtn";
//        if(lnkProd3 != null)
//            lnkProd3.className = "pbtn";
//        if(lnkProd4 != null)
//            lnkProd4.className = "pbtn";
//        if(lnkProd5 != null)
//            lnkProd5.className = "pbtn nobtmbdr";
//        if(lnkProd6 != null)
//            lnkProd6.className = "pbtn psel";
//    }
//}


//// Begin: video controls ///

function stopVideo() {
    //alert('test');
    try {

        var sl = document.getElementById("SLVID");
        if (sl.content)
        //alert('have content');

            sl.content.MediaPlayer.Stop();
    }
    catch (e) {
    }    
}

//// End: video controls ///


// MakeHot(tabToShow, lImgToShow, rImgToShow)
// 1. tabToShow - the tab to show
// 2. lImgToShow - the left curved image to show
// 3. rImgToShow - the right curved image to show
// author: jibby b.
// date: 2.12.09
function MakeHot(tabToShow, lImgToShow, rImgToShow, tabContentToShow)
{
    // TO DO: deselect currently selected tab
    var selTab = document.getElementById("selTab");
    selTab.style.backgroundColor = "#DADBDE";
    selTab.id = "";
    
    // get mid div (contains all tabs)
    var divMid = document.getElementById("divMid");
    
    // get all divs in mid
    var divs = divMid.getElementsByTagName("div");
    
    // loop thru divs
    for(var i = 0; i < divs.length; i++)
    {
        var div = divs.item(i);
        
        if(div != null)
        {   
            // id of current div
            var id = new String(div.id);
            
            // turn vis off for this div...maybe
            if(id.indexOf("divSelLeft") != -1 || id.indexOf("divSelRight") != -1)
                div.style.visibility = "hidden";
        }
    }
    
    // get allcontent div (contains all tabs data)
    var divAllContent = document.getElementById("divAllContent");
    divs = divAllContent.getElementsByTagName("div");
    
    // hide all content dives
    for(var i = 0; i < divs.length; i++)
    {
        var div = divs.item(i);
        
        if(div != null)
        {   
            // id of current div
            var id = new String(div.id);
            
            // turn vis off for this div...maybe
            if(id.indexOf("divContentTab") != -1)
            {
                div.style.display = "none";
            }
        }
    }
    
    // show the selected content
    tabContentToShow.style.display = "block";
    
    // select new tab
    tabToShow.id = "selTab";
    tabToShow.style.backgroundColor = "#ffffff";
    
    // show left and right curved images
    lImgToShow.style.visibility = "visible";
    rImgToShow.style.visibility = "visible";
}

function clearText(element, text) {
    if (element.value == text) {
        element.value = '';
    }
}

function setText(element, text) {
    if(element.value == "") {
        element.value = text;
    }
}


