// JScript File

/*
	DOMhelp 1.0
	written by Chris Heilmann
	http://www.wait-till-i.com
	To be featured in "Beginning JavaScript for Practical Web Development, Including  AJAX" 
*/
DOMhelp={
	debugWindowId:'DOMhelpdebug',
	init:function(){
		if(!document.getElementById || !document.createTextNode){return;}
	},
	lastSibling:function(node){
		var tempObj=node.parentNode.lastChild;
		while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
			tempObj=tempObj.previousSibling;
		}
		return (tempObj.nodeType==1)?tempObj:false;
	},
	firstSibling:function(node){
		var tempObj=node.parentNode.firstChild;
		while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
			tempObj=tempObj.nextSibling;
		}
		return (tempObj.nodeType==1)?tempObj:false;
	},
	getText:function(node){
		if(!node.hasChildNodes()){return false;}
		var reg=/^\s+$/;
		var tempObj=node.firstChild;
		while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue)){
			tempObj=tempObj.nextSibling;
		}
		return tempObj.nodeType==3?tempObj.nodeValue:false;
	},
	setText:function(node,txt){
		if(!node.hasChildNodes()){return false;}
		var reg=/^\s+$/;
		var tempObj=node.firstChild;
		while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue)){
			tempObj=tempObj.nextSibling;
		}
		if(tempObj.nodeType==3){tempObj.nodeValue=txt}else{return false;}
	},
	createLink:function(to,txt){
		var tempObj=document.createElement('a');
		tempObj.appendChild(document.createTextNode(txt));
		tempObj.setAttribute('href',to);
		return tempObj;
	},
	createTextElm:function(elm,txt){
		var tempObj=document.createElement(elm);
		tempObj.appendChild(document.createTextNode(txt));
		return tempObj;
	},
	closestSibling:function(node,direction){
		var tempObj;
		if(direction==-1 && node.previousSibling!=null){
			tempObj=node.previousSibling;
			while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
				 tempObj=tempObj.previousSibling;
			}
		}else if(direction==1 && node.nextSibling!=null){
			tempObj=node.nextSibling;
			while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
				 tempObj=tempObj.nextSibling;
			}
		}
		return tempObj.nodeType==1?tempObj:false;
	},
	initDebug:function(){
		if(DOMhelp.debug){DOMhelp.stopDebug();}
		DOMhelp.debug=document.createElement('div');
		DOMhelp.debug.setAttribute('id',DOMhelp.debugWindowId);
		document.body.insertBefore(DOMhelp.debug,document.body.firstChild);
	},
	setDebug:function(bug){
		if(!DOMhelp.debug){DOMhelp.initDebug();}
		DOMhelp.debug.innerHTML+=bug+'\n';
	},
	stopDebug:function(){
		if(DOMhelp.debug){
			DOMhelp.debug.parentNode.removeChild(DOMhelp.debug);
			DOMhelp.debug=null;
		}
	},
	getKey:function(e){
		if(window.event){
	      var key = window.event.keyCode;
	    } else if(e){
	      var key=e.keyCode;
	    }
		return key;
	},
/* helper methods */
	getTarget:function(e){
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		if (!target){return false;}
		while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body'){
			target=target.parentNode;
		}
		return target;
	},
	stopBubble:function(e){
		if(window.event && window.event.cancelBubble){
			window.event.cancelBubble = true;
		} 
		if (e && e.stopPropagation){
			e.stopPropagation();
		}
	},
	stopDefault:function(e){
		if(window.event && window.event.returnValue){
			window.event.returnValue = false;
		} 
		if (e && e.preventDefault){
			e.preventDefault();
		}
	},
	cancelClick:function(e){
		if (window.event && window.event.cancelBubble 
		    && window.event.returnValue){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e && e.stopPropagation && e.preventDefault){
			e.stopPropagation();
			e.preventDefault();
		}
	},
	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener){
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},
	cssjs:function(a,o,c1,c2){
		switch (a){
			case 'swap':
				o.className=!DOMhelp.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!DOMhelp.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				var found=false;
				var temparray=o.className.split(' ');
				for(var i=0;i<temparray.length;i++){
					if(temparray[i]==c1){found=true;}
				}
				return found;
			break;
		}
	},
    safariClickFix:function(){
      return false;
    }
}
DOMhelp.addEvent(window, 'load', DOMhelp.init, false);



document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

// currently select leftNav item
var currentElem = null;

