///jquery-1.3.2-vsdoc.js
var ajaxLoaderImage = new Image();
ajaxLoaderImage.src = "images/icons/ajax-loader.gif";

var selectedOptionId = -1;
var loggingInAction = true;
var isLoginWindowOpened = false;
var notLoggedInAction = false;

/* window hander used for holding the reference to the pop up windows */
var win = null;

/* function for opening a new window */
function NewWindow(mypage, myname, w, h, scroll) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition
	+ ',scrollbars=' + scroll + ',toolbar=no,location=no,status=no,menubar=no,resizable=no';
    win = window.open(mypage, myname, settings)
    if (win.window.focus) { win.window.focus(); }
}


function votePoll() {
	var len = document.forms[0].pollOptionId.length;
	for (i = 0; i < len; i++) {
		if (document.forms[0].pollOptionId[i].checked) {
			selectedOptionId = document.forms[0].pollOptionId[i].value;
			break;
		}
	}
	//+ document.getElementById("hdnPollId").value,
	$("#pollOptionsPanel").fadeOut("slow", function() {
	    $.ajax({
	        type: "GET",
	        scriptCharset: "iso-8859-1",
	        url: "ajax/Poll.aspx",
	        data: "selectedAnswer=" + selectedOptionId + "&hdnPollId=68",
	        dataType: "json",
	        success: function showResult(res) {
	            var pollResultsInfo = res
	            var pollAnswers = pollResultsInfo.PollAnswers;
	            if (!pollResultsInfo.LoggedIn) {
	                $("#pollOptionsPanel").show();
	                doLogin(130, 330, true);
	            } else {
	                if (pollResultsInfo.HasVoted) {
	                    if (selectedOptionId != -1) {
	                        $('#AllreadyVotedMessage').show();
	                    }
	                }
	                
	                viewPoll(res)
	            }
	        }
	    });
	});
}
function showPoll() {
    
    $('#pollResultsPanel').show();
    $('#pollResultsPanel').empty();
    $('#ajaxLoadingImageBlue').appendTo("#pollResultsPanel").show();
    var selectedOptionId = -1;
    if ($('#pollOptionsPanel').length) {
        var len = document.forms[0].pollOptionId.length;
        for (i = 0; i < len; i++) {
            if (document.forms[0].pollOptionId[i].checked) {
                selectedOptionId = document.forms[0].pollOptionId[i].value;
                break;
            }
        }
    }
    $('#pollOptionsPanel').hide();
    $.ajax({
        type: "GET",
        scriptCharset: "iso-8859-1",
        url: "ajax/Poll.aspx",
        data: "selectedAnswer=" + selectedOptionId + "&hdnPollId=68",
        dataType: "json",
        success: function showResult(res) {
            var pollResultsInfo = res
            var pollAnswers = pollResultsInfo.PollAnswers;
            if (pollResultsInfo.HasVoted) {
                if (selectedOptionId != -1)
                    $('#AllreadyVotedMessage').show();
                $("#" + pollOptionsPanel).remove();
                $('#ajaxLoadingImageBlue').appendTo("body").hide();
                $('#pollResultsPanel').empty();
                viewPoll(res);
            } else {
                $('#ajaxLoadingImageBlue').appendTo("body").hide();
                $('#pollResultsPanel').empty();
                $('#pollOptionsPanel').show();
            }
        }
    });
    
    
}

