var modalsCount = 0;
var theModals = new Array();

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="graphics/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

function switchLoc(restID, locID, totalLocs){
    //alert('SwitchLoc restID=' + restID + 'locID=' + locID + 'totalLocs=' + totalLocs);
    for (i=1;i<=totalLocs;i=i+1){
        if(i != locID){
            document.getElementById('divMapLink' + restID + i).style.display="none";
        }
        else{
            document.getElementById('divMapLink' + restID + i).style.display="inline";
            if(document.getElementById('map' + restID).style.display == "inline"){
                var ptrMapAddress=eval("mapAddress"+restID+locID);
                ptrMapAddress();
            }
        }
    }
}
function showDescription(resID){
    document.getElementById('slideshow' + resID).style.display="none";
    document.getElementById('divlblDesc' + resID).style.display="none";
    document.getElementById('map' + resID).style.display="none";
    document.getElementById('divlblSlide' + resID).style.display="inline";
    document.getElementById('divlblPrice' + resID).style.display="inline";
    document.getElementById('divEmptySpace' + resID).style.display="none";
    document.getElementById('description' + resID).style.display="block";
 } 
function showSlideShow(resID){
    document.getElementById('description' + resID).style.display="none";
    document.getElementById('slideshow' + resID).style.display="block";
    document.getElementById('divlblDesc' + resID).style.display="inline";
    document.getElementById('divlblSlide' + resID).style.display="none";
    document.getElementById('divlblPrice' + resID).style.display="inline";
    document.getElementById('map' + resID).style.display="none";
    document.getElementById('divEmptySpace' + resID).style.display="none";
}
function showMap(resID){
        hideComment(resID);
     document.getElementById('slideshow' + resID).style.display="none";
     document.getElementById('description' + resID).style.display="none";
     document.getElementById('divlblPrice' + resID).style.display="none";
     document.getElementById('divEmptySpace' + resID).style.display="inline";
     document.getElementById('divlblDesc' + resID).style.display="inline";
     document.getElementById('divlblSlide' + resID).style.display="inline";
     document.getElementById('map' + resID).style.display="inline";
 }
function showPlay(resID){
    document.getElementById('divPlay' + resID).style.display="inline";
    document.getElementById('divPause' + resID).style.display="none";
 }
function showPause(resID){
    document.getElementById('divPlay' + resID).style.display="none";
    document.getElementById('divPause' + resID).style.display="inline";
}
function showComment(resID, locID){
     document.getElementById('topleftbar' + resID).style.display="none";
     document.getElementById('slideshow' + resID).style.display="none";
     document.getElementById('description' + resID).style.display="none";
     document.getElementById('map' + resID).style.display="none";
     document.getElementById('tddivide' + resID).style.borderRight="none";
     document.getElementById('themiddletd' + resID).style.display="none";
     document.getElementById('commentleft' + resID).style.display="block";
     //document.getElementById('commentright' + resID).style.display="block";
     //document.getElementById('themiddletd' + resID).style.width="356px";
     document.getElementById('icomment' + resID).src='comment.aspx?rid=' + resID + '&lid=' + locID;
}
function cancelComment(resID){
     hideComment(resID);
}
function hideComment(resID){
     document.getElementById('commentleft' + resID).style.display="none";
     //document.getElementById('commentright' + resID).style.display="none";
     
     document.getElementById('topleftbar' + resID).style.display="block";
     document.getElementById('themiddletd' + resID).style.display="block";
     document.getElementById('tddivide' + resID).style.borderRight="solid 4px #981334";
     document.getElementById('themiddletd' + resID).style.width="350px";
     showSlideShow(resID);
}

function theSearch(){
    window.location ='search.aspx?keyword=' + document.getElementById('txtSearch').value + '&ex=x';
}

function ifReturnKey(theCode){
    if(theCode==13){
        theSearch();
    }
}
        