leftNavhl={
  // CSS classes
  overClass:'over', // rollover effect
  hideClass:'hide', // hide things
  currentClass:'current', // open item
  
  init:function(){
    var hl;
    if(!document.getElementsByClassName || !document.createTextNode){return;}
    var leftNavList=document.getElementsByClassName('channelList')[0];
    if(!leftNavList){return;}
    var leftNavItems=leftNavList.getElementsByTagName('li');
    for(var i=0;i<leftNavItems.length;i++){
      hl=leftNavItems[i].getElementsByTagName('a')[0];
      if(hl.href.indexOf("#")>0)
      {
          DOMhelp.addEvent(hl,'click',leftNavhl.toggleLeftNav,false);
          DOMhelp.addEvent(hl,'mouseover',leftNavhl.hover,false);
          DOMhelp.addEvent(hl,'mouseout',leftNavhl.hover,false);
	      hl.onclick = DOMhelp.safariClickFix;
          DOMhelp.cssjs('add',leftNavItems[i],leftNavhl.hideClass);
      }
    }
  },
  toggleLeftNav:function(e){
    var section=DOMhelp.getTarget(e).parentNode.parentNode;
    if (currentElem != null && currentElem != section)
    {
        DOMhelp.cssjs('swap',currentElem,leftNavhl.currentClass,leftNavhl.hideClass);
    }
    else
    {
        currentElem = null;
    }
	if(DOMhelp.cssjs('check',section,leftNavhl.currentClass)){
      DOMhelp.cssjs('swap',section,leftNavhl.currentClass,leftNavhl.hideClass);
    }else{
      DOMhelp.cssjs('swap',section,leftNavhl.hideClass,leftNavhl.currentClass);
      currentElem = section;
    }
   // DOMhelp.cancelClick(e);
    return true;
  },
  hover:function(e){
    var hl = DOMhelp.getTarget(e).parentNode.parentNode;
    var action = e.type == 'mouseout'?'remove':'add';
    DOMhelp.cssjs(action,hl,leftNavhl.overClass);
    return true;
  }
}



leftNavhls={
  // CSS classes
  overClass:'over', // rollover effect
  hideClass:'hide', // hide things
  currentClass:'current', // open item
  
  init:function(){
    var hls;
    if(!document.getElementsByClassName || !document.createTextNode){return;}
    var leftNavList=document.getElementsByClassName('channelList')[1];
    if(!leftNavList){return;}
    var leftNavItems=leftNavList.getElementsByTagName('li');
    for(var i=0;i<leftNavItems.length;i++){
      hls=leftNavItems[i].getElementsByTagName('a')[0];
      if(hls.href.indexOf("#")>0)
      {
          DOMhelp.addEvent(hls,'click',leftNavhls.toggleLeftNav,false);
          DOMhelp.addEvent(hls,'mouseover',leftNavhls.hover,false);
          DOMhelp.addEvent(hls,'mouseout',leftNavhls.hover,false);
	      hls.onclick = DOMhelp.safariClickFix;
          DOMhelp.cssjs('add',leftNavItems[i],leftNavhls.hideClass);
      }
    }
  },
  toggleLeftNav:function(e){
    var section=DOMhelp.getTarget(e).parentNode.parentNode;
    if (currentElem != null && currentElem != section)
    {
        DOMhelp.cssjs('swap',currentElem,leftNavhls.currentClass,leftNavhls.hideClass);
    }
    else
    {
        currentElem = null;
    }
	if(DOMhelp.cssjs('check',section,leftNavhls.currentClass)){
      DOMhelp.cssjs('swap',section,leftNavhls.currentClass,leftNavhls.hideClass);
    }else{
      DOMhelp.cssjs('swap',section,leftNavhls.hideClass,leftNavhls.currentClass);
      currentElem = section;
    }
   // DOMhelp.cancelClick(e);
    return true;
  },
  hover:function(e){
    var hls = DOMhelp.getTarget(e).parentNode.parentNode;
    var action = e.type == 'mouseout'?'remove':'add';
    DOMhelp.cssjs(action,hls,leftNavhls.overClass);
    return true;
  }
}