function viewPoll(res) {
	var pollResultsInfo = res
	var pollAnswers = pollResultsInfo.PollAnswers;
	
	var pollAnswersHTML = "";
	var bg = "#0066cc";
	for (var i = 0; i < pollAnswers.length; i++) {
		if (pollAnswers[i].AnswerID == selectedOptionId)
			bg = "#FF8000";
		else
			bg = "#0066cc";
		pollAnswersHTML += "<div>" + pollAnswers[i].Answer
				+ "</div><div id='barDiv'><div id='bar" + i
				+ "' style='float:left;width:" + "0" + "%"
				+ ";background-color:" + bg + "'>&nbsp;" + "</div><strong>"
				+ pollAnswers[i].Vote + "%" + "</strong></div>";
		pollAnswersHTML += "<div style='height:3px'>&nbsp;</div>"
	}
	pollAnswersHTML += "<div>Total Votes: <strong>"
			+ pollResultsInfo.TotalVotes + "</strong></div>\n";

	$("#pollResultsPanel").html(pollAnswersHTML);
	$("#pollResultsPanel").fadeIn("slow", function() {
		animateResults();
	});
}
function animateResults() {
	$("#barDiv div").each(function() {
		var percentage = $(this).next().text();
		$(this).css({
			width : "0%"
		}).animate({
			width : percentage
		}, 'slow');
	});
}

function showPollResults() {
    
}


function setupNewsHeadlinesLinksMouseEvents() {
	$('[id*=lnkHeadline_]').each(function(index, element) {
		$(element).mouseover(function() {
			$(this).css("text-decoration", "underline");
		})
		$(element).mouseout(function() {
			$(this).css("text-decoration", "none");
		})
	})
}
function setupLatestPrintEditionTitleLinksMouseEvents() {
    $('[id*=lnkLatestPrintEditionTitle_]').each(function(index, element) {
        $(element).mouseover(function() {
            $(this).css("text-decoration", "underline");
        })
        $(element).mouseout(function() {
            $(this).css("text-decoration", "none");
        })
    })
}
function setupGoodGuysTabEvents() {
	$('#accommodationTab, #attractionTab, #toursTab, #airlineTab').mouseover(function() {
		$(this).css("text-decoration", "underline");
	}).mouseout(function() {
		$(this).css("text-decoration", "none");
	});
	
	$('#attractionTab').click(function() {
		$(this).css({'background':'#457ebc'});
		$('#accommodationPanel, #toursPanel, #airlinePanel').each(function(){
			if($(this).css('display')== 'block' ) {
				$('#' + $(this).attr('val')).css('background', '#90b5de');
				$(this).fadeOut(function(){$('#attractionPanel').fadeIn('slow');});
			}			
		})	
				
	});
	
	$('#accommodationTab').click(function() {
		$(this).css({'background':'#457ebc'});
		$('#attractionPanel, #toursPanel, #airlinePanel').each(function(){
			if($(this).css('display')== 'block' ) {
				$('#' + $(this).attr('val')).css('background', '#90b5de');
				$(this).fadeOut(function(){$('#accommodationPanel').fadeIn('slow');});
			}			
		})	
				
	});
	
	
	$('#toursTab').click(function() {
		$(this).css({'background':'#457ebc'});
		$('#accommodationPanel, #airlinePanel, #attractionPanel').each(function(){
			if($(this).css('display')== 'block' ) {
				$('#' + $(this).attr('val')).css('background', '#90b5de');
				$(this).fadeOut(function(){$('#toursPanel').fadeIn('slow');});
			}			
		})					
	});
	
	
	$('#airlineTab').click(function() {
		$(this).css({'background':'#457ebc'});
		$('#accommodationPanel, #toursPanel, #attractionPanel').each(function(){
			if($(this).css('display')== 'block' ) {
				$('#' + $(this).attr('val')).css('background', '#90b5de');
				$(this).fadeOut(function(){$('#airlinePanel').fadeIn('slow');});
			}			
		})				
	});
}