/* VERSION 2.0 UPDATES */

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	 return true					
}
function validEmail(emailID){	
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email");
        emailID.focus();
        return false
    }
    if (echeck(emailID.value)==false){
        alert("Invalid E-Mail Address");
        emailID.focus();        
        return false;
    }
    return true
}
function reportError(request) {
    $F('couponEmailResponse') = "Error Occurred";
}
function inputFocus(inp) {
    if (inp.id == "txtSearch") {
        if (inp.value == "e.g. cheese pizza") {
            inputClear(inp);
        }
    } else if (inp.id == "txtCouponFrom") {
        if (inp.value == "Your e-mail") {
            inputClear(inp);
        }
    } else if (inp.id == "txtCouponTo") {
        if (inp.value == "Friend's e-mail") {
            inputClear(inp);
        }
    }
}
function inputBlur(inp) {
    if (inp.id == "txtSearch") {
        if (inp.value == "") {
            inputUnClear(inp, "e.g. cheese pizza");
        }
    } else if (inp.id == "txtCouponFrom") {
        if (inp.value == "") {
            inputUnClear(inp, "Your e-mail");
        }
    } else if (inp.id == "txtCouponTo") {
        if (inp.value == "") {
            inputUnClear(inp, "Friend's e-mail");
        }
    }
}
function inputClear(inp, num){
    $(inp).val('');
    $(inp).css('color', '#000000');
}
function inputUnClear(inp, value){
    $(inp).val(value);
    $(inp).css('color', 'gray');
}
function emailCoupon(){
    $('#coupEmail').show();
    $('#coupEmalButtons').show();
    $('#couponEmailResponse').hide();
}
function cancelCoupon(){
    $('#coupEmail').fadeOut("fast");
    $('#coupEmalButtons').fadeOut("fast");
}
function sendCoupon(couponid){
    if(validEmail(document.getElementById('txtCouponFrom'))){
        if(validEmail(document.getElementById('txtCouponTo'))){
            var url = 'emailcoupon.aspx';
            $.get(url, { from: $('#txtCouponFrom').val(), to: $('#txtCouponTo').val(), cid: couponid }, function(data){couponResponse(data);});
        }
    }
}
function couponResponse(data){
    alert(data);
    $('#couponEmailResponse').show();
    $('#couponEmailResponse').html(data); 
    cancelCoupon();
}
//***THE READY FUNCTION***
$().ready(function() {
    $('#themodal').jqm({ajax: $(".themodaltrigger").attr("href"), 
        trigger: 'a.themodaltrigger',
        onShow: function(h){h.w.fadeIn("nomal");},
        onHide: function(h){h.o.remove(); h.w.fadeOut("normal");}
    });
    $('#hapmodal1').jqm({ajax: $(".hapmodaltrigger1").attr("href"), 
        trigger: 'a.hapmodaltrigger1',
        onShow: function(h){h.w.fadeIn("nomal");},
        onHide: function(h){h.o.remove(); h.w.fadeOut("normal");}
    });    
    $('#hapmodal2').jqm({ajax: $(".hapmodaltrigger2").attr("href"), 
        trigger: 'a.hapmodaltrigger2',
        onShow: function(h){h.w.fadeIn("nomal");},
        onHide: function(h){h.o.remove(); h.w.fadeOut("normal");}
    });
    var mods
    for (mods in theModals)
    {
        $('#hapmodal2').after("<div class=\"menuModal\" id=\"modMenu" + theModals[mods] + "\">Please wait... <img src=\"graphics/thickboxload.gif\" alt=\"loading\" /></div>");
        $("#modMenu" + theModals[mods]).jqm({ajax: $(".modMenuTrigger" + theModals[mods]).attr("href"), 
            trigger: 'a.modMenuTrigger' + theModals[mods],
            onShow: function(h){h.w.fadeIn("nomal");},
            onHide: function(h){h.o.remove(); h.w.fadeOut("normal");}
        });    
    }
       
    if (document.getElementById('divArticle2') != null)
    {
        $('#divArticle2').css("top", (document.getElementById('trHighAnswers').offsetTop + 30));
    }
    $('#ctl00_imgHead' + 2).fadeTo("slow", 0.4);
    $('#ctl00_imgHead' + 3).fadeTo("slow", 0.4);
    bannerLoop(1);
});
function printCoupon(couponid){
    document.getElementById("iCouponPrint").width = document.getElementById('imgCoupon').width + "px";
    document.getElementById("iCouponPrint").height = document.getElementById('imgCoupon').height + "px";
    frames["iCouponPrint"].location.href = document.getElementById('imgCoupon').src;
    frames["iCouponPrint"].focus();
    setTimeout('frames["iCouponPrint"].print()',10);

    $('#iPrintCount').show();
    $('#iPrintCount').attr("src", "http://idsnews.com/advertising/coupon/printcoupon.aspx?id=" + couponid);
}

var bannerHeadNew = 2;
var bannerHeadOld = 1;
var bannerautoloop = true;
var bannerloopcount = 3;
var theTimeOut;
function bannerLoop(i){
    if(bannerautoloop){
        if (i >= bannerloopcount){
            theTimeOut = setTimeout('bannerLoop(0)', 1000);
            bannerHeadOut();
        }
        else{
            theTimeOut = setTimeout('bannerLoop(' + (i + 1) + ')', 1000);
        }
    }
}
function bannerNum(num){
    if(num == 4){
        num = 1;
    }
    else if(num == 0){
        num = 3;
    }
    return num;
}
function bannerHeadOut(){
    //document.title = "OUT";
    $('#ctl00_imgHead' + bannerHeadOld).fadeTo("slow", 0.4);
    $('#answer' + bannerHeadOld).fadeOut("slow");
    $('#personname' + bannerHeadOld).fadeOut("slow", function(){
        //document.title = "IN";
        $('#ctl00_imgHead' + bannerHeadNew).fadeTo("slow", 1);
        $('#answer' + bannerHeadNew).fadeIn ("slow");
        $('#personname' + bannerHeadNew).fadeIn("slow");
        if(bannerautoloop){   
            bannerHeadOld = bannerHeadNew;
            bannerHeadNew = bannerNum(bannerHeadNew + 1);
        }
    });
}
function overHead(head){
    bannerautoloop = false;
    bannerHeadOld = bannerHeadNew;
    bannerHeadNew = head;
    setTimeout('bannerHeadOut()', 2000);
}

function showAnswer(){
    $('#divHighAnswerLink').hide();
    var browserName=navigator.appName; 
    if (browserName=="Microsoft Internet Explorer")
    {
        $('#iespacebug').show();
    }
    $('#divHighAnswer').slideDown('normal');
}
function hideAnswer(){
    $('#divHighAnswer').slideUp('normal', function(){
        $('#divHighAnswerLink').show();
    });
}