var carouselCurrent=0;
    var carouselEx=-1;
    var carouselTotal=4;
    var rotationThread=null;

    function clearRotationThread()
    {
          if(rotationThread)
          {
                clearInterval(rotationThread);
                rotationThread=null;
          }
    }
    function InitCarousel()
    {
        for(i = 0; i<carouselTotal; i=i+1)
        {
            changeOpacities(100, 0, i);
        }
        
        //showCarouselItem(0);
        showCarouselCurrent();
    }
    function showCarouselCurrent()
    {
       clearRotationThread();
       rotationThread= setInterval("showCarouselItem(-1);",4000);
    }

    function showCarouselItem(index)
    {

        if(index>=0)
        {
            clearRotationThread();
            //show the current having mouse over. 
            carouselEx=carouselCurrent;
            carouselCurrent=index;
        }
        else
        {   //loop from first to last and remmber the current and last displayed
            carouselEx=(carouselCurrent>=0 && carouselCurrent<carouselTotal) ? carouselCurrent : 0;
            index= (carouselCurrent>=0 && carouselCurrent<carouselTotal-1)? carouselCurrent+1: 0;
            carouselCurrent=index;
        }
        opacity(carouselCurrent, carouselEx)
    }

    function opacity(idIn, idOut)
    {
        //speed for each frame
        var speed = Math.round(600 / 50);
        var timer = 0;
        
        //determine the direction for the blending, if start and end are the same nothing happens
        for(i = 0; i <= 100; i=i+5)
        {
            setTimeout("changeOpacities(" + i + ",'" + idIn + "', '"+idOut+"')",(timer * speed));
            timer++;
        }
    }

    function changeOpacities(opacity, idIn, idOut) 
    {
        if(idIn!=idOut)
        {
            changeOpacity(100 - opacity, "div_ic_"+idOut, 1);
            changeOpacity(100 - opacity, "div_tc_"+idOut, 1);
            changeTextColor("li_link"+idOut, "#aaa");
            changeBG("li_link"+ idOut, "transparent");
        }
        changeOpacity(opacity, "div_ic_"+idIn, 10);
        changeOpacity(opacity, "div_tc_"+idIn, 10);
        changeTextColor("li_link"+ idIn, "#fff");
        changeBG("li_link"+ idIn, "#ccc");
    }

    //change the opacity for different browsers 
    function changeOpacity(opacity, id, zIndex)
    {
        try{
            var object = document.getElementById(id).style;
            
            object.opacity = (opacity / 100);
            object.MozOpacity = (opacity / 100);
            object.KhtmlOpacity = (opacity / 100);
            object.filter = "alpha(opacity=" + opacity + ")";
            object.zoom = 1; // give element layout for ie 6
            object.zIndex = zIndex;
        }catch(ex){}
    }
    //change the color for different browsers 
    function changeTextColor(id, color)
    {
        try{
            var object = document.getElementById(id).style;
            object.color = color;
        }catch(ex){}
    }
    
    function changeBG(id, backgroundColor)
    {
        try{
            var object = document.getElementById(id).style;
            object.backgroundColor = backgroundColor;
        }catch(ex){}
    }
    //start the rotation
    setTimeout("InitCarousel();",500);
    
DOMhelp.addEvent(window,'load',leftNavhl.init,false);
DOMhelp.addEvent(window,'load',leftNavhls.init,false);

/**
SAL - Simple Ajax Lib. 23-Sep-2005
by Nigel Liefrink
Email: leafrink@hotmail.com
*/

window.debug = false;
/**
Browser Compatability function.
Returns the correct XMLHttpRequest depending on the current browser.
*/
function GetXmlHttp() {	
	var xmlhttp = false;
	
	//console.log('ajax GetXmlHttp default var' + xmlhttp);
	
	if (window.XMLHttpRequest)
	{
	//console.log('non-IE option?');
		xmlhttp = new XMLHttpRequest();
		//console.log('new xhttpRequest readystate' + xmlhttp.readyState);
  }
	else if (window.ActiveXObject)// code for IE
	{
	//console.log('activeX (IE option)');
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
		//console.log('getXMLHttp catch has occurred');
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp=false;
			}
		}
	}
	//console.log('end of getXMLHttp, variable' + xmlhttp);
	return xmlhttp;
}


/**
<summary>
Gets the response stream from the passed url, and then calls the callbackFuntion passing the response and the div_ids.
</summary>
<param name="url">The url to make the request to get the response data.</param>
<param name="callbackFunction">The function to call after the response has been recieved. the response <b>must</b> always be the first argument to the function.</param>
<param name="params"> (optional) Any other parameters you want to pass to the functions. (Note: only constants/strings/globals can be passed as params, most variables will be out of scope.) </param>
</summary>
<example>
	<code>
PassAjaxResponseToFunction('?getsomehtml=1', 'FunctionToHandleTheResponse', "\'div1\',\'div2\',\'div3\'');

function FunctionToHandleTheResponse(response, d1, d2, d3){
	var data = response.split(';');
	document.getElementById(d1).innerHTML = data[0];
	document.getElementById(d2).innerHTML = data[1];
	document.getElementById(d3).innerHTML = data[2];
}
	</code>
</example>
*/
function PassAjaxResponseToFunction(url, callbackFunction, params)
{		
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
			                                var response = xmlhttp.responseText;
			                                var functionToCall = callbackFunction+'(response,'+params+')';
			                                if(window.debug){
				                                alert(response);
				                                alert (functionToCall);
			                                }
			                                eval(functionToCall);
		                                } else if(window.debug){
			                                document.write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
}


