﻿// JScript File

// Show/Hide Container Functions
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function GetFormField(fieldname)
{
   var field = document.getElementById(fieldname);
   if(!field) 
     eval("theForm." + fieldname);
   if(!field)
        field=document.getElementsByName(fieldname);
   return field;
}

 function GoToSearchResults(relativePath,phrase,mode)
 {
    mode=GetFormField(mode);
    phrase=GetFormField(phrase);
    
    var modeName = (mode) ? mode.options[mode.options.selectedIndex].value : "None";
        modeName= (modeName=="None")? "" : "/" + modeName;
        
    var phraseText= (phrase)? escape(phrase.value): "";
    if(phraseText=="")
    {
        //alert("Please enter one or two keywords");
        alert("We’re sorry – you haven’t typed anything in the search field. Please try again.");
        return false;
    }
    phraseText=(phraseText=="") ? phraseText : "/" + phraseText +"/";
    window.location.href=relativePath + "search" +modeName +phraseText;
    return false;
 }
 
 function GoToVideoSearchResults(relativePath,phrase,mode)
 {
    phrase=GetFormField(phrase);
    
    var phraseText= (phrase)? escape(phrase.value): "";
    if(phraseText=="")
    {
        //alert("Please enter one or two keywords");
        alert("We’re sorry – you haven’t typed anything in the search field. Please try again.");
        return false;
    }
    phraseText=(phraseText=="") ? phraseText : "/" + phraseText +"/";
    window.location.href=relativePath + "search/" +mode +phraseText;
    return false;
 }
 
 function ValidateSearchCriteria(phrase)
 {
    phrase=GetFormField(phrase);
    var phraseText = (phrase)? escape(phrase.value): "";
    if(phraseText=="")
    {
        //alert("Please enter one or two keywords");
        alert("We’re sorry – you haven’t typed anything in the search field. Please try again.");
        return false;
    }
    return true;
 }
 
function UpdateBestPrice(ControlID,UrlProcessor,EditorialItemID,PriceRunnerProductId,product)
{
    var sURL=UrlProcessor +"?EditorialItemID=" + EditorialItemID +"&PRProductId="+PriceRunnerProductId + "&product="+ product;
    var ControlObj=$(ControlID);
        ControlObj=(ControlObj==null)?ControlID:ControlObj;
    SetInnerHTMLFromAjaxResponse(sURL,ControlObj);
    return false;
}

function UpdateVisiblity(ControlID, Visibility)
{
    var controlObj = $(ControlID);
    
    if (controlObj != null)
    {
        if (Visibility == "true" || Visibility == true)
        {
            controlObj.style.display = "block";
            controlObj.style.height = "auto";
        }
        else
        {
            controlObj.style.display = "none";
            controlObj.style.height = "0px";
        }
    }
}

//video

var VideoFullScreenPage= 'fullscreen.html';
var VideoPlayerFeed;
var s_height = screen.availHeight;
var s_width = screen.availWidth;

function openFS(height, width)
{
	var win = window.open(VideoFullScreenPage + "?" + VideoPlayerFeed, "WhatHiFi_tv", "top=0,left=0,toolbar=no,width=" + s_width + ",status=no,resizable=yes,scrollbars=no");
}

function InitMediaPlayer(flashPath, playerPath, mode, editorialID, innerSection, width, height)
{
    VideoFullScreenPage = flashPath + 'fullscreen.html';
    VideoPlayerFeed = flashPath + 'mediaplayer.ashx?EditorialItemID=' + editorialID + '%26InnerSection='+ innerSection + '%26Mode=' + mode;
    
    s_height = s_width * (parseInt(height) / parseInt(width));
    
    var so = new SWFObject(playerPath, 'mediaplayer', width, height, '8', '#ffffff'); 
    
    so.addVariable('xmlURL', VideoPlayerFeed);
    so.addParam('wmode', 'opaque');
//  so.addParam('scale', 'noscale');
    so.write('flashcontent');
}

function  MoveAddElement1Before2(sourceID,targetID)
{
    MoveElementBefore(sourceID,targetID);
}

function MoveElementBefore(sourceID,targetID)
{
   // get ad container
    var source = document.getElementById(sourceID);
    // remove ad container from current position
    source.parentNode.removeChild(source);
    // get position container
    var targetdiv = document.getElementById(targetID);
    // insert ad container into position container
    //targetdiv.insertBefore(source);
    targetdiv.appendChild(source);
    targetdiv.style.display='block';
    source.style.display='block';
}