function setupTabEvents() {
	$('#latestNewsTab').mouseover(function() {
		$(this).css("text-decoration", "underline");
	})
	$('#latestNewsTab').mouseout(function() {
		$(this).css("text-decoration", "none");
	})

	$('#previousNewsTab').mouseover(function() {
		$(this).css("text-decoration", "underline");
	})
	$('#previousNewsTab').mouseout(function() {
		$(this).css("text-decoration", "none");
	})
	$('#latestNewsTab').click(function() {
		$('#NewsCopyPrevious').hide();
		$('#NewsCopy').fadeIn('slow');
		$('#previousNewsTabContainer').css('background', '#90b5de');
		$('#latestNewsTabContainer').css('background', '#457ebc');

	})
	$('#previousNewsTab').click(function() {
		$('#NewsCopyPrevious').fadeIn('slow');
		$('#NewsCopy').hide();
		$('#previousNewsTabContainer').css('background', '#457ebc');
		$('#latestNewsTabContainer').css('background', '#90b5de');
	})

}

function setupSearchTabEvents() {
    $('#newsSearchTab').mouseover(function() {
        $(this).css("text-decoration", "underline");
    })
    $('#newsSearchTab').mouseout(function() {
        $(this).css("text-decoration", "none");
    })

    $('#serviceProviderSearchTab').mouseover(function() {
        $(this).css("text-decoration", "underline");
    })
    $('#serviceProviderSearchTab').mouseout(function() {
        $(this).css("text-decoration", "none");
    })
    $('#newsSearchTab').click(function() {
       
        doSearch($('#searchString').val());
        
        $('#serviceProviderSearchTabContainer').css('background', '#90b5de');
        $('#newsSearchTabContainer').css('background', '#457ebc');

    })
    $('#serviceProviderSearchTab').click(function() {       
        doSPSearch();       
        $('#serviceProviderSearchTabContainer').css('background', '#457ebc');
        $('#newsSearchTabContainer').css('background', '#90b5de');
    })

}

function doSearch(searchString, searchUrl) {
    searchUrl = searchUrl || "ajax/SearchNews.aspx?searchString=" + searchString;
    currentSearch = "NEWS";
    $('#searchResults').empty();
    $('#ajaxLoadingImage').appendTo("#searchResults").show();
    $.ajax({
        type: "GET",
        scriptCharset: "iso-8859-1",
        dataType: "json",
        url: searchUrl,
        success: function showResult(res) {
        var ajaxObject = res;
        setTimeout("$('#searchString').focus();", 500);  
            $('#ajaxLoadingImage').appendTo("body").hide();
            $('#searchResults').empty();
            $('#searchResults').html(ajaxObject.HTML);
            $('[id*=lnkHeadline_]').each(function(index, element) {
                $(element).mouseover(function() {
                    $(this).css("text-decoration", "underline");
                })
                $(element).mouseout(function() {
                    $(this).css("text-decoration", "none");
                })
            })
            $('[id*=lnkSortBy]').each(function(index, element) {
                $(element).mouseover(function() {
                    $(this).css("text-decoration", "underline");
                })
                $(element).mouseout(function() {
                    $(this).css("text-decoration", "none");
                })
            })
            var searchResultInfo = ajaxObject.SearchResultInfo;
            $('#lnkPaging_' + searchResultInfo.PageNo).css('background', '#BB2C2A');
        }
    });
}

function doSPSearch(searchUrl) {
    var searchString = $('#searchString').val();
    currentSearch = "SP";
    searchUrl = searchUrl || "ajax/SPSearch.aspx?searchString=" + searchString;   
    $('#searchResults').empty();
    $('#ajaxLoadingImage').appendTo("#searchResults").show();
	$.ajax({
	type: "GET",
	dataType: "json",
		scriptCharset : "iso-8859-1",
		url: searchUrl,
		success: function showResult(res) {
		setTimeout("$('#searchString').focus();", 500);     
		var ajaxObject = res;    
		$('#ajaxLoadingImage').appendTo("body").hide();
		$('#searchResults').empty();
		$('#searchResults').html(ajaxObject.HTML);
		}
	});
}

function setupSPSearch() {
    $('#spSearchTab').click(function() {
        currentSearch = "SP";
		doSPSearch();
	})
}

