//-----------------------------------------
function CSDetail_ChangeVersion_V2(obj)
{
	var url="./CreativeSpec.aspx?CS_CreativeSpecID="+obj.options[obj.selectedIndex].getAttribute("CS_CreativeSpecID")+"&CID="+obj.options[obj.selectedIndex].getAttribute("CountryID")+"&LID="+obj.options[obj.selectedIndex].getAttribute("LanguageID");
	GoToPage(url);
}

 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------------------------------
// BEGIN - HY_SEARCH_PRODUCT_CS Search Section Control
//-----------------------------------------------------------------------------------------------------
function HY_SEARCH_Mode_OnClick(sMode)
{
	var PRODUCT_CS_SEARCH = document.getElementById("PRODUCT_CS_SEARCH");

	if(sMode == PRODUCT_CS_SEARCH.getAttribute("Mode")) return; // didn't change
	
	PRODUCT_CS_SEARCH.setAttribute("Mode", sMode);

	var SEARCH_PRODUCT_BasicDiv = document.getElementById("SEARCH_PRODUCT_BasicDiv");
	var SEARCH_CS_BasicDiv = document.getElementById("SEARCH_CS_BasicDiv");

	if(sMode == "CS")
	{
		if(SEARCH_CS_BasicDiv.getAttribute("Loaded") != "1")
		{
			SEARCH_CS_BasicDiv.innerHTML = CrossBrowser_GetHTML(SEARCH_CS_BasicDiv.getAttribute("urlBasicHTML"), null);
			SEARCH_CS_BasicDiv.setAttribute("Loaded", "1");
			HY_SEARCH_CS_AdType_onchange();
		}
	}
	else
	{
		if(SEARCH_PRODUCT_BasicDiv.getAttribute("Loaded") != "1")
		{
			SEARCH_PRODUCT_BasicDiv.innerHTML = CrossBrowser_GetHTML(SEARCH_PRODUCT_BasicDiv.getAttribute("urlBasicHTML"), null);
			SEARCH_PRODUCT_BasicDiv.setAttribute("Loaded", "1");
			HY_SEARCH_PRODUCT_Property_onchange();
		}
	}

	document.getElementById("SEARCH_PRODUCT_BasicDiv").style.display = (sMode == "PRODUCT" ? "" : "none");
	document.getElementById("SEARCH_PRODUCT_BasicDiv").disabled = !(sMode == "PRODUCT");

	document.getElementById("SEARCH_CS_BasicDiv").style.display = (sMode == "PRODUCT" ? "none" : "");
	document.getElementById("SEARCH_CS_BasicDiv").disabled = !(sMode == "CS");
}

///////////////////////// HY_SEARCH_CS
//////////// CS OnChange Events
function HY_SEARCH_CS_AdType_onchange()
{
	var SEARCH_CS_AdType = document.getElementById("SEARCH_CS_AdType");
	var SEARCH_CS_Dimensions = document.getElementById("SEARCH_CS_Dimensions");

    var sDimensions = SEARCH_CS_AdType.options[SEARCH_CS_AdType.selectedIndex].getAttribute("Dimensions");
    if (sDimensions == "NO_DIMENSIONS")
    {
        SEARCH_CS_Dimensions.options.length = 0;
        
	    var oOpt = document.createElement("OPTION");
	    oOpt.value = "";
	    oOpt.text = SEARCH_CS_Dimensions.getAttribute("NAOptionText");
	    
        try{SEARCH_CS_Dimensions.options.add(oOpt);}
        catch(e){SEARCH_CS_Dimensions.add(oOpt);}
    }
    else
    {
	    var aryDimensions = sDimensions.split(",");
	    var sDimensions_Selected = SEARCH_CS_Dimensions.value;
        
	    SEARCH_CS_Dimensions.options.length = 0;

	    var oOpt = document.createElement("OPTION");
	    oOpt.value = "";
	    oOpt.text = SEARCH_CS_Dimensions.getAttribute("AllOptionText");

        try{SEARCH_CS_Dimensions.options.add(oOpt);}
        catch(e){SEARCH_CS_Dimensions.add(oOpt);}

	    for(var i=0; i<aryDimensions.length; i++)
	    {
		    oOpt = document.createElement("OPTION");
		    var aryValueText = aryDimensions[i].split("_");
		    oOpt.value = aryValueText[0];
		    oOpt.text = aryValueText[1];

            try{SEARCH_CS_Dimensions.options.add(oOpt);}
            catch(e){SEARCH_CS_Dimensions.add(oOpt);}

		    if(sDimensions_Selected == aryValueText[0]) oOpt.selected = true;
	    }
    }
}

