﻿// JScript File    
var myID = 0;
var fLoaded = 0;

function doSearchGeneric(id) {
    var form1 = document.getElementById(id);
    var keywords, language, city;
    var u;
    if (form1.keywords.value) {
      keywords = form1.keywords.value;
    } else {
      keywords = ""
    }
    city = form1.city.value;
    if (city != "Montreal")
    {
      u = "/" + city + "/searchresults?searchtype=Article&r=(FullCategory:%22/Cities/" + city + "%22 OR FullCategory:%22/Cities/All English Cities%22)";
    }
    else
    {
      u = "/searchresults?searchtype=Article&r=FullCategory:Cities/" + city;
    }
    u =  u + "&q=" + keywords;
    document.location.href=u;
    return false;
}  

  
function doLocalSearch(id, city) {
    var form1 = document.getElementById(id);
    var what, where, city;
    what = form1.what.value;
    where = form1.where.value;
    city = form1.city.value;
    var stype=form1.stype[1].checked;
    var u = city + "/zipsearch?fs=http://www.ziplocal.com/find/" + what + "-in-" + where + '.iframe';
    if(stype)
    {
      var u = city + "/zipsearch?fs=http://www.ziplocal.com/find/" + what + "-near-" + where + '.iframe';
    }
    document.location.href = u;
    return false;
}  

function clearText(thefield){
  if (thefield.defaultValue==thefield.value) thefield.value = "";
} 

function viewmore(divid,expandid,collapseid) { 
    thisdiv = document.getElementById(divid);
    expand = document.getElementById(expandid);
    collaps = document.getElementById(collapseid);
    if(thisdiv.style.display == "none") {
        thisdiv.style.display = "block";
        expand.style.display = "none";
        collaps.style.display = "block";
     } else {
       thisdiv.style.display = "none";
       expand.style.display = "block";
       collaps.style.display = "none";
    }   
}   


//Change font size for article body

var defaultfontsize=14;
function SetFontSize(p) {
if (p == "grow") {
if(defaultfontsize<16) { defaultfontsize+=2; }
}
else {
if(defaultfontsize>10) { defaultfontsize-=2; }
}
document.getElementById('articlemain').style.fontSize=defaultfontsize+'px';
}


function SetFontSize_v2(p) {
if (p == "grow") {
if(defaultfontsize<21) { defaultfontsize+=2; }
}
else {
if(defaultfontsize>10) { defaultfontsize-=2; }
}
document.getElementById('articlemain').style.fontSize=defaultfontsize+'px';
document.getElementById('articlemain').style.lineHeight=(defaultfontsize+1)+'px';

}



function initfontsize()
{
document.getElementById('articlemain').style.fontSize=defaultfontsize;
}




//Open new window
 function openWin(url) {
        aWindow = window.open(url, 'cgiwindow', 'Toolbar=no, Location=no, Directories=no, Status=0, Menubar=0, Scrollbars=1,  Resize=1, width=780, height=750');
    }
    
    
//Open Print Preview window
 function openWinPrintPreview(url) {
        aWindow = window.open(url, 'cgiwindow', 'Toolbar=no, Location=no, Directories=no, Status=0, Menubar=0, Scrollbars=1,  Resize=1, width=900, height=600');
    }    
    
    
    
//Open new window shorter height
 function openWinSmall(url) {
        aWindow = window.open(url, 'cgiwindow', 'Toolbar=no, Location=no, Directories=no, Status=0, Menubar=0, Scrollbars=1,  Resize=1, width=780, height=500');
    }    
    
    
// Print from a frame     
function printArticle()
{
window.frames['this2print'].focus();
window.frames['this2print'].print();

}  

var toggleOpenPic = new Image;
var toggleClosePic = new Image;
toggleOpenPic = "/App_Themes/standard/images/structure/minimizeCmp1.gif";
toggleClosePic = "/App_Themes/standard/images/structure/maximizeCmp1.gif";
		
function toggleImageLrg(myID) {
	var str = myID.src;
	    if(str.indexOf('minimizeCmp1.gif') != -1) {
		    myID.src = toggleClosePic;
	    } else {
		    myID.src = toggleOpenPic;
	    }
	}
	
	function swicth_and_open(a,x)
	{
	if($("#"+a).is(":hidden"))
	{
	$("#"+a).slideDown("normal");
	$(x).attr("src",toggleOpenPic);
	}else{
	$("#"+a).slideUp("normal");
	$(x).attr("src",toggleClosePic);
	}
	
	}
// Article image js
function fLoadTrue(variable){
fLoaded = variable;
}

function showMovieImg(){
    document.getElementById('thumbnailsHolder').style.display='block';
}

function controlMovieSelect(selector){
    if(myID != 0){
        if (myID != selector){
            document.getElementById('movie'+myID).className='movieThum';
            document.getElementById('movie'+selector).className='movieThumSelected';
            myID = selector;
        }
    } else {
        document.getElementById("movie"+selector).className="movieThumSelected";
        myID = selector;
    }
}