function ShowNewsComments(newsId, commentId) {
    $('#pnlNewsComments').empty();
    $('#ajaxLoadingImage').appendTo("#pnlNewsComments").show();
    $.ajax({
        type: "GET",
        scriptCharset: "iso-8859-1",
        url: "ajax/ShowNewsComments.aspx?newsId=" + newsId,
        dataType: "json",
        success: function showResult(res) {
            showthecomment(res,commentId);
        }
    });
}

function showthecomment(res,commentId) {
    $('#ajaxLoadingImage').appendTo("body").hide();
    var showNewsComments = res;    
    $('#pnlNewsComments').html(showNewsComments.HTML);
    $('#pnlNewsComments').fadeIn('slow');
    $.scrollTo('#comment_' + commentId);
    
}
var thewindow = "";
function AjaxWindow() {
    var modalWindowOpened = false;

    this.createWindow = function(title, width, height, top, left) {
        /* create dummy container to hold the modal window so that we can close it ,donno why we need this */
        $('<div/>')
	    .attr("id", "modalWindowHoldindDiv")
	    .appendTo("body");

        /* create the modalWindowcontainer */
        $('<div/>')
	    .attr("id", "modalWindowContainer")
	    .css("background", "#FFFFFF")
	    .css("width", width)
	    .css("height", height)
	    .appendTo("#modalWindowHoldindDiv");

        /*create modalWindowHeaderPanel */
        $('<div/>')
	    .attr("id", "modalWindowHeaderPanel")
	    .css("cursor", "move")
        .css("width", width)
	    .appendTo("#modalWindowContainer");

        //.css("background", "#90b5de")
        //.css("width", width)
        //.css("height", "20px")

        /*create modalWindowTitlePanel */



        $('<div/>')
	    .attr("id", "modalWindowTitlePanel")
	    .css("float", "left")
	    .appendTo("#modalWindowHeaderPanel");

        $('<span/>')
	    .html("&nbsp;")
	    .appendTo("#modalWindowTitlePanel");

        $('<img/>')
	    .attr("id", "modalWindowArrow")
	    .attr("src", "images/ArrowOnBlue_Invert.gif")
	    .attr("alt", "Arrow")
	    .appendTo("#modalWindowTitlePanel");

        $('<span/>')
	    .html("&nbsp;" + title)
	    .appendTo("#modalWindowTitlePanel");


        /*
        .css("float", "left")
        .css("font-weight", "bold")
        .css("color", "#FFFFFF")
        */

        /*create modalWindowClosePanel */
        $('<div/>')
	    .attr("id", "modalWindowClosePanel")
	    .css("float", "right")
	    .css("cursor", "pointer")
	    .css("font-weight", "bold")
	    .css("color", "#FFFFFF")
	    .appendTo("#modalWindowHeaderPanel")


        $('<span/>')
        .html("&nbsp;Close&nbsp;")
        .attr("id", "modalWindowCloseText")
	    .attr("class", "modalclose")
	    .appendTo("#modalWindowClosePanel")
	    .mouseover(function() {
	        $(this).css("text-decoration", "underline");
	    }).mouseout(function() {
	        $(this).css("text-decoration", "none");
	    })

        /*create the close image */
        $('<img/>')
	    .attr("id", "modalWindowCloseImage")
	    .attr("src", "images/close.gif")
	    .attr("class", "modalclose")
	    .attr("alt", "Close")
	    .attr("align", "absmiddle")
	    .css("cursor", "pointer")
	    .appendTo("#modalWindowClosePanel");

        $('<span/>')
	    .html("&nbsp")
	    .appendTo("#modalWindowClosePanel")

        /*create modalWindowBodyPanel */
        $('<div/>')
	    .attr("id", "modalWindowBodyPanel")
	    .attr("width", width)
	    .appendTo("#modalWindowContainer");


        $('#modalWindowContainer').modal({
            containerId: "simplemodal-container",
            position: [top, left],

            onClose: function(dialog) {

                $('#modalWindowHoldindDiv').remove();
                modalWindowOpened = false;
                isLoginWindowOpened = false;
                $.modal.close();
                if (isNewsComment) {
                    isNewsComment = false;
                    ShowNewsComments(currentNewsCommentId, currentCommentId);
                }
            }
        }).init();
        $("#simplemodal-container").draggable();



    }
    this.closeWindow = function() {
        $.modal.close(true);
        modalWindowOpened = false;
        isFirstRequest = true;
        isLoginWindowOpened = false;
    }
    this.makeRequest = function(ajaxURL, formData, successFunction) {
        var requestType = "GET";
        for (var i in formData) {
            if (formData[i] != undefined) {
                requestType = "POST";
                break;
            }
        }
        //fix undefined values so that they become ''
        for (var i in formData) {
            if (formData[i] == undefined) {
                formData[i] = '';
            }
        }

        $('#modalWindowBodyPanel').empty();
        showAjaxLoadIndicator();
        $.ajax({
            type: requestType,
            data: formData,
            scriptCharset: "iso-8859-1",
            url: ajaxURL,
            dataType: "json",
            success: function showResult(res) {
            hideAjaxLoadIndicator();
            var ajaxObject = res;
            if ((!ajaxObject.LoggedIn) && (!isLoginWindowOpened)) {
                    $('#modalWindowHoldindDiv').remove();                    
                    $.modal.close();                    
                    doLogin(130, 330,true);                    
                } else {                  
                    $('#modalWindowBodyPanel').empty();
                    $('#modalWindowBodyPanel').html(ajaxObject.HTML);
                    successFunction.success(ajaxObject);
                }
            }
        })
    }

    function showAjaxLoadIndicator() {
        $('#ajaxLoadingImage').appendTo("#modalWindowBodyPanel").show();
    }
    function hideAjaxLoadIndicator() {
        $('#ajaxLoadingImage').appendTo("body").hide();
    }

}