///////////////////////// SEARCH_PRODUCT
function HY_SEARCH_PRODUCT_Property_onchange()
{
	var SEARCH_PRODUCT_Property = document.getElementById("SEARCH_PRODUCT_Property");
	var optProperty = SEARCH_PRODUCT_Property.options[SEARCH_PRODUCT_Property.selectedIndex];

	SEARCH_SelectBox_Generate(document.getElementById("SEARCH_PRODUCT_AdType"), optProperty.getAttribute("ATIDs").split(","));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////// COMMON Util
function SEARCH_SelectBox_Generate(oSlt, aryIDs)
{
	var sSelectedValue = oSlt.value;
	var sAllOptionText = oSlt.getAttribute("AllOptionText");
	var oOpt;
	
	oSlt.options.length = 0;

	if(sAllOptionText != null && sAllOptionText != "")
	{
		oOpt = document.createElement("OPTION");
		oOpt.value = "0";
		oOpt.text = sAllOptionText;
		try{oSlt.options.add(oOpt);}
		catch(e){oSlt.add(oOpt);}
	}

	if(aryIDs != null)
	{
		for(var i=0; i<aryIDs.length; i++)
		{
			if(aryIDs[i] != "")
			{
				oOpt = document.createElement("OPTION");
				oOpt.value = aryIDs[i];
				oOpt.text = oSlt.getAttribute("Name_ID" + aryIDs[i]);
		        try{oSlt.options.add(oOpt);}
		        catch(e){oSlt.add(oOpt);}
				if(sSelectedValue == aryIDs[i]) oOpt.selected = true;
			}
		}
	}
}
//-----------------------------------------------------------------------------------------------------
// END - SEARCH_PRODUCT_CS Search Section Control
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------
function Demo_CategoryID_onchange(obj)
{
	var Demo_CategoryID=document.getElementById("Demo_CategoryID");
	var Demo_ItemID=document.getElementById("Demo_ItemID");
	SEARCH_SelectBox_Generate(Demo_ItemID, Demo_CategoryID.options[Demo_CategoryID.selectedIndex].getAttribute("ItemIDs").split(","));
}

//-----------------------------------------
function Demo_MarketID_onclick(obj)
{
	var objs=document.getElementsByName(obj.getAttribute("name"));
	var objAll=document.getElementById("Demo_MarketID0");
	if(obj.getAttribute("id")==objAll.getAttribute("id"))
	{
		if(obj.checked)
		{
			for(var i=0;i<objs.length;i++)
			{
				if(objs[i].getAttribute("id")!=objAll.getAttribute("id"))
					objs[i].checked=false;
			}
		}
		else
			obj.checked=true;
	}
	else
	{
		var AllChecked=true;
		var AllUnChecked=true;
		for(var i=0;i<objs.length;i++)
		{
			if(objs[i].getAttribute("id")!=objAll.getAttribute("id"))
			{
				if(objs[i].checked)
					AllUnChecked=false;
				else
					AllChecked=false;
			}	
		}
		if(AllUnChecked||AllChecked)
			objAll.checked=true;
		else
			objAll.checked=false;
	}

	if(objAll.checked)	
	{
		for(var i=0;i<objs.length;i++)
		{
			if(objs[i].getAttribute("id")!=objAll.getAttribute("id"))
			{
				objs[i].checked=false;
			}
		}
	}
}

//-----------------------------------------
function ShowCreative(iCreativeID) {

    openPopupWindow(MarketBaseURL+'/pages/CreativeShowcaseCreative.aspx?CreativeID=' + iCreativeID+"&PageID="+CurrentPageID,780,780);
}

//-----------------------------------------
function AdvertisingSite_Change()
{
    var select=document.getElementById("advertisingsite");
    var option =select.options[select.selectedIndex];
    var url=option.value;
    var newbrowser=option.getAttribute("NewBrowser");
    
    if(newbrowser=='1')
        window.open(url);
    else    
        window.location=url;;
}
//-----------------------------------------
function MarketSelector_On() {
    WindowControls_Hide();
    var MarketSelector = document.getElementById("MarketSelector_On");
    MarketSelector.style.display = 'inline';
    var MarketSelector_List = document.getElementById("MarketSelector_List");
    MarketSelector_List.focus();
}
//-----------------------------------------
function MarketSelector_Off() {
    WindowControls_Show();
    var MarketSelector = document.getElementById("MarketSelector_On");
    MarketSelector.style.display = 'none';
}
//-----------------------------------------
function MarketSelector_Change(obj) {
    var option = obj.options[obj.selectedIndex];
    var newBrowser = option.getAttribute("NewBrowser");
    var URL = option.value;

    MarketSelector_Off();

    if (newBrowser == '1') {
        window.open(URL, 'Market');
    }
    else {
        window.location = URL;
    }
}
//-----------------------------------------
function MarketSelector_OnMouseOut(evt) {
    if (!ReallyMousingOut(evt, "MarketSelector_On")) return false;

    MarketSelector_Off();
}
//-----------------------------------------
function MarketSelector2_Change() {
    var obj = document.getElementById("MarketSelector2");
    var option = obj.options[obj.selectedIndex];
    var newBrowser = option.getAttribute("NewBrowser");
    var URL = option.value;

    if (newBrowser == '1') {
        window.open(URL, 'Market');
    }
    else {
        window.location = URL;
    }
}
//-----------------------------------------
function LiveSearch_TextBoxFocus(obj) {
    var defaulttext = obj.getAttribute("defaulttext");
    if (obj.value == defaulttext) {
        obj.value = "";
    }
    obj.className = "WebSearchTextBox";
}
//-----------------------------------------
function LiveSearch_TextBoxBlur(obj) {
    var defaulttext = obj.getAttribute("defaulttext");
    if (trim(obj.value) == "") {
        obj.className = "WebSearchTextBox_Default";
        obj.value = defaulttext;
    }
    else {
        obj.className = "WebSearchTextBox";
    }
}
//-----------------------------------------
function LiveSearch_Submit(uniqueid, isWebSearch, OmnitureLinkName) {
    if (LiveSearch_Validate(uniqueid)) {
        var form = document.forms["livesearch_form" + uniqueid];
        DoOmnitureWebSearchKeywordCustomLink(form, OmnitureLinkName);
        return true;
    }
    else
        return false;  
}
//-----------------------------------------
function LiveSearch_Validate(uniqueid) {
    var form = document.forms["livesearch_form" + uniqueid];
    var textboxes = form.getElementsByTagName("input");
    var textbox = null;
    
    for (var i = 0; i < textboxes.length; i++) {
        if (textboxes[i].id == "q") {
            textbox = textboxes[i];
            break;
        }
    }
    if (textbox == null)
        return false;
    else {
        var defaulttext = textbox.getAttribute("defaulttext");
        if (textbox.value.toLowerCase() == defaulttext.toLowerCase() || trim(textbox.value) == "") {
            return false;
        }
        else
            return true;
    }
}
//-----------------------------------------
function LiveSearch_Site(uniqueid, OmnitureLinkName) {
    if (LiveSearch_Submit(uniqueid, false, OmnitureLinkName)) {
        var form = document.forms["livesearch_form" + uniqueid];
        form.submit();
    }
}

//-----------------------------------------
function SpecialtySearch_ButtonClick(UniqueID, OmnitureLinkName) {
    if (SpecialtySearch_Submit(UniqueID, OmnitureLinkName)) {
        var form = document.forms["specialtysearch_form_" + UniqueID];
        form.submit();
    }
}
//-----------------------------------------
function SpecialtySearch_Submit(UniqueID, OmnitureLinkName) {
    if (SpecialtySearch_Validate(UniqueID)) {
        var form = document.forms["specialtysearch_form_" + UniqueID];
        DoOmnitureWebSearchKeywordCustomLink(form, OmnitureLinkName);
        return true;
    }
    else {
        return false;
    }
}
//-----------------------------------------
function SpecialtySearch_Validate(UniqueID) {
    var form = document.forms["specialtysearch_form_" + UniqueID];
    var textboxes = form.getElementsByTagName("input");
    var textbox = null;

    for (var i = 0; i < textboxes.length; i++) {
        if (textboxes[i].id == "q") {
            textbox = textboxes[i];
            break;
        }
    }
    if (textbox == null) {
        return false;
    }
    else {
        if (trim(textbox.value) == "") {
            return false;
        }
        else
            return true;
    }
}

//-----------------------------------------
var SurveyInvitation = null;
var SurveyInvitationID = 0;
var SurveyInvitationLogID = 0;
function SurveyInvitation_Get() {
    if (Number(SurveyInvitationID) > 0) {
        var html = CrossBrowser_GetHTML("../Pages/SurveyInvitationHTML.aspx?SurveyInvitationID=" + SurveyInvitationID + "&SurveyInvitationLogID=" + SurveyInvitationLogID, null);

        if ((html != null && html != '')) {
            var div = document.createElement("div");
            div.innerHTML = html;
            document.body.appendChild(div);

            SurveyInvitation = document.getElementById("SurveyInvitation");
            if (SurveyInvitation != null) {
                var top = -(SurveyInvitation.clientHeight + 6);
                var left = 0;
                var screenWidth = 0;
                if (typeof (window.innerWidth) == 'number') {
                    //Non-IE
                    screenWidth = window.innerWidth;
                } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                    //IE 6+ in 'standards compliant mode'
                    screenWidth = document.documentElement.clientWidth;
                } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                    //IE 4 compatible
                    screenWidth = document.body.clientWidth;
                }
                left = (screenWidth / 2) - 180;

                WindowControls_Hide();

                SurveyInvitation.setAttribute("top", top);
                SurveyInvitation.style.top = top + "px";
                SurveyInvitation.style.left = left + "px";
                SurveyInvitation.style.visibility = "";

                var IntervalID = window.setInterval(SurveyInvitation_Move, 1);
                SurveyInvitation.setAttribute("IntervalID", IntervalID);
            }
        }
    }
}

