

function download_video(video_id, fmt, website_url) {
	$('#download-loading').show();
	$('#blk_result').html('');
}
	
function selectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

var THUMB_PREVIEW_TIMER;

function mousOverImage(name,id,nr, bSize, bColor, is_filtered){

	if(name)
		imname = name;

	imname.style.border = bSize+'px solid #'+bColor;

	if ( is_filtered == 0 ) {
		if ( nr == 1 ) {
		//imname.src = "http://img.youtube.com/vi/"+id+"/"+nr+".jpg";
		imname.src = "http://i.ytimg.com/vi/"+id+"/"+nr+".jpg";
		
		} else {
		//imname.src = "http://img.youtube.com/vi/"+id+"/"+nr+".jpg";
		imname.src = "http://i"+nr+".ytimg.com/vi/"+id+"/"+nr+".jpg";
		}
		nr++;
		if(nr > 3)
			nr = 1;
		THUMB_PREVIEW_TIMER = setTimeout("mousOverImage(false,'"+id+"',"+nr+", '"+bSize+"', '"+bColor+"', "+is_filtered+");",600);
	} else {
		imname.src = "images/disallowed_thumbnail.gif";
	}
}


function mouseOutImage(name, bSize, bColor, is_filtered){

	if(name)
		imname = name;

	imname.style.border = bSize+'px solid #'+bColor;
	if ( is_filtered == 0 ) {
	if(THUMB_PREVIEW_TIMER)
		clearTimeout(THUMB_PREVIEW_TIMER)
	}
}


function toggleSearchSettings() {

	var filter = document.getElementById('filter');

	if(filter.style.display == "none") {

		filter.style.display = "block";

	}else{

		filter.style.display = "none";
	}
}

function filterIsActive(id) {

	var status = document.getElementById(id);
	
	if(getObjInnerText(status) == lang_filter_on) {
		return false;
	}else{

		return true;
	}
}

function setSafeSearchPref() {

	var filterTitle = document.getElementById('filter-title');
	var hiddenInput = document.getElementById('search-filter-hiddenInput');
	var status = document.getElementById('search-filter-status-button');

	if(filterIsActive('search-filter-status-button')) {
		hiddenInput.value = "on";
		//setObjInnerText(filterTitle,"Search Filter ON");
		setObjInnerText(status, lang_filter_on);
		status.style.background = "green";

	}else{
		hiddenInput.value = "off";
		//setObjInnerText(filterTitle,"Search Filter OFF");
		setObjInnerText(status, lang_filter_off);
		status.style.background = "#D93636";

	}

}





function getObjInnerText(obj){ 
	if (document.all) { // IE; 
		return obj.innerText; 
	} 
	else{ 
		if (obj.textContent) 
		{ 
			return obj.textContent; 
		} 
		else 
			alert("Error: This application does not support your browser. Try again using IE or Firefox."); 
	} 
} 

function setObjInnerText(obj, text){ 
	if (document.all) { // IE; 
		obj.innerText = text; 
	} 
	else{ 
		if (obj.textContent) 
		{ 
			obj.textContent = text; 
		} 
		else 
			alert("Error: This application does not support your browser. Try again using IE or Firefox."); 
	} 
} 

function isset(varname){
 	 return(typeof(window[varname])!='undefined');
}


function showLoading(target_di,loading_div, value)
{
	tObject = document.getElementById(target);
	tObject = document.getElementById(target);

	object.style.top = '0px';
	object.style.left = '0px';
	object.style.width = '0px';
	object.style.display = 'block';
	object.innerHTML = 'Loading... ';	

}