/**
///<summary>
///Sets the innerHTML property of obj_id with the response from the passed url./
///</summary>
///<param name="url">The url to make the request to get the response data.</param>
///<param name="obj_id">The object or the id of the object to set the innerHTML for.</param>
*/

function SetInnerHTMLFromAjaxResponse(url, obj_id)
{	

//TTP 2743/RedMine 41 MLC 16-12-2008 - use this jquery instead!
try
{
$('#'+obj_id).load(url);
//console.log("J QUERY LOADED URL" + url);
}
catch(ex){//console.log("ex");
}

//TTP 2743/RedMine 41 MLC - all the following can be replaced by the above jquery!!!

//    
//  //console.log('inside ajax, url' + url);

//  var xmlhttp = new GetXmlHttp();
//  
//  //console.log('ajax, after getXmlhttp' + xmlhttp);
//  //now we got the XmlHttpRequest object, send the request.
//  if (xmlhttp)
//  {
//  //console.log('inside xmlHTTP, readyState=' + xmlhttp.readyState);
//    xmlhttp.onreadystatechange = function () 
//                                {
//	                               
//                                    //console.log('readystate' + xmlhttp.readyState);
//	                                if (xmlhttp && xmlhttp.readyState==4)
//	                                {//we got something back..
//		                           
//		                                //console.log(xmlhttp.status);
//		                                if (xmlhttp.status==200)
//		                                {
//			                                try{
//			                                    //console.log(obj_id);
//			                                    //console.log(xmlhttp.responseText);
//			                                    
//			                                    
//			                                    if(typeof obj_id == 'object')
//			                                    {
//			                                    //console.log('inside object');
//                                                    obj_id.innerHTML = xmlhttp.responseText;
//			                                    } else {
//			                                    
//			                                    //console.log('inside ID');
//				                                    document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
//			                                    }
//			                                    
//			                                    //this is hard-coded test code (TTP 2743/RedMine 41 MLC) and this works because the objID is being lost
//			                                    document.getElementById('ctl00_middlecontent_ReviewArticle1_bestPrice').innerHTML = xmlhttp.responseText;

//			                                }
//			                                catch(ex){//console.log(ex);}
//		                                } else if(window.debug){
//			                                document.Write(xmlhttp.responseText);
//		                                }
//	                                }
//                                }
//    xmlhttp.open("GET",url,true);
//    xmlhttp.send(null);
//  }
//  


}


function UpdateResponseScript(url)
{
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
//			                                if(window.debug){
//				                                alert(xmlhttp.responseText);
//		
//			                                }
                                            try{
			                                    eval(xmlhttp.responseText);
			                                }catch(exce){
			                                //alert("error : " + exce); alert(xmlhttp.responseText);
			                                }
		                                } else if(window.debug){
			                                document.Write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
}

function UpdateUserControl(url, obj_id)
{		
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
			                                
			                                var rstring=xmlhttp.responseText;
			                                var fromindex = rstring.indexOf('<br style="display:none;ajax:start" />');
			                                if(fromindex >= 0 )
			                                {
			                                   rstring=rstring.substring(fromindex,rstring.indexOf('<br style="display:none;ajax:end" />'));
    		                                }
    		                                else
    		                                {
    		                                    fromindex = rstring.indexOf('<form ');
    		                                    if(fromindex>=0)
    		                                    {
    		                                        fromindex = rstring.indexOf('>',fromindex+1);
    		                                        rstring=rstring.substring(fromindex+1,rstring.indexOf('</form>'));
    		                                    }
    		                                }

				                    
			                                if(typeof obj_id == 'object'){
				                                obj_id.innerHTML = rstring
			                                } else {
				                                document.getElementById(obj_id).innerHTML = rstring
			                                }
			                                try{
			                            	    var cookiebegin = rstring.indexOf("<cookie");
			                                    if(cookiebegin >= 0)
			                                    {
			                                        rstring = rstring.substring(cookiebegin+8,rstring.indexOf(">",cookiebegin+1));
                                                    cookiebegin=rstring.indexOf("\"");                                    			                                        
			                                        rstring = rstring.substring(cookiebegin+1,rstring.indexOf("\"",cookiebegin+1));
			                                        var cokkienamevalue = rstring.split(":");
			                                        SetCookie(cokkienamevalue[0],cokkienamevalue[1],cokkienamevalue[2]);
			                                    }
			                                  }catch(e){}
		                                } else if(window.debug==true){
			                                document.Write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
  return false;
}

