﻿$(function() {
    Navigation();
    $("#keywords").val(decodeURI(getUrlPara("keyword")));
    var cookie = GetCookie("UserLogin"); 
    if (cookie != null && cookie.value != "") {
        $("#loginlink").attr("href", "javascript:LoginOut()").html("LogOut");
    }
    $("a[tag]").hover(function() {
        $(this).addClass("yiny");
        var tag = $(this).attr("tag");
        var obj = $("div[class=nav-help][tag=" + tag + "]");
        $(obj).show();
        $(obj).css("left", $(this).position().left);
    }, function() {
        var tag = $(this).attr("tag");
        var obj = $("div[class=nav-help][tag=" + tag + "]");
        $(obj).hide(); $(this).removeClass("yiny");
    });
    $("div[class=nav-help][tag]").hover(function() {
        var tag = $(this).attr("tag");
        $("a[tag=" + tag + "]").addClass("yiny");
        $(this).show();
    }, function() {
        var tag = $(this).attr("tag");
        $("a[tag=" + tag + "]").removeClass("yiny");
        $(this).hide();
    });
});

function Navigation() {
    var left = "";
    $("ul[id=navTop]>li:eq(0)").hover(function() {        
        left = $("ul[id=navTop]").parent().parent().position().left; $(this).children("ul").show(); $(this).children("ul").css("left", $(this).position().left - left - 12);
    },
    function() { $(this).children("ul").hide(); });
    $("ul[id=navTop]>li:gt(0)").each(function(i) {
    var top = $(this).position().top;
    left = $("ul[id=navTop]").parent().parent().position().left;
        $(this).hover(function() { $(this).children("ul").show(); $(this).children("ul").css("left", $(this).position().left - left - 2); }, function() { $(this).children("ul").hide(); });
    });
}

function ValidEmail(email) {
    var reg = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
    if (reg.test(email))
        return true;
    else
        return false;
}

function PageJump() {    
    location.href = $("#pagesort").val();
}

function SearchPro() {
    var keyword = $("#keywords").val();
    if (keyword == "") {
        alert("At least one of the fields in the search form must be entered.");return;
    }
    location.href = "s-" + encodeURI(keyword)+".htm";
}

function getUrlPara(paraName) {
    var sUrl = location.href;
    var sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)"
    var re = new RegExp(sReg, "gi");
    if (!re.exec(sUrl)) {
        return "";
    }
    else {
        return RegExp.$1.split('#')[0];
    }
}

function ShowDiv(id) {
    $("#" + id).show();
}

function CloaseDiv(id) {
    $("#" + id).hide();
}

function LoginOut() {
    var exp = new Date();
    exp.setTime(exp.getTime() - 24 * 60 * 60 * 1000);
    document.cookie = "UserLogin='';expires=" + exp.toGMTString() + ";path=/";
    location.href = "Index.html";
}