function ajaxGet(script,target, param, emptyLoad) {

	
		if (emptyLoad == null) {
			var emptyLoad = "";
		}
		
		
		
		if (emptyLoad != "") {
		
			//document.getElementById(emptyLoad).innerHTML = '<table height="100%" width="100%"><tr><td align="center" valign="middle"><img src="'+theme_base+'/images/ajax-loader.gif" border="0"></td></td></table>';
			$('#'+emptyLoad).html('<img src="'+theme_base+'/images/ajax-loader.gif" border="0">');
		}

		if (param == false) {

			param = '';
		}

		var url = script + param;

  		$.ajax(
    		{
      		'url':url
			,'timeout':12000
      		,'success':function(data)
				{ 
					if (emptyLoad != "") {
						$('#'+emptyLoad).html('');
					}
					
					$('#'+target).html(data);
					//$("#"+target).html(req.responseText).serialize();
			
					return true;
				}


			,'error':function(req)
				{ 
					if (emptyLoad != "") {
						$('#'+emptyLoad).html('');
					}
					$('#'+target).html("Ooops, something went wrong...Pls try again");
					return false;
				}

    		}
  		);



}

function addbookmark(bookmarkurl,bookmarktitle){
	if (document.all);window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


function submitForm(theform, successMsg, refreshSection, refrechParams) {
	var status = AjaxRequest.submit(
		theform
		,{
		'onSuccess':function(req){ 

				if(req.responseText.search("error1") != "-1")
					alert(lang_please_enter_guest_and_comment);
				else if(req.responseText.search("error2") != "-1")
					alert(lang_please_enter_the_image_code);
				else if(req.responseText.search("error3") != "-1")
					alert(lang_wrong_image_code);
				else{
					refreshHandler(refreshSection,refrechParams);
					if(successMsg != "")
						alert(successMsg);
				}

			}
		}
	);
	return status;
}

function getNewImgCode(root,img_id) {

	var foo = new Date; // Generic JS date object
	var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
	var ts = parseInt(unixtime_ms / 1000);

	var img = document.getElementById(img_id);
	img.src = root+'lib/validator/code.php?id='+ts;
}

function refreshHandler(section,params) {

	if (section == "comments") {
		refreshComments(params);
	}
}

function refreshComments(vid){

	ajaxGet(website_url + 'ajax/comments_local.php?vid=', 'local_comments', vid, false);
	setContent('commentPost','<p class="resultMsg">Comment Posted Successfully!</p>');
	var total = parseInt(getContent('comments_count1')) + 1;
	setContent('comments_count1',total);
	setContent('comments_count2',total);
}

function hideObjectId(id) {

	var object = document.getElementById(id);
	if ( object == null ) {
	} else {
		object.style.display = "none";
	}
}
function showObjectId(id) {

	var object = document.getElementById(id);
	if ( object == null ) {
	} else {
		object.style.display = "block";
	}
}

function toggleDesc(){

	var long_desc = document.getElementById("long_desc");
	var short_desc = document.getElementById("short_desc");

	if(short_desc.style.display == "block") {
		hideObjectId("short_desc");
		showObjectId("long_desc");
	}else{
		hideObjectId("long_desc");
		showObjectId("short_desc");
	}
}

function setDisplay(mode){

	var display_list = document.getElementById("display_list");
	var display_grid = document.getElementById("display_grid");
	var button_list = document.getElementById("button_list");
	var button_grid = document.getElementById("button_grid");


	if(mode == "list") {
		hideObjectId("display_grid");
		showObjectId("display_list");
		button_list.className='selected';
		button_grid.className='';
		setCookie("list_mode", "list", '', '/', '', '' );
	}else{
		hideObjectId("display_list");
		showObjectId("display_grid");
		if ( button_list == null ) {
		} else {
			button_list.className='';
			button_grid.className='selected';
			setCookie("list_mode", "grid", '', '/', '', '' );
		}
	}
}

function setDisplayOnLoad() {

	var mode = getCookie("list_mode");
	if(mode == "") {
		mode = "list";
		setCookie("list_mode", "list", '', '/', '', '' );
	}
	setDisplay(mode);
	
}

function setListOrderBy(order){
	var corder = getCookie("list_time");
	if(corder == "" || corder != order) {
		setCookie("list_orderby", order, '', '/', '', '' );
		location.href=location.href;
	}
}

function setListTime(time){
	var ctime = getCookie("list_time");
	if(ctime == "" || ctime != time) {
		setCookie("list_time", time, '', '/', '', '' );
		location.href=location.href;
	}
}

function setContent(id,content) {

	var object = document.getElementById(id);
	object.innerHTML = content;
}

function getContent(id) {

	var object = document.getElementById(id);
	return object.innerHTML;
}


function downloadVid(link) {

	downloadWin = window.open (link,"downloadWin","menubar=0,resizable=0,location=1,status=0,scrollbars=0,width=200,height=150"); 
	downloadWin.moveTo(0,0);
 } 




/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {

    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



function checkAll22(field)
{
	if ( $("#rem_all_comments:checked").val() == 1 ) {
		$("input[@type=checkbox].vids_class").each(function(){
			this.checked = true;
		});
	
	} else {
		$("input[@type=checkbox].vids_class").each(function(){
			this.checked = false;
		});
	}
}

function uncheckAll(field)
{
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}


function ajaxGetArray(script,target, param, emptyLoad) {

	
		if (!isset(emptyLoad)) {
			var emptyLoad = "";
		}

		if (emptyLoad != "") {
			document.getElementById(emptyLoad).innerHTML = '<table height="100%" width="100%"><tr><td align="center" valign="middle"><img src="'+theme_base+'/images/ajaxLoader.gif" border="0"></td></td></table>';
		}

		if (param == false) {

			param = '';
		}

		var url = script + param;

  		AjaxRequest.get(
    		{
      		'url':url
      		,'onSuccess':function(req)
				{ 
					if (emptyLoad != "") {
						document.getElementById(emptyLoad).innerHTML = '';
					}
					
					//document.getElementById(target).innerHTML = req.responseText;
					$("#"+target).html(req.responseText).serialize();
			
					return true;
				}


			,'onError':function(req)
				{ 
					if (emptyLoad != "") {
						document.getElementById(emptyLoad).innerHTML = '';
					}
					document.getElementById(target).innerHTML = "Ooops, something went wrong...Pls try again";
					return false;
				}

    		}
  		);



}

function get_video_url() {
	var player_html = document.getElementById("mediaspace").innerHTML;
	$.post("get_video_url.php", { "string": player_html },
   function(data){
     if ( data != '0' ) {
		window.location.href = data;
	 }
   }
   );
	
	 
}

function custom_bookmark(title,url){
	if (window.sidebar) { // Mozilla Firefox
		window.sidebar.addPanel(title, url, url);
	}
	else if (window.external || (window.opera && window.print) ) { // IE
		window.external.AddFavorite(url, title);
	}
}

function set_display_favorites() {
	if ( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ) {
	} else if (window.sidebar) { // Mozilla Firefox
		document.getElementById('blk_favorites').style.display = '';
	} else if (window.external || (window.opera && window.print) ) { // IE
		document.getElementById('blk_favorites').style.display = '';
	}
}

jQuery(document).ready( function() {
	jQuery("#frmUploadVideoDesc").submit(function() {
		var title	= jQuery('#title').val();
		var desc	= jQuery('#desc').val();
		var keyword	= jQuery('#keyword').val();
		
		if ( title == '' ) {
			alert(lang_please_specify_video_title);
			return false;
		} else if ( desc == '' ) {
			alert(lang_please_specify_video_desc);
			return false;
		} else if ( keyword == '' ) {
			alert(lang_please_specify_video_keyword);
			return false;
		} else {
			return true;
		}
	});
	

});

function upload_video_file() {
	var file1	= jQuery('#file1').val();
	if ( file1 == '' ) {
		alert(lang_please_specify_video_file);
		return false;
	} else {
		document.frmUploadVideo.submit();
	}
}