function SetCookie(cookieName,cookieValue,nDays) {
     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0) nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+escape(cookieValue)
				     + ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName) {
     var theCookie=""+document.cookie;
     var ind=theCookie.indexOf(cookieName);
     if (ind==-1 || cookieName=="") return ""; 
     var ind1=theCookie.indexOf(';',ind);
     if (ind1==-1) ind1=theCookie.length; 
     return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function clearCombo(cboX){
    for(i = cboX.options.length; i > 0; i--){
        cboX.options[i]=null;
    }  
}  
// 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_WithPRCategory(ControlID,UrlProcessor,EditorialItemID,PriceRunnerProductId,PriceRunnerCategoryId,product)
{
//console.log("JS UTILS");
//console.log("controlID=" + ControlID);

    var sURL=UrlProcessor +"?EditorialItemID=" + EditorialItemID +"&PRProductId="+ PriceRunnerProductId +"&PRCategoryID="+ PriceRunnerCategoryId +"&product="+ product;

    
    SetInnerHTMLFromAjaxResponse(sURL,ControlID);
    
    //console.log('here (after Ajax JS call)');
    return false;
}

function UpdateBestPrice(ControlID,UrlProcessor,EditorialItemID,PriceRunnerProductId,product)
{
//console.log("no pr category, invalid?");
    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, "stuff_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 InitHcmPlayer(flashUrl,playerPath,playerDivId,editorialId,innersection,width,height,videoPreRoll)
{
    //TTP 2337, 2319 code optimisation
    
    //TTP 2696  SponsoredVid is removed just commented it
    // if(innersection == "SponsoredVid")
  //  {
  //      flashUrl = "rtmp://cp38076.edgefcs.net/ondemand/streamuk/stuff/advertorial/sony/Sony_Vaio_FW_Stuff.flv";   
   // }
   // else
   // {
        flashUrl = flashUrl +"&InnerSection="+"" + innersection + ""+"&EditorialItemID="+"" + editorialId +"";
   
   // }
 
 //respond to PreRoll switch (set in appSettings.config)
 //TTP 2440
 if(videoPreRoll == "true")
 {
 //contains displayclick:"link"
     window.player = new HCMPlayer({playerConfiguration:{autostart: "true", quality:"true" ,displayclick:"link"}, playerHeight:"" + height +"", playerWidth:"" + width +"", mpuDivId:"mpuHolder", playerDivId:"" + playerDivId + "",crossdomain:'<%=ResolveUrl("~/crossdomain.xml")%>', playerFile:"" + flashUrl +""}).init();            
    }
   else
   {
    //does not contain displayclick:"link"
     window.player = new HCMPlayer({playerConfiguration:{autostart: "true", quality:"true"}, playerHeight:"" + height +"", playerWidth:"" + width +"", mpuDivId:"mpuHolder", playerDivId:"" + playerDivId + "",crossdomain:'<%=ResolveUrl("~/crossdomain.xml")%>', playerFile:"" + flashUrl +""}).init();            
    }
          
}

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';
}

// disappearing text for search box

var HintClass = "searchInput";
var HintActiveClass = "searchInputActive";

// define a custom method on the string class to trim leading and training spaces
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

function initHintTextboxes() {
  var inputs = document.getElementsByTagName('input');
  for (i=0; i<inputs.length; i++) {
    var input = inputs[i];
    if (input.type!="text")
      continue;
      
    if (input.className.indexOf(HintClass)!=-1) {
      input.hintText = input.value;
      input.className = HintClass;
      input.onfocus = onHintTextboxFocus;
      input.onblur = onHintTextboxBlur;
    }
  }
}

function onHintTextboxFocus() {
  var input = this;
  if (input.value.trim()==input.hintText) {
    input.value = "";
    input.className = HintActiveClass;
  }
}

function onHintTextboxBlur() {
  var input = this;
  if (input.value.trim().length==0) {
    input.value = input.hintText;
    input.className = HintClass;
  }
}

window.onload = initHintTextboxes;

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

