﻿/// <reference path="jquery/jquery-1.3.2-vsdoc.js" />

//HPSearchCategories

$(document).ready(function(){ 

    var PagePath = window.location.toString();
    
    if(!PagePath.match('aspx') || PagePath.match('default.aspx'))
    {
        BindMainCategoriesList();
    }
    //GetHPSelectedTab(FirstTab);
    BindPromotionsHoverEvent();
}); 

function ddd()
{
    $("#TopNavBar1_topMenuDiv").hover(function(){
     $("#HPSearchCategoriesMainContainer select").css({ visibility: "hidden" });
   },function(){
    $(".HPSearchCategoriesSelect select").css({ visibility: "visible" });
    });
}

function BindMainCategoriesList()
{
    $.post("/Handlers/GetCategories.ashx",
         {SelectedIndex: $("#sWorldsCategories").val(), type: "MainCategories"},
         function(data){
         $("#dvSearchMainCategoriesContainer").empty();
         $("#dvSearchMainCategoriesContainer").append(data);
//         if($("#sWorldsCategories").val()==-1)
//         {
//             $("#dvSearchSubCategoriesContainer").empty();
//             $("#dvSearchSubCategoriesContainer").append(
//                 "<select id='sSubCategories' class='HPSearchCategoriesSelect'" + 
//                 "<option value='-1' selected='selected'>--בחר מסלול לימודים--</option></select>");
//         }
    });
}
function BindSubCategoriesList()
{
    $.post("/Handlers/GetCategories.ashx",
         {SelectedIndex: $("#sMainCategories").val(), type: "SubCategories"},
         function(data){
         $("#dvSearchSubCategoriesContainer").empty();
         $("#dvSearchSubCategoriesContainer").append(data);
    });
}
function SubmitSearchCategories()
{
//    document.getElementById('frmHPMain').submit();
    var CategoryID=-1;
    var ToolTip = $(".HPSearchCategoriesInsideLeft .ToolTip");
    
//    if($("#sWorldsCategories").val()==257 || $("#sWorldsCategories").val()==254 || $("#sWorldsCategories").val()==308 || $("#sWorldsCategories").val()==643 || $("#sWorldsCategories").val()==699 || $("#sWorldsCategories").val()==710)
        CategoryID = $("#sMainCategories").val();
//    else
//        CategoryID = $("#sSubCategories").val();
        
    if(CategoryID!=-1 && CategoryID!=null)
    {
        ToolTip.removeClass("WithBG").removeClass("Yellow2");

        $("#sWorldsCategories").val(-1);
        window.open("/gui/index/searchresults.aspx?" + 
        "CategoryID=" + CategoryID
        + "&AreaID=" + ($('#sAreas').val() != -1 ? $('#sAreas').val() : "") 
        + "&DiplomaTypeID=", '_top');
    }
    else
    {        
        if($("#sWorldsCategories").val()==-1)
        {
            ToolTip.text($("#spnWorldsCategories").text());
            ToolTip.addClass("WithBG").addClass("Yellow2");
        }
        else if($("#sMainCategories").val()==-1)
        {
            ToolTip.text($("#spnMainCategories").text());
            ToolTip.addClass("WithBG").addClass("Yellow2");
        }
//        else
//        {
//            ToolTip.text($("#spnSubCategories").text());
//            ToolTip.addClass("WithBG").addClass("Yellow2");
//        }
    }
}

//HPUsefullLinks
function GetHPSelectedTab(id)
{
    $("#TabsAjaxIndicator").css({ display: "block" });
    $(".SelectedTab").removeClass("SelectedTab");
    $("#"+id).addClass("SelectedTab");
    id= id.replace('HPUsefullLinksTab','');
    
    $.post("/Handlers/GetHPSelectedTab.ashx",
         {SelectedIndex: id},
         function(data){
             $("#dvSelectedTabContent").empty();
             $("#dvSelectedTabContent").append(data);
             $("#TabsAjaxIndicator").css({ display: "none" });
    });
}

//HPMostWanted
function ToggleMostWantedItemImage(img,e,container, color, status)
{
    if(status)
    {
        container.style.color = color;
        if(e=='over')
        {
            var srcOn = img.src.replace('.jpg','_on.jpg');
            img.src = srcOn;
        }
        else
        {
            var srcOff = img.src.replace('_on.jpg','.jpg');
            img.src = srcOff
        }
    }
}

function RemoveSelected(a)
{
    //a.className = "Item"
}

function ChangeMainImage(item)
{
    var MainImage = $('.MainImage .Middle .Info');
    var item = $(item);
    
    if(jQuery(".Image",MainImage).attr('src')!=jQuery(".Image img",item).attr('src'))
    {
        //jQuery(".Image",MainImage).attr('src',jQuery(".Image img",item).attr('src'));
        jQuery(".Image",MainImage).fadeOut(1, function() {
                $(this).attr({ src: jQuery(".Image img",item).attr('src') }).fadeIn(1);
        });
        jQuery(".Title",MainImage).fadeOut(1, function() {
                $(this).text(jQuery(".Description .SubTitle",item).text()).fadeIn(1);
        });
        jQuery(".SubTitle",MainImage).fadeOut(1, function() {
                $(this).text(jQuery(".Description .Title",item).text()).fadeIn(1);
        });
        MainImage.attr('href',jQuery(".Image",item).attr('href'));
    //    jQuery(".Title",MainImage).text(jQuery(".Description .SubTitle",item).text());
    //    jQuery(".SubTitle",MainImage).text(jQuery(".Description .Title",item).text());
    }
}

function BindPromotionsHoverEvent()
{
    $(".HPPromotions .RightSection .Items .Item").hover(
      function () {
         ChangeMainImage(this);
      });
}


//Mail Account

function ValidateMailForm() {
	if($('#mailUsername').val().length < 2){
		$('#mailUsername').focus();
		return false ;
	}
	if($('#mailPassword').val().length < 2){
		$('#mailPassword').focus();
		return false ;
	}
    return true ;
}

function goToMail(mailType){
    var user = $('#mailUsername').val();
    var pass = $('#mailPassword').val();
	switch(mailType) {
	    case "gmail":
		    $('#frmGmail :input[name=\'Email\']').val(user);
		    $('#frmGmail :input[name=\'Passwd\']').val(pass);
		    gmailCK(); 
		    break;
	    case "walla":
		    $('#frmWalla :input[name=\'username\']').val(user);
		    $('#frmWalla :input[name=\'password\']').val(pass);
        	$('#frmWalla').submit();
		    break;
	    case "yahoo":
		    $('#frmYahoo :input[name=\'login\']').val(user);
		    $('#frmYahoo :input[name=\'passwd\']').val(pass);
        	$('#frmYahoo').submit();
		     break;
	    case "hotmail":
		    $('#frmHotmail :input[name=\'login\']').val(user);
		    $('#frmHotmail :input[name=\'passwd\']').val(pass);
        	$('#frmHotmail').submit();
		     break;
    }
}
function gmailCK() {
	var start_time = (new Date()).getTime();
    var now = (new Date()).getTime();
	var login_box_time = (new Date()).getTime();
    var cookie = "T" + start_time + "/" + login_box_time + "/" + now;
    document.cookie = "GMAIL_LOGIN=" + cookie;
	$('#frmGmail').submit();
}
