
/*
Title:      Technology Review Javascript
Author:     Eben Bathalon, eben.bathalon@technologyreview.com
Notes:		Basic DOM javascript
*/





/*
Title:		Pop-up script for media viewer
Notes:		
*/
function popChild(url, width, height, winName) {
  var features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + width + ",height=" + height;
  if (winName == "") {
  	winName = "childWin";
  }
  SmallWin = window.open(url,winName,features);
  if (window.focus) {
    SmallWin.focus();
  }
}


/*
Title:		Pop-up script for printer friendly page
Notes:		
*/
function printerFriendly(url, width, height, winName) {
  var features = "bookmarks=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + width + ",height=" + height;
  if (winName == "") {
  	winName = "childWin";
  }
  SmallWin = window.open(url,winName,features);
  if (window.focus) {
    SmallWin.focus();
  }
}


/*
Title:		Style Switcher
Author:		Paul Swoden & Peter-Paul Koch @ A List Apart
Notes:		Uses alternative style sheets to switch font sizes. Works in 4.x browsers.
*/
var RateClickNum = 0

function RanNow()
{
var TempRan=Math.random()*10000000000000000;
return TempRan;
}

function clearfield(frm){
if (frm.value == "Enter Search")
	frm.value = "";
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/* End Style Switcher */


/* Discussions - Grab Parent Node ID */
function ClientClick(node){
var PARIDfrm = document.getElementById("Discuss1_ParentID");
PARIDfrm.value = node.Attributes.Value;
var tempfrm = document.getElementById("pidx");
tempfrm.value = node.Attributes.Value;
}
/* END Discussions */

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function RChange(RateNum) { //v3.0
var i=1
RateNum = RateNum +1;
for (i=1;i<=10;i++)
	{
		if (RateNum >= i) MM_changeProp('rating' + i,'','src','/images/rating/rating_over.gif','IMG');
		if (RateNum < (i+1)) MM_changeProp('rating' + i,'','src','/images/rating/rating_off.gif','IMG');
	}
}

function RateClick(RateNum,AID) { //v3.0
RateClickNum = RateNum;
MM_changeProp('rating' + RateNum,'','src',('/devtools/ratesubmit.aspx?r=' + RateNum + '&a=' + AID),'IMG');
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}
var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left="30px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" //extra
}


/*
Title:		Most Read switch (index)
Author:		Sarah Redman
Notes:		Show/hide select video sections.
*/
function switchTo(me, hide1, hide2, hide3, hide4) {
document.getElementById(hide1).style.display = "none";
document.getElementById(hide2).style.display = "none";
document.getElementById(hide3).style.display = "none";
document.getElementById(hide4).style.display = "none";
document.getElementById(me).style.display = "block";
}


/*
Title:		Most Read switch (index)
Author:		Sarah Redman
Notes:		Show/hide select video sections.
*/
function videoRoll(me, hide1, hide2, hide3, hide4, hide5, hide6) {
document.getElementById(hide1).style.display = "none";
document.getElementById(hide2).style.display = "none";
document.getElementById(hide3).style.display = "none";
document.getElementById(hide4).style.display = "none";
document.getElementById(hide5).style.display = "none";
document.getElementById(hide6).style.display = "none";
document.getElementById(me).style.display = "block";
}
