// JavaScript Document

if(header_server_host=='music.bloson.com') {
var VIDEO_SEARCH_ROOT_PATH = MUSIC_DOMAIN;
}else if(header_server_host=='video.bloson.com') {
var VIDEO_SEARCH_ROOT_PATH = VIDEO_DOMAIN;
}else if(header_server_host=='shopping.bloson.com') {
var VIDEO_SEARCH_ROOT_PATH = SHOPPING_DOMAIN;
}else if(header_server_host=='www.bloson.com') {
var VIDEO_SEARCH_ROOT_PATH = BASEPATH;
}



var VIDEO_ROOT_PATH = VIDEO_DOMAIN;

jquery(function() 
{
	jquery("#search_videos").autocomplete(VIDEO_SEARCH_ROOT_PATH+"action_autosearch.php", 
	{
		width: 260,
		selectFirst: false, cacheLength:0
	});
	
});


function go_autosearch()
{

	var regExp = /\s/g;
	var str = jquery("#search_videos").val();
	var PageName = "CommonFunction";
	var Submit = "find_title_type";
	var resultString = str.replace(regExp,'+');
	resultString = convertValues(resultString);

	jquery.post(VIDEO_SEARCH_ROOT_PATH+"action_autosearch.php",{Submit:Submit, title: str},function(getResult){

		if(trim(getResult) == "tv"){
			document.frm_video_search.action = VIDEO_ROOT_PATH+"tv/"+resultString+"/";
			document.frm_video_search.submit();
		}
		else {
			document.frm_video_search.action = VIDEO_ROOT_PATH+"movies/"+resultString+"/1298439374/";
			document.frm_video_search.submit();
		}
	});

	/*
	 if(jquery("#video_search_type").val() == "tv_shows") 
	 {
		 document.frm_video_search.action = VIDEO_ROOT_PATH+"tv/"+resultString;
		 document.frm_video_search.submit();
	 }
	 else if(jquery("#video_search_type").val() == "movie") 
	 {
		 document.frm_video_search.action = VIDEO_ROOT_PATH+"movies/"+resultString+"/123";
		 document.frm_video_search.submit();
	 }	
	 */
}

function go_videosearch()
{
	if((jquery("#search_videos").val()).length < 1)
	{
		jquery("#errMsg").fadeIn(3000);
		jquery("#errtxt").text('Please enter Keyword');
		jquery("#errtxt").show();
		jquery("#search_videos").focus();
		jquery("#errMsg").fadeOut(3000);
	}
	else
	{
		var srch = jquery("#search_videos").val().toLowerCase();
		
		/*if(jquery("#video_search_type").val() == "tv_shows") 
		{
			search_tvshow(srch);
		}
		else if(jquery("#video_search_type").val() == "movie") 
		{
			get_movieid(srch);
		}
		else if(jquery("#video_search_type").val() == "all") 
		{
			var resultString = str.replace(regExp, '+');
			var searchtype = jquery('#video_search_type').val();
			document.frm_video_search.action = VIDEO_ROOT_PATH+"search_videos/"+searchtype+"/"+resultString;
			document.frm_video_search.submit();
			
		}*/
		var regExp = /\s/g;
		var resultString = srch.replace(regExp, '+');
		resultString = convertValues(resultString);
		document.frm_video_search.action =  VIDEO_ROOT_PATH+"search_videos/"+resultString+"/";
		document.frm_video_search.submit();
	}
}

function search_tvshow(str)
{
	var regExp = /\s/g;
	var resultString = str.replace(regExp, '+');
	resultString = convertValues(resultString);
	var searchtype = jquery('#video_search_type').val();

	document.frm_video_search.method = "post";
	document.frm_video_search.action = VIDEO_ROOT_PATH+"search_videos/"+searchtype+"/"+resultString+"/";
	document.frm_video_search.submit();
	
}

function convertValues(resultString)
{
	resultString = resultString.replace("#","hashstr");	
	resultString = resultString.replace("&","andstr");
	resultString = resultString.replace("/","slashstr");
	resultString = resultString.replace("?","%3F");
	resultString = resultString.replace("%","%25");	
	return resultString;
}