function AddPollComment() {
    loggingInAction = true;
    var pollCommentWindow = new AjaxWindow();
    pollCommentWindow.createWindow("Poll Comment", "600px", "500px", 150, 300);
    
    var getFormData = function() {
        return {
            postComment: $('#postComment').val(),
            hdnpollId: $('#hdnpollId').val(),
            txtMessageHeading: $('#txtMessageHeading').val(),
            txtMessage: $('#txtMessage').val(),
            chbAnonymous: ($('#chbAnonymous').is(':checked')) ? 1 : 0,
            txtSecurityCode: $('#txtSecurityCode').val()
        }

    }
    var ajaxURL = "ajax/CommentPoll.aspx";
    var successFunction = { success: function(ajaxPollComment) {
        if (ajaxPollComment.Success == "true") {
            $('#btnModalClose').click(function() {
                pollCommentWindow.closeWindow();
            })
        } else {       
            setTimeout( "$('#txtMessageHeading').focus();",500);        
            //document.getElementById("txtMessageHeading").focus();
            $('#btnModalSend').click(function() {
                pollCommentWindow.makeRequest(ajaxURL, getFormData(), successFunction);
            })
        }

    }
    }
    pollCommentWindow.makeRequest(ajaxURL, getFormData(), successFunction);

}
var isNewsComment = false;
var currentNewsCommentId = "";
var currentCommentId = "";
function AddNewsComment(newsId) {
    isNewsComment = true;
    currentNewsCommentId = newsId;
    var newsCommentWindow = new AjaxWindow();
    newsCommentWindow.createWindow("News Comment", "600px", "500px", 150, 300 );
   
    var getFormData = function() {
        return {
            hdnPostComment: $('#hdnPostComment').val(),
            hdnNewsId: newsId,
            txtMessageHeading: $('#txtMessageHeading').val(),
            txtMessage: $('#txtMessage').val(),
            chbAnonymous: ($('#chbAnonymous').is(':checked')) ? 1 : 0,
            txtSecurityCode: $('#txtSecurityCode').val()
        }

    }
    var ajaxURL = "ajax/NewsComment.aspx";
    var successFunction = { success: function(ajaxNewsComment) {

        if (ajaxNewsComment.Success == "true") {
            currentCommentId = ajaxNewsComment.CommentId;

            $('#modalWindowCloseText').click(function() {
                newsCommentWindow.closeWindow();
                ShowNewsComments(newsId, ajaxNewsComment.CommentId);
            });
            $('#modalWindowCloseImage').click(function() {
                newsCommentWindow.closeWindow();
                ShowNewsComments(newsId, ajaxNewsComment.CommentId);
            })

        } else {
            setTimeout("$('#txtMessageHeading').focus();", 500);
            $('#btnModalSend').click(function() {
                newsCommentWindow.makeRequest(ajaxURL, getFormData(), successFunction);
            })
        }
    }
    }
    newsCommentWindow.makeRequest(ajaxURL, getFormData(), successFunction);

}