//-----------------------------------------
function SurveyInvitation_Move() {
    var top = Number(SurveyInvitation.getAttribute("top")) + 3;
    SurveyInvitation.setAttribute("top", top);
    SurveyInvitation.style.top = top + "px";

    if (top >= 183) {
        window.clearInterval(SurveyInvitation.getAttribute("IntervalID"));
    }
}

//-----------------------------------------
function SurveyInvitation_Close() {
    SurveyInvitation.style.visibility = "hidden";
    WindowControls_Show();
}

//-----------------------------------------
function SurveyInvitation_Open(newWindow, inviteID, logID) {
    var url = MarketBaseURL + "/pages/SurveyInvitationRedirect.aspx?inviteID=" + inviteID + "&logID=" + logID;

    if (newWindow == '1')
        window.open(url, 'SurveyInvitation');
    else
        window.location = url;

    SurveyInvitation_Close();
}


//-----------------------------------------
function FlyoutMenu_On(containerid,tabid,menuid,resizeFlyout) {
    var class_off;
    var class_on;
    if(resizeFlyout==null)
        resizeFlyout=false;
        
    var tab = document.getElementById(tabid);
    if (tab != null) {
        class_off = tab.getAttribute("class_off");
        if (class_off == null || class_off=="")
            tab.setAttribute("class_off", tab.className);
            
        class_on = tab.getAttribute("class_on");
        tab.className = class_on;
    }

    var menu = document.getElementById(menuid);
    if (menu != null) {
        class_off = menu.getAttribute("class_off");
        if (class_off == null || class_off=="")
            menu.setAttribute("class_off", menu.className);
            
        class_on = menu.getAttribute("class_on");
        menu.className = class_on;
        
        var menu2 = document.getElementById(menuid+"_2");
        //this iframe allows menu to fly over flash and sliverlight controls.
        var iframe=document.getElementById(menuid+"_iframe");
        if(menu2!=null&&iframe!=null)
        {
            if(resizeFlyout&&menu2.clientWidth<tab.offsetWidth)
            {
                menu2.style.width=(tab.offsetWidth+20)+"px";
            }   

            if(resizeFlyout){
                menu2.style.left=menu.offsetWidth-menu2.clientWidth+"px";
                iframe.style.left=menu2.style.left;
            }
            var iframe_height=menu2.clientHeight-6;
            var iframe_width=menu2.clientWidth-12;
            iframe.style.height=iframe_height+"px";
            iframe.style.width=iframe_width+"px";
            iframe.style.display="block";
        }
    }
    //WindowControls_Hide();
}