//Main feature tabs
var remember = 'button1';
function revertOld(selected){

    document.getElementById(selected).className='tabbuttonSel';
    document.getElementById(remember).className='tabbutton';  
    remember = selected;
}
function createCookieUntil(name, value, days) {

    var expires = "";
    var date = new Date();
    switch (days) {
        case 1:
           // date.setDate(date.getDate() + 1)
             
            break;
        case 7:
            while (date.getDay() != 0) {
                date.setDate(date.getDate() + 1)
            }
            break;
        default:
            date.setDate(date.getDate() + 60)
            break;

    }
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    if (days==1 || days==7 ) {
        expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    
    
    document.cookie = name + "=" + value + expires + "; path=/";
}

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 var 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;
}
function getQueryString()
        {
          var q = String (document.location).split ('?')[1];
          if (!q) return '';
          q = q.split('&');
          for (var i = 0 ; i < q.length; i++)
          {
             if(q[i].split('=')[0]=='rurl')
             {
               return q[i].split('=')[1]
             }
          }
        }
function SelectCity(city, cityUrl)
{
   var a='';
   if(city.toLowerCase()=='montréal')
    a=cityUrl+getQueryString().replace('/','');
    else
    a=cityUrl+getQueryString();
    createCookie("MetroNewsDefaultCity", cityUrl, 9000);
    document.location.href = a;
}
function SelectCity2(city, cityUrl, path)
{
   var a='';
   if(city.toLowerCase()=='montréal')
    a=cityUrl+getQueryString().replace('/','');
    else
    a=document.location.href;
    createCookie("MetroNewsDefaultCity", cityUrl, 9000);
    //alert(cityUrl);
    //hidelayer();
    document.location.href = cityUrl+path;
}
function SelectCityWithoutRedirect(city, cityUrl,Redirect)
{
   var a='';
   if(city.toLowerCase()=='montréal')
    a=cityUrl+getQueryString().replace('/','');
    else
    a=cityUrl+getQueryString();
    createCookie("MetroNewsDefaultCity", cityUrl, 9000);
    
    document.location.href = Redirect;
}
function IsCitySelected()
{
    var defaultCity = readCookie("MetroNewsDefaultCity");
    if (defaultCity){
       if(defaultCity.indexOf("journalmetro")>-1 || defaultCity.indexOf("Montreal")>-1 || defaultCity.indexOf("montréal")>-1 || defaultCity.indexOf("montreal")>-1)
       {
       
       }else{document.location=defaultCity;}
       }
}

function changePopShare(parent,myid) {
    if (parent == "MostPopularWithCity_counterscontainer"){
        if(myid == "MostPopularWithCity_MostReadCounter" ){
            document.getElementById("mostTabs").className="finderTopBar mostPopular";
        }
        if(myid == "MostPopularWithCity_MostEmailedCounter"){
            document.getElementById("mostTabs").className="finderTopBar mostShared";
        }
    }
}
function GetLocalGuidesLink(x)
{if(x!=""){window.open(x,'_blank');}}
/*
onkeydown="limitText(this,900);" 
onkeyup="limitText(this,900);"
*/
function limitText(a,lim_num)
{
 var indx=$(a).attr("value").indexOf(":");
 if(indx>-1)
 {
 $(a).attr("value",$(a).attr("value").substring(0, indx));
 }
    if($(a).attr("value").length>lim_num)
    {
     $(a).attr("value",$(a).attr("value").substring(0, lim_num));
    }
}


function ProcessCreditLine_en(a,media_server)
{
    var br_box ="";
    var img_box="";
    var author="";
    if(a.indexOf("THE CANADIAN PRESS")>-1)
    {
      img_box="<img src='"+media_server+"/images/CP-Logo.jpg'>";
    }
    if(a.indexOf("CITYTV")>-1)
    {
     img_box="<img src='"+media_server+"/images/Citytvlogo.gif'>";
    }
    if(a.indexOf(",")>-1 && img_box!="")
    {
     br_box ="<br/>"
     author=a.substring(0,a.indexOf(","));
    }else{
      if(img_box==""){author=a;}
    }
 return author+br_box+img_box;
}

function ProcessCreditLine_fr(a,media_server)
{
    var br_box ="";
    var img_box="";
    var author="";
    if(a.indexOf("LA PRESSE CANADIENNE")>-1)
     {
      img_box="<img src='"+media_server+"/images/CP-Logo-fr.jpg'>";
     }
     if(a.indexOf("CITYTV")>-1)
     {
      img_box="<img src='"+media_server+"/images/Citytvlogo.gif'>";
     }
    if(a.indexOf(",")>-1 && img_box!="")
    {
     br_box ="<br/>"
     author=a.substring(0,a.indexOf(","));
    }else{
      if(img_box==""){author=a;}
    }
   return author+br_box+img_box;
}


