﻿


function addEvent(obj, evType, fn){ 
    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, false); 
        return true; 
    } else if (obj.attachEvent){ 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    } else { 
        return false; 
    } 
}

function toggleOff(listItemName)
{
    if (listItemName != null)
    {
        listItemName.style.display = "none";
    }
}

function validateImage(image, listItemName)
{
    if (!isImageOk(image))
    {
        toggleOff(listItemName);
    }
}

function ReplaceBadImageWithPlaceHolder(img)
{
    if(!isImageOk(img))
    {
        img.src = "../resources/images/no_image_avail.gif";
    }
}

function isImageOk(img)
{

    if (!img.complete) {
        return false;
    }

    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    return true;
}

String.prototype.format = function()
{
    var str = this;

    for(var i=0;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }

    return str;
}

/////news Image
var imgHeight=0;
var imgWidth=0;
function imgLoad(imgNews)
{
   var img = new Image();
   
   if (img != null)
   {
       img.src = imgNews.src;
       imgHeight=img.height;
       imgWidth=img.width;
   }

   var proportion;
   if(imgNews.src.indexOf("no_image_avail.gif")>0)
        {
        imgNews.style.display="none";
        document.getElementById("topNewsPhoto").innerHTML="<div style='color:#5A5A5A; font-size:12px;'>&#9679;</div>"
        }
     else
        {
        imgNews.style.display="block";    
        }
//   imgHeight=imgNews.height;
//   imgWidth=imgNews.width;

   if(imgWidth>imgHeight)
    {
        if(imgWidth>85)
        {
        proportion=imgWidth/imgHeight;
        document.getElementById("newsImg").style.width="85px";
        newWidth=parseFloat(document.getElementById("newsImg").style.width);
        newHeight=Math.floor(85/proportion);
        document.getElementById("newsImg").style.height=newHeight+"px";
        }
    }
    else
    {
        if(imgHeight>85)
        {
        proportion=imgHeight/imgWidth;
        document.getElementById("newsImg").style.height="85px";
        newHeight=parseFloat(document.getElementById("newsImg").style.height);
        newWidth=Math.floor(85/proportion);
        document.getElementById("newsImg").style.width=newWidth+"px";
        }
    }
}   

function Over(event,Url)
{
  doTooltip(event,Url,imgWidth,imgHeight);
}
           

//////////SearchBar
var slogan=true;
                
function TxtFocus(txt)
{
    if(slogan)
    {
        txt.style.color="#111111";
        txt.value="";
        txt.style.fontSize="24px";
        txt.style.fontFamily="Arial,Helvetica,sans serif";
        slogan=false;
    }
}

function TestTextBox()
{
    if(document.getElementById("ctl00_MainContent_txtSearch").value==" It's ok, you're not cheating on Google...")
    document.getElementById("ctl00_MainContent_txtSearch").value="";
}

//////////////loading Main Page
function MainPageLoad()
{
document.getElementById("ctl00_MainContent_txtSearch").focus();
document.getElementById("aBack").removeAttribute("href");
document.getElementById("aBack").style.textDecoration="underline";
document.getElementById("aBack").style.cursor="pointer";
document.getElementById("aBack").style.display="block";
}

function BackClick()
{
    eraseCookie("LFHomePage");
    window.location="../";
}

///Weather
function hov(loc,cls){
   if(loc.className)
      loc.className=cls;}
      
 function ZipClick1(txt)
 {
    txt.value="";
 }
 
 ///Javascript enabled results controls
function getQueryStrings() {
    var argList = new Object();

    if(window.location != null && window.location.search.length > 1) {
        var urlParms = window.location.search.substring(1);
        var argPairs = urlParms.split('&');

        for(var i = 0; i < argPairs.length; i++) {
            var pos = argPairs[i].indexOf('=')

            if(pos == -1)
                continue;
            else {
                var argName = argPairs[i].substring(0, pos);
                var argVal = argPairs[i].substring(pos + 1);

                if(argVal.indexOf('+') != -1)
                    argVal = argVal.replace(/\+/g, ' ');

                argList[argName] = unescape(argVal);
            }
        }
    }
    
    return argList;
}

function getSearchTerm(){
    var searchWord = "";
    var argList = getQueryStrings();
    var topSearchBox = document.getElementById('ctl00_MainContent_TopSearch_txtSearch');
    var bottomSearchBox = document.getElementById('ctl00_MainContent_BottomSearch_txtSearch');
    
    var querySearch = "";
    var topSearch = "";
    var bottomSearch = "";
    
    if (argList != null)
    {
        if (argList["search"] != null)
        {
            querySearch = argList["search"];
        }
    }    
    
    if (topSearchBox != null)
    {
        // don't escape here, escape at the end of function
        topSearch = topSearchBox.value;
    }
    
    if (bottomSearchBox != null)
    {
        // don't escape here, escape at the end of function
        bottomSearch = bottomSearchBox.value;
    }
    
    if (querySearch.length > 0)
    {
        searchWord = querySearch;
        
        if ((topSearch == querySearch) && (bottomSearch.length > 0))
        {
            searchWord = bottomSearch;    
        }
        else if ((bottomSearch == querySearch) && (topSearch.length > 0))
        {
            searchWord = topSearch;
        }
    }
    
    return escape(searchWord);
}

 function LoadPage()
 {
 /*
 document.getElementById("newPager").innerHTML=document.getElementById("PagerHolder").innerHTML;
 document.getElementById("PagerHolder").style.display="none";
 */
        var browser=navigator.appName;
        if ((browser=="Microsoft Internet Explorer") && (document.getElementById('header') != null))
        {
            document.getElementById('header').style.overflow="hidden";
        }
 }
 
 
 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 eraseCookie(name) {
	createCookie(name,"",-1);
}

 
 
 function SetHomeCookie()
 {
 createCookie("LFHomePage","Classic", 3000);
 }