//-----------------------------------------
function FlyoutMenu_Off(containerid,tabid,menuid) {
    var tab = document.getElementById(tabid);
    if (tab != null) {
        tab.className = tab.getAttribute("class_off");
        }

    var menu = document.getElementById(menuid);
    if (menu != null) {
        menu.className = menu.getAttribute("class_off");

        var iframe=document.getElementById(menuid+"_iframe");
        if(iframe!=null)
        {
            iframe.style.display="none";
        }
    }
    //WindowControls_Show();
}
//-----------------------------------------
function FlyoutMenu_OnMouseOut(evt, containerid,tabid,menuid) {
    if (!ReallyMousingOut(evt, containerid)) {
        return false;
    }
    else{
        FlyoutMenu_Off(containerid,tabid,menuid);
    }
}

function ReallyMousingOut(evt, sEleID) {
    try {
        var iSearchDepth = 100;
        if (evt == null) { evt = window.event }

        var oEle = null;
        if (evt.toElement == null)
            oEle = evt.relatedTarget; //FireFox
        else
            oEle = evt.toElement;

        for (var i = 0; i < iSearchDepth && oEle != null; i++) {
            if (oEle.id == sEleID)
                return false;
            else {
                    oEle = oEle.parentNode;
                }

        }
    } catch (e) {return false; }
    return true;
}