function CreateCookieLink(uid)
{
createCookie(uid,'1',0.02);
return true;
}

/*function limitTextx(id_val,  limitNum) {
var limitField=document.getElementById(id_val);
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} }
	
    function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	
}else{
$("#"+limitCount).attr("value",limitNum-limitField.value.length);
}

}*/

function GetWeatherRequest(city){
$.get("/weather/?pcity="+city, function(data){
$(data,"#full_weather_request").find("div").each(function() {

if($(this).attr("id")=="latest_updated_ajax")
{$("#Lupdate").html($(this).html());}
if($(this).attr("id")=="Weather_info")
{$("#mainweatherBox").html($(this).html());}
});
});
}
function gettimeDiff(d1,d2)
{
var x0=(d2.getHours()-d1.getHours())*60;
var x1=((d2.getMinutes()+x0)-d1.getMinutes())*60;
var x2=((d2.getSeconds()+x1)-d1.getSeconds())*1000;
var x3=(d2.getMilliseconds()+x2)-d1.getMilliseconds();
return parseInt(x3/10);
}

function changeTicker(tickerNumber, numOfNews) {
    tickerNumber++;
    currentTicker = "#latest" + tickerNumber;
    $('#metroTickerLatest').fadeOut('slow', function() { $('#metroTickerLatest').html($(currentTicker).html()); });
    if (tickerNumber >= (numOfNews)) tickerNumber = 0;
    $('#metroTickerLatest').fadeIn('slow', function() { });
    if (stop_ticker == "") {
        setTimeout("changeTicker(" + tickerNumber + ", " + numOfNews + ")", delay * 1000);
    }
}

function howManyMinutesAgo(myYear, myMonth, myDay, myHour, myMinutes, mySeconds, uid, maxMinutes)
{
    articleDate= new Date(myYear, myMonth-1, myDay, myHour, myMinutes, mySeconds);                                
    numberOfMinutes = Math.round((new Date() - articleDate)/1000/60);                
    if(numberOfMinutes <= maxMinutes)
    {
        $('#mainSectionMainStoryHowLongAgo'+uid).text(numberOfMinutes + ' minutes ago');   
        $('#mainSectionMainStoryHowLongAgo'+uid).show();
        $('#mainSectionMainStoryHowLongAgoSeparator'+uid).show();
        
    }
}
function howManyMinutesAgo(myYear, myMonth, myDay, myHour, myMinutes, mySeconds, uid, maxMinutes, pcity)
{
    articleDate= new Date(myYear, myMonth-1, myDay, myHour, myMinutes, mySeconds);                                
    numberOfMinutes = Math.round((new Date() - articleDate)/1000/60);                
    if(numberOfMinutes <= maxMinutes)
    {
        if (pcity == 'montreal')
        {
        $('#mainSectionMainStoryHowLongAgo'+uid).text('Il y a ' + numberOfMinutes + ' minute(s)');   
        }
        else
        {
        $('#mainSectionMainStoryHowLongAgo'+uid).text(numberOfMinutes + ' minutes ago');   
        }
        $('#mainSectionMainStoryHowLongAgo'+uid).show();
        $('#mainSectionMainStoryHowLongAgoSeparator'+uid).show();
        
    }
}
function InitMenus() {
    $("div.metroNavElements").each(function(index) {

        var x = $(this).children(".metroSubNav"); x.slideDown(0.1, function() {
            x.slideUp(0.1, function() { /*menu_beig_used = 0;*/ });
        });

    });

    $("div.metroNavElements").hover(
        function() { var x = $(this).children(".metroSubNav"); CheckAndUp(x); },
        function() { var x = $(this).children(".metroSubNav"); CheckAndDown(x); }

        );
    $(".seperator_nav:last").css("display", "none");
}
function CheckAndUp(a) {
    if (a.css("display") == "none") { a.slideDown(500, function() { }); }
}
function CheckAndDown(a) {
    if (a.css("display") == "block") { a.slideUp(50, function() { }); }
}
function Clear_search_box_in(a) {
    if ($("#search_text_box").attr("value") == a) {
        $("#search_text_box").attr("value", "");
    }
}
function Clear_search_box_out(a) {
    if ($("#search_text_box").attr("value") == "") {
        $("#search_text_box").attr("value", a);
    }
}
function howManyMinutesAgo_fr(myYear, myMonth, myDay, myHour, myMinutes, mySeconds, uid, maxMinutes)
{
    articleDate= new Date(myYear, myMonth-1, myDay, myHour, myMinutes, mySeconds);                                
    numberOfMinutes = Math.round((new Date() - articleDate)/1000/60);                
    if(numberOfMinutes <= maxMinutes)
    {
        $('#mainSectionMainStoryHowLongAgo'+uid).text('Il y a ' + numberOfMinutes + ' minute(s)');   
        $('#mainSectionMainStoryHowLongAgo'+uid).show();
        $('#mainSectionMainStoryHowLongAgoSeparator'+uid).show();
        
    }    
}