function get_movieid(movie_title)
{
	var regExp = /\s/g;
	var resultString = movie_title.replace(regExp, '+');
	resultString = convertValues(resultString);
	var searchtype = jquery('#video_search_type').val();
	
	document.frm_video_search.method = "post";	
	document.frm_video_search.action = VIDEO_ROOT_PATH+"search_videos/"+searchtype+"/"+resultString+"/";
	document.frm_video_search.submit();
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function set_timezone()
{
	var now = new Date();
	var user_timeoffset = now.getTimezoneOffset();
	jquery.post(VIDEO_ROOT_PATH+"application/action.php",{Submit: "set_timezone", user_timeoffset: user_timeoffset});
}
function tab1()
{
jquery('#ltab1').removeClass('left_tab_norm');
jquery('#ltab1').addClass('left_tab_norm_sel');

jquery('#ltab2').removeClass('left_tab_norm1_sel');
jquery('#ltab2').addClass('left_tab_norm1');

jquery('#ltab3').removeClass('left_tab_norm2_sel');
jquery('#ltab3').addClass('left_tab_norm2');

jquery('#ltab4').removeClass('left_tab_norm3_sel');
jquery('#ltab4').addClass('left_tab_norm3');

jquery('.tab_cont1').show();
jquery('.tab_cont2').hide();
jquery('.tab_cont3').hide();
jquery('.tab_cont4').hide();
}
function tab2()
{
jquery('#ltab1').removeClass('left_tab_norm_sel');
jquery('#ltab1').addClass('left_tab_norm');

jquery('#ltab2').removeClass('left_tab_norm1');
jquery('#ltab2').addClass('left_tab_norm1_sel');

jquery('#ltab3').removeClass('left_tab_norm2_sel');
jquery('#ltab3').addClass('left_tab_norm2');

jquery('#ltab4').removeClass('left_tab_norm3_sel');
jquery('#ltab4').addClass('left_tab_norm3');

jquery('.tab_cont1').hide();
jquery('.tab_cont3').hide();
jquery('.tab_cont4').hide();

jquery('.tab_cont2').show();
}
function tab3()
{
jquery('#ltab1').removeClass('left_tab_norm_sel');
jquery('#ltab1').addClass('left_tab_norm');

jquery('#ltab2').removeClass('left_tab_norm1_sel');
jquery('#ltab2').addClass('left_tab_norm1');

jquery('#ltab3').removeClass('left_tab_norm2');
jquery('#ltab3').addClass('left_tab_norm2_sel');
jquery('.tab_cont1').hide();
jquery('.tab_cont2').hide();
jquery('.tab_cont4').hide();
jquery('.tab_cont3').show();

jquery('#ltab4').removeClass('left_tab_norm3_sel');
jquery('#ltab4').addClass('left_tab_norm3');
}

function tab4()
{
jquery('#ltab1').removeClass('left_tab_norm_sel');
jquery('#ltab1').addClass('left_tab_norm');

jquery('#ltab2').removeClass('left_tab_norm1_sel');
jquery('#ltab2').addClass('left_tab_norm1');

jquery('#ltab3').removeClass('left_tab_norm2_sel');
jquery('#ltab3').addClass('left_tab_norm2');

jquery('#ltab4').removeClass('left_tab_norm3');
jquery('#ltab4').addClass('left_tab_norm3_sel');
jquery('.tab_cont1').hide();
jquery('.tab_cont2').hide();
jquery('.tab_cont3').hide();
jquery('.tab_cont4').show();
}

function checkkeyword()
{
	if((jquery("#vq").val()).length < 1)
	{
		jquery("#errMsg").fadeIn(3000);
		jquery("#errtxt").text('Please enter Keyword');
		jquery("#errtxt").show();
		jquery("#vq").focus();
		jquery("#errMsg").fadeOut(3000);
	}
	else
	{
		
		var regExp = /\s/g;
		var str = jquery("#vq").val();
		var resultString = str.replace(regExp, '+');
		var searchtype = jquery('#video_search_type').val();
		document.form_search.method = "post";
		document.form_search.action = VIDEO_ROOT_PATH+"search_videos/"+searchtype+"/"+resultString+"/";
		document.form_search.submit();
		
	}
	return false;
}


function meg(){
}