function doLogin(top, left, isNotLoggedInAction, isNotLoggedInWithRegistrationForm) {
    isLoginWindowOpened = true;
    var top = top || 130 ;
    var left = left || 330;
    
    var isNotLoggedInAction = isNotLoggedInAction || false;
    var isNotLoggedInWithRegistrationForm = isNotLoggedInWithRegistrationForm || false
    
    var loginWindow = new AjaxWindow();
    loginWindow.createWindow("Login", "400px", "200px", top, left);

    var getFormData = function() {
        return {}
    }
    var ajaxURL = "ajax/Login.aspx?txtEmail=" + $('#txtInitialEmail').val()
    var successFunction = { success: function(ajaxLogin) {
        if (ajaxLogin.Success == "true") {
            $('#' + pnlLogIn).remove();
            var selectedOptionId = -1;

            if ($('#pollOptionsPanel').length) {
                var len = document.forms[0].pollOptionId.length;
                for (i = 0; i < len; i++) {
                    if (document.forms[0].pollOptionId[i].checked) {
                        selectedOptionId = document.forms[0].pollOptionId[i].value;
                        break;
                    }
                }
            }
            if (selectedOptionId != -1)
                votePoll();
            else
                showPoll();
            $("#headlineScrollup").show();
            $("#pnlNotLogedInTopSiteMessage").hide();
            if (typeof (pnlYouAreNotLoggedIn) != "undefined")
                $('#' + pnlYouAreNotLoggedIn).remove();
            $('#' + pnlLogedIn).show();
            $('#' + lnkRegisterHere).empty();
            $('#' + lnkRegisterHere).html("Logout");
            $('#' + lnkRegisterHere).attr("href", "Logout.aspx");
            $('#loginName').html(ajaxLogin.LoginDetails.Firstname + " " + ajaxLogin.LoginDetails.Surname);

            loginWindow.closeWindow();
            if (fromURL != undefined) {
                window.location = fromURL;
            }

        } else {
            setTimeout("$('#txtEmail').focus();", 1000);
            $('#closeWindowHere').click(function() {
                isLoginWindowOpened = false;
                loginWindow.closeWindow();
            }).mouseover(function() {
                $(this).css("color", "#FF0000");
            }).mouseout(function() {
                $(this).css("color", "#0080FF");
            })

            //$('#txtEmail').focus();
            $('#txtEmail').keydown(function(event) {
                switch (event.keyCode) {
                    case 13: $('#txtInitialEmail').val($('#txtEmail').val());
                        ajaxURL = "ajax/Login.aspx?txtEmail=" + $('#txtInitialEmail').val();
                        loginWindow.makeRequest(ajaxURL, getFormData(), successFunction);
                }
            });
            $('#btnModalLogin').click(function() {
                $('#txtInitialEmail').val($('#txtEmail').val());
                ajaxURL = "ajax/Login.aspx?txtEmail=" + $('#txtInitialEmail').val();
                loginWindow.makeRequest(ajaxURL, getFormData(), successFunction);
            })

        }
    }
    }
    if (isNotLoggedInAction) {
        loginWindow.makeRequest(ajaxURL + "&isNotLoggedInAction=true", getFormData(), successFunction);
} else if (isNotLoggedInWithRegistrationForm)
    loginWindow.makeRequest(ajaxURL + "&isNotLoggedInWithRegistrationForm=true", getFormData(), successFunction);    
  else
    loginWindow.makeRequest(ajaxURL, getFormData(), successFunction);  
}