//-----------------------------------------
function SELECTABLE_STORY_SELECT_onchange(Adv_SectionGUID, NumStories) {

    // first hide all stories
    for (var i = 1; i <= NumStories; i++) {
        var SELECTABLE_STORY_DIVHIDE = document.getElementById("SELECTABLE_STORY_DIV_" + Adv_SectionGUID + "_" + i);
        SELECTABLE_STORY_DIVHIDE.style.display = "none";
    }

    // now show the selected one
    var SELECTABLE_STORY_SELECT = document.getElementById("SELECTABLE_STORY_SELECT_" + Adv_SectionGUID);
    var SELECTABLE_STORY_SELECT_OPTION=SELECTABLE_STORY_SELECT.options[SELECTABLE_STORY_SELECT.selectedIndex];
    var SELECTABLE_STORY_DIVSHOW = document.getElementById("SELECTABLE_STORY_DIV_" + Adv_SectionGUID + "_" + SELECTABLE_STORY_SELECT.value);
    SELECTABLE_STORY_DIVSHOW.style.display = "";

    // set the window hash in case of back button click
    // NOTES:
    //      - there can only be one selectable story section on the site right now - so we don't need to include section id.
    //      - if it becomes a publisher controlled section we'll need to include section id
    //      - also - this is currently the only use of location.hash on the site.  
    //      - if there are eventually other uses of it we'll have to create addtohash and getfromhash functions so that we aren't overwriting hash values that aren't our own.
    window.location.hash = SELECTABLE_STORY_SELECT.value;
    
    try{
    s.linkTrackVars='eVar8,events,products';
    s.linkTrackEvents='event3';
    s.events='event3';
    s.eVar8='budgetcalculator';
    s.products='Content Saved Type;budgetcalculator';
    s.tl(this,'o',SELECTABLE_STORY_SELECT_OPTION.getAttribute("title"));
    }catch(e){;}

}

//-----------------------------------------
function SELECTABLE_STORY_onload(Adv_SectionGUID, NumStories) {
    // look at the #hash on the location string - set by SELECTABLE_STORY_SELECT_onchange - and preselect that option if it exist.
    // useful for bookmarking or when a user clicks "back"
    var sHash = window.location.hash;
    if (sHash != "") {
        var iSelectStoryNum = parseInt(sHash.substring(1, sHash.length));
        if (!isNaN(iSelectStoryNum)) { // make sure it is a number
            if (iSelectStoryNum > 0 && iSelectStoryNum <= NumStories) { // make sure it fits with the number of stores we have
                // select the option & fire event
                var SELECTABLE_STORY_SELECT = document.getElementById("SELECTABLE_STORY_SELECT_" + Adv_SectionGUID);
                for (var i = 0; i < SELECTABLE_STORY_SELECT.options.length; i++) {
                    if (SELECTABLE_STORY_SELECT.options[i].value == iSelectStoryNum) {
                        SELECTABLE_STORY_SELECT.options[i].selected = true;
                        SELECTABLE_STORY_SELECT_onchange(Adv_SectionGUID, NumStories);
                        break;
                    }
                }
            }
        }
    }
}


