﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
///////////////////////////////////////
// Gasta.js - created 1st April 2009
///////////////////////////////////////

//Home Page Tabs

function switch_tabs(id) {
    $(".tab_content").hide();

    $("#tab_content" + id).show();

    return false;

}


//Client Side Search

function do_search(is_home) {

    var s = $("#search_type").val();
    var t = URLEncode(remove_reserved($("#txt_search").val())); //remove reserved chars

      
    switch (s) {
        case ("Web"):
            if (is_home==true) {
                window.location = "/";
            }
            else {
                window.location = "/Search/" + t;
            }
            return false;
            break;
        case ("Image"):
            window.location = "/Image/" + t;
            return false;
            break;
        case ("Video"):
            window.location = "/Video/" + t;
            return false;
            break;
        case ("News"):
            window.location = "/News/" + t;
            return false;
            break;
        case ("Shopping"):
            window.location = "/Shopping/" + t;
            return false;
            break;
        default:
            window.location = "/Search/" + t;
            return false;
            break;
    }


    return false;

}


function tab_search(search_type, is_home) {
    var s = $("#search_type").val(search_type);
    //var t = $("#txt_search").val();


    do_search(is_home);


    return true;
    
}

function check_enter(myfield, e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        do_search();
        return false;
    }
}


//Search Navigation
function format_search_header() {

    var s = $("#search_type").val();
    //set selected tab

    var t = $("#s_" + s).attr({ "class": "selected" })

    var test = $("#test");
   
    
} 

//Social Bookmark - Twitter, Facebook -MVC will not accept URL encoded / : = or ?
function bookmark(b_type, id) 
{
    //var st = URLEncode(format_url($("#st" + id).html()));
    //var su = URLEncode(format_url($("#su" + id).html()));

    var st = $("#st" + id).html();
    var su = $("#su" + id).html();

    //var newWindow = window.open("/Bookmark/" + b_type + "/" + (su) + "/" + (st));
    var b_client    = $("#b_client").attr({ value: b_type });
    var b_url = $("#b_url").attr({ value: su });
    var b_message = $("#b_message").attr({ value: st });

    $("#form_bookmark").submit();

    return false;


}

function format_url(str) { // reservered as MVC URL don't like encoded URL

    str = str.replace(new RegExp("http://","g"), "---http---");
    str = str.replace(new RegExp("https://", "g"), "---https---");

    str = str.replace(new RegExp("HTTP://", "g"), "---http---");
    str = str.replace(new RegExp("HTTPS://", "g"), "---https---");

    str = str.replace(new RegExp('(\\?)', "g"), "---q---");
    str = str.replace(new RegExp('=', "g"), "---e---");

    str = str.replace(new RegExp("/","g"), "---sh---");

    return str;
}

//Play video
function play_vid(vid) {    
    var vid_elem = $("#vid_" + vid);
    vid_elem.html('<div id="flashcontent" style="text-align: center; clear:both">' +
    '<div id="popupControls">' +
					'<img src="/assets/images/close.gif" onclick="close_list_video(\'' + vid + '\');" id="popCloseBox" />' +
				'</div>' +
'<embed id="movie_player" ' + detect_screen_width() + ' type="application/x-shockwave-flash" src="http://youtube.com/v/' + vid + '".swf" name="movie_player" bgcolor="#FFFFFF" quality="high"/>' +
'</div>');
    return false;

}

function close_list_video(vid) {
    var vid_elem = $("#vid_" + vid);
    vid_elem.html("");
}