function SendToFriend(newsId) {
    var sendToFriendWindow = new AjaxWindow();
    sendToFriendWindow.createWindow("Send to friend", "600px", "500px", 150, 300);

    var getFormData = function() {
        return {
            sendToFriend: $('#sendToFriend').val(),
            hdnNewsId: newsId,
            txtEmailAddress: $('#txtEmailAddress').val(),
            txtSenderName: $('#txtSenderName').val(),
            txtSenderEmail: $('#txtSenderEmail').val(),
            txtMessage: $('#txtMessage').val(),
            txtSecurityCode: $('#txtSecurityCode').val()
        }

    }
    var ajaxURL = "ajax/SendToFriend.aspx";
    var successFunction = { success: function(ajaxSendToFriend) {
        if (ajaxSendToFriend.Success == "true") {
            $('#btnModalClose').click(function() {
                sendToFriendWindow.closeWindow();
            })
        } else {
        setTimeout("$('#txtEmailAddress').focus();", 500);
            $('#btnModalSend').click(function() {
                sendToFriendWindow.makeRequest(ajaxURL, getFormData(), successFunction);
            })
        }
    }
    }
    sendToFriendWindow.makeRequest(ajaxURL, getFormData(), successFunction);

}
var isloggedInAction;
var fromURL = '';
var currentSearch = "NEWS";
$(document).ready(function() {
    setupGoodGuysTabEvents();
    setupNewsHeadlinesLinksMouseEvents();
    setupLatestPrintEditionTitleLinksMouseEvents();
    setupTabEvents();
    var searchString = $.jqURL.get('searchString')
    var newsId = $.jqURL.get('newsId')
    
    isloggedInAction = $.jqURL.get('loginaction');
    fromURL = $.jqURL.get('from');

    if (isloggedInAction == 'true') {
        var referrer = document.referrer;
        if (referrer.indexOf("Register.aspx") == -1)
            doLogin(130, 330, false, true);
    }
    if (searchString != "") {
        $('#searchString').val(searchString);
        setupSearchTabEvents();
        setupSPSearch();
        // doSearch(searchString);
    }
    var newsId = $.jqURL.get('newsId');

    $('#btnSendToFriend').click(function() {
        SendToFriend(newsId);
    }).mouseover(function() {
        $(this).css("color", "#FF0000");
    }).mouseout(function() {
        $(this).css("color", "#000000");
    })



    $('#btnPrintNews').click(function() {
        NewWindow('print/NewsStory.aspx?newsId=' + newsId, 'PrintStory', '500', '500', 'yes');
    }).mouseover(function() {
        $(this).css("color", "#FF0000");
    }).mouseout(function() {
        $(this).css("color", "#000000");
    })

    $('#btnAddNewsComment').click(function() {
        AddNewsComment(newsId);
    }).mouseover(function() {
        $(this).css("color", "#FF0000");
    }).mouseout(function() {
        $(this).css("color", "#000000");
    })

    $('#btnAddNewsComment2').click(function() {
        AddNewsComment(newsId);
    }).mouseover(function() {
        $(this).css("color", "#FF0000");
    }).mouseout(function() {
        $(this).css("color", "#000000");
    })

    $('#btnLogin').click(function() {
        doLogin();
    })
    $('#imgYouAreNotloggedIn').click(function() {
        doLogin(130, 330, true);
    })

    $('#btnPollComment').click(function() {
        AddPollComment();
    }).mouseover(function() {
        $(this).css("color", "#FF0000");
    }).mouseout(function() {
        $(this).css("color", "#000000");
    })

    $('#txtInitialEmail').keydown(function(event) {
        switch (event.keyCode) {
            case 13: doLogin();
        }
    }).focus();

    $('#btnHomeSearch').click(function() {
        self.location = 'SiteSearch.aspx?searchString=' + $('#searchString').val();
    })
    $('#btnHomeSearch').keydown(function(event) {
        switch (event.keyCode) {
            case 13: self.location = 'SiteSearch.aspx?searchString=' + $('#searchString').val();
        }
    });

    $('#btnSearch').click(function() {
        if (getCurrentSearch() == "NEWS")
            doSearch($('#searchString').val());
        else
            doSPSearch();
    })
    function getCurrentSearch() {
        return currentSearch;
    }

    $('#searchString').keydown(function(event) {
        switch (event.keyCode) {
            case 13: if ($('#btnHomeSearch').length) {
                    self.location = 'SiteSearch.aspx?searchString=' + $('#searchString').val();
                } else {
                    if (currentSearch == "NEWS")
                        doSearch($('#searchString').val());
                    else
                        doSPSearch();
                }
        }
    });
    if ($('#txtInitialEmail').is(':hidden')) {
        $('#searchString').focus();
    }

    if ($('#' + hdnShowPoll).length) {
        hdnShowPoll = $('#' + hdnShowPoll).val();
        if (hdnShowPoll == "true")
            showPoll();
    }


    var headline_count;
    var headline_interval;
    var old_headline = 0;
    var current_headline = 0;

    $(document).ready(function() {
        headline_count = $("div.headlineScroller").size();
        $("div.headlineScroller:eq(" + current_headline + ")").css('top', '5px');

        headline_interval = setInterval(headline_rotate, 4000); //time in milliseconds
        $('#headlineScrollup').hover(function() {
            //setTimeout("", 4000);  
            clearInterval(headline_interval);
        }, function() {
            headline_interval = setInterval(headline_rotate, 4000); //time in milliseconds
            headline_rotate();
        });
    });

    function headline_rotate() {
        current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
        $("div.headlineScroller:eq(" + old_headline + ")").animate({ top: -205 }, "slow", function() {
            $(this).css('top', '210px');
        });
        $("div.headlineScroller:eq(" + current_headline + ")").show().animate({ top: 5 }, "slow");
        old_headline = current_headline;
    }

    if ($("#" + hdnJavascriptLoginStatus).val() == "true") {
        $("#headlineScrollup").show();
        $("#pnlNotLogedInTopSiteMessage").hide();
    }

    //lets do the menu stuff
    var activeMenuItemId;
    var currentLocation = location.href;
    currentLocation = currentLocation.toLocaleLowerCase();
    $('[id*=lnkMenu]').each(function() {
        var currentHref = $(this).attr("href");
        currentHref = currentHref.toLocaleLowerCase();
        if (currentLocation.indexOf(currentHref) != -1) {
            activeMenuItemId = $(this).attr("id");
            $(this).css("background-color", "#bb2c2a");
        }
    })
    $('[id*=lnkSortBy]').each(function(index, element) {
        $(element).mouseover(function() {
            $(this).css("text-decoration", "underline");
        })
        $(element).mouseout(function() {
            $(this).css("text-decoration", "none");
        })
    })
    $('[id*=lnkMenu]').click(function() {
        $("#" + activeMenuItemId).css("background-color", "#457ebc");
        $(this).css("background-color", "#bb2c2a");
    })
    .mouseover(function() {
        if ($(this).attr("id") != activeMenuItemId)
            $(this).css("background-color", "#90b5de");
    }).mouseout(function() {
        if ($(this).attr("id") != activeMenuItemId)
            $(this).css("background-color", "#457ebc");
    })



    


})
