function f_uploadchkcook(){
   var userid = getCookie("userid");
   if (userid != null){
   <!--
      document.writeln("<input type=\"hidden\" name=\"inUID\" value=\""+getCookie("userid")+"\" />");
   //-->
   } else {
      document.location.href="/";
   }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function PopUp(win_name,URL,width,height,scrollbars,menubar){

if (scrollbars==null){
   scrollbars=0;
}

if (menubar==null){
   menubar="no"
}

    open( URL,win_name, "width="+width+",height="+height+",left=465,top=437,status=0,toolbar=0,menubar="+menubar+",resizable=no,location=0,scrollbars="+scrollbars+"");
}

function f_nktxtsrc(){
   var txtvl = document.logohsrchfrm.qrytxt.value;
   if (txtvl.indexOf(",")>=0){
     for (i=0;i<txtvl.length;i=i+1){
       txtvl = txtvl.replace(",","");
     }
   }
   document.logohsrchfrm.qrytxtc.value = txtvl;
}
function f_clear_search(){
if (document.srchfrm.in_query.value == "Search") {
	document.srchfrm.in_query.value = ""; } 
}

function f_advcdsub(onSubCall){
   var txtvl = document.advancedsearch.qrytxt.value;
   if (txtvl.indexOf(",")>=0){
     for (i=0;i<txtvl.length;i=i+1){
       txtvl = txtvl.replace(",","");
     }
   }
   document.advancedsearch.qrytxtc.value = txtvl;
   doDates();
   if (onSubCall == "no"){
      document.advancedsearch.submit();
   }
}

function fsubBlogChkr(in_form_name){
    var title = document[in_form_name]["inTitle"].value;
    var description = document[in_form_name]["inDescription"].value;
    var url = document[in_form_name]["inURL"].value;
    if (title == ""){
       alert("Please enter a Title");
    } else if (description == ""){
       alert("Please enter a Description");
    } else if (url == ""){
       alert("Please enter a URL");
    } else {
      document[in_form_name].submit();
    } 
}

function fsubArtChkr(in_form_name){
    var headline = document[in_form_name]["inHlne"].value;
    var ArtTxt = document[in_form_name]["inArtTxt"].value;
    if (headline == ""){
       alert("Please enter a headline");
    } else if (ArtTxt == ""){
       alert("Please enter article text");
    } else {
       eval('document.' + in_form_name + '.submit();');
    } 
}

function f_readl(){
   if (document.readl.to.value==""){
       window.alert("Please fill in your email address.");
  } else {
     document.readl.submit();
  }
}

function fcmarplc(in_form_name,in_field_nm){
   var inTxt = document[in_form_name][in_field_nm].value;
   varTxtA = inTxt;
   for (i=0;i<varTxtA.length;i=i+1){
      varTxtA = varTxtA.replace("(","");
      varTxtA = varTxtA.replace(")","");
      varTxtA = varTxtA.replace("'","");
      varTxtA = varTxtA.replace(",","");
   }
   document[in_form_name][in_field_nm].value = varTxtA;
}

function surfto(form,select_name,scope) {   
   var myindex=form.elements[select_name.name].selectedIndex;
   if (form.elements[select_name.name].options[myindex].value != "0") {
      if (scope==0) {
         window.location=form.elements[select_name.name].options[myindex].value;
      } else if (scope==1) {
                                top.location=form.elements[select_name.name].options[myindex].value;
      } else if (scope==2) {
                                // Defining scope this way allows specific conditions to be met for certain pages in future
                                window.open(form.elements[select_name.name].options[myindex].value,"","scrollbars,resizable,width=400,height=480");
                }
        }
}

function setCookie(name,value,expires,path,domain,secure){
var curCookie=name+"="+escape(value)+
((expires)?"; expires="+expires.toGMTString():"")+
((path)?"; path="+path:"")+
((domain)?"; domain="+domain:"")+
((secure)?"; secure":"");
document.cookie=curCookie;}

function getCookie(name){
var dc=document.cookie;
var prefix=name+"=";
var begin=dc.indexOf("; "+prefix);
if(begin==-1){
begin=dc.indexOf(prefix);
if(begin!=0)return null;
}else
begin+=2;
var end=document.cookie.indexOf(";",begin);
if(end==-1)
end=dc.length;
return unescape(dc.substring(begin+prefix.length,end));}

function deleteCookie(name,path,domain){
if(getCookie(name)){
document.cookie=name+"="+
((path)?"; path="+path:"")+
((domain)?"; domain="+domain:"")+
"; expires=Thu, 01-Jan-70 00:00:01 GMT";}}

function fixDate(date){
var base=new Date(0);
var skew=base.getTime();
if(skew>0)
date.setTime(date.getTime()-skew);}

DaysofWeek=new Array()
DaysofWeek[0]="Sunday"
DaysofWeek[1]="Monday"
DaysofWeek[2]="Tuesday"
DaysofWeek[3]="Wednesday"
DaysofWeek[4]="Thursday"
DaysofWeek[5]="Friday"
DaysofWeek[6]="Saturday"
Months=new Array()
Months[0]="Jan"
Months[1]="Feb"
Months[2]="Mar"
Months[3]="Apr"
Months[4]="May"
Months[5]="Jun"
Months[6]="Jul"
Months[7]="Aug"
Months[8]="Sep"
Months[9]="Oct"
Months[10]="Nov"
Months[11]="Dec"

function showDate()
{var dte=new Date();
var day=DaysofWeek[dte.getDay()]
var date=dte.getDate()
var month=Months[dte.getMonth()]
var spc=" ";
var com=",";
if(date==1||date==21||date==31)
ender="st";
else if(date==2||date==22)
ender="nd";
else if(date==3||date==23)
ender="rd";
else
ender="th";
return(spc+day+com+spc+month+spc+date+ender);}

function get_cookie(name)
{
  if (document.cookie.length > 0)
  {
    begin = document.cookie.indexOf(name +"=");
    if (begin != -1)
    {
      begin += name.length+1;
      end = document.cookie.indexOf(";", begin);
      if (end == -1) {
        end = document.cookie.length;
      }
    return unescape(document.cookie.substring(begin, end)); }
    }
  return null;
}

function set_cookie(name,value)
{
  document.cookie = name + "=" + escape(value);
}

function vote_check(name,rating)
{
  if (get_cookie(name) == null)
  {
    set_cookie(name,rating);
    document.voting_form.inRt.value = rating;
  }
  else {
    document.voting_form.inRt.value = -1;   
  }
  document.voting_form.submit();
}

function jsLogo(){
   var c = new Date();
   var d = c.getDay();
   var dayOfWeek = DaysofWeek[d].toLowerCase();
   document.write("<img src=\"http://img.metro.co.uk/i/mastHead/daypart/" + dayOfWeek  + "Tag.gif\" width=\"61\" height=\"61\" alt=\"Metro\" id=\"MastHeadTag\" />");
}

function jsLogoPartner(){
   var c = new Date();
   var d = c.getDay();
   var dayOfWeek = DaysofWeek[d].toLowerCase();
   document.write("<img src=\"http://img.metro.co.uk/i/mastHead/daypart/" + dayOfWeek  + "Tag.gif\" width=\"61\" height=\"61\" alt=\"Metro\" />");
}


function clearArticleForm() {
  document.addcomment.inName.value = "";
  document.addcomment.inEmail.value = "";
  document.addcomment.inLocation.value = "";
  document.addcomment.inHlne.value = "";
  document.addcomment.inArtTxt.value = "";
}
function showDiv(div) {
  if (document.getElementById(div) != null){
   document.getElementById(div).style.display='block';
  }
}
function hideDiv(div) {
   if (document.getElementById(div) != null){
	document.getElementById(div).style.display='none';
   }
}
			
function showAll() {
   showDiv('headlines_news');
   showDiv('headlines_fame');
   showDiv('headlines_sport');
   showDiv('headlines_weird');
}

function closeStretch(name){
   if (document.getElementById(name + '_arrow') != null){
      document.getElementById(name + '_arrow').src=('http://img.metro.co.uk/i/new_index/new/' + name + '_closed.gif');
   }
   if (document.getElementById('click_' + name) != null){
      document.getElementById('click_' + name).src=('http://img.metro.co.uk/i/std/home/click_here.gif');
   }   
}
			
function closeAll() {
   closeStretch('news');
   closeStretch('sport');
   closeStretch('weird');
   closeStretch('fame');
}
			
function swap(hide) {		
   showAll();
   hideDiv('headlines_' + hide);				
   var id = document.getElementById(hide + '_arrow');				
   var headlines_div = document.getElementById('headlines_' + hide);
   var cut = id.src.lastIndexOf('/') + 1;
   var image = id.src.substring(cut);
   if((image == hide + '_closed.gif') && (headlines_div.style.display='none')) {
      closeAll();
      id.src=('http://img.metro.co.uk/i/new_index/new/' + hide + '_open.gif');
      document.getElementById('click_' + hide).src=('http://img.metro.co.uk/i/std/home/dont_click_here.gif');
   }
								
}
function init(){
   var stretchers = document.getElementsByClassName('stretcher'); //div that stretches
   var toggles = document.getElementsByClassName('display'); //h3s where I click on

   //accordion effect
   var myAccordion = new fx.Accordion(
     toggles, stretchers, {opacity: true, duration: 300}
   );
  
 function checkHash(){
   var found = false;
   toggles.each(function(h3, i){
      if (window.location.href.indexOf(h3.title) > 0) {
      myAccordion.showThisHideOpen(stretchers[i]);
      found = true;
      }
   });
   return found;
 }

  if (!checkHash()) myAccordion.showThisHideOpen(stretchers[0]);

}
	
	function fadeIt(direction) {
		var imageObj = new fx.Opacity('image'+count, {duration:1000});
		var headerObj = new fx.Opacity('header'+count, {duration:1000});
		var textObj = new fx.Opacity('text'+count, {duration:1000});
		
		textObj.setOpacity(1);
		textObj.custom(1,0);	
		
		headerObj.setOpacity(1);
		headerObj.custom(1,0);	
		
		imageObj.setOpacity(1);
		imageObj.custom(1,0);	
		
		if(direction=='forwards') {
			if(count < total) {
				count=count+1;
			} else {
				count=1;
			}
		} else {
			if(count > 1) {
				count=count-1;
			} else {
				count=total;
			}
		}
		
		if(document.getElementById('text'+count).style.display!='block') {
			document.getElementById('text'+count).style.display='block';
		}
		
		if(document.getElementById('image'+count).style.display!='block') {
			document.getElementById('image'+count).style.display='block';
		}
		
		if(document.getElementById('header'+count).style.display!='block') {
			document.getElementById('header'+count).style.display='block';
		}
				
		var imageObj = new fx.Opacity('image'+count, {duration:1000});
		var headerObj = new fx.Opacity('header'+count, {duration:1000});
		var textObj = new fx.Opacity('text'+count, {duration:1000});
		
		textObj.setOpacity(0);
		textObj.custom(0,1);	
		
		headerObj.setOpacity(0);
		headerObj.custom(0,1);	
		
		imageObj.setOpacity(0);
		imageObj.custom(0,1);
		
		showCount();
		scrollTimer();
	}
	
	function hideThem() {
		document.getElementById('text1').style.display='block';
		document.getElementById('image1').style.display='block';
		document.getElementById('header1').style.display='block';
		
		for(var loopCount = 2; loopCount <= total; loopCount++) {
			var textObj = new fx.Opacity('text'+loopCount);
			textObj.setOpacity(0);
			var headerObj = new fx.Opacity('header'+loopCount);
			headerObj.setOpacity(0);
			var imageObj = new fx.Opacity('text'+loopCount);
			imageObj.setOpacity(0);
		}
	}
	
	function showCount() {
		document.getElementById('counterBox').innerHTML=count+'/'+total;
	}
	
	scrollTime = 10000;
	
	function scrollTimer() {

		window.clearTimeout(tOut);
		tOut = setTimeout("fadeIt('forwards');",scrollTime); 
	}
	
	
	function mouseover(id) {
		id.className = "viral-video-box-hover";
	}
	
	function mouseout(id) {
		id.className = "viral-video-box";
	}
