// JavaScript Document
function fb_share() {
	u=location.href;
	t=document.title;
//	video_id = gup("video_id");
//	if(video_id!="")
//		u="http://www.campuschannels.com/video.php?video_id="+video_id;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function show_delay_clear_msg(el, msg, delay){
	document.getElementById(el).innerHTML=msg;
	setTimeout("document.getElementById('"+el+"').innerHTML='';", delay*1000);
}

function leave_message(){
	window.open('leavemessage.php','_blank','width=600, height=540, location=0, menubar=0, resizable=0, scrollbars=0, status=0, titlebar=0, toolbar=0');	
}

function submitenter(myfield,e, callFunction)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
	   if(callFunction=='')
		   myfield.form.submit();
		else
			eval(callFunction)();
   return false;
   }
else
   return true;
}

function showmenu(container, id){
	//clear the previous hide if any
	clearhidemenu(container, id.substr(0, 4));
	var menus = document.getElementById(container).getElementsByTagName('ul');		//hide all other opened menus;
	//close other same level menus and their submenus
	for(i = 0; i<menus.length; i++){
		if(menus[i].id.substr(0, 2)!='m_') continue;
		if(menus[i].id==id || (menus[i].id.length<id.length && id.substr(0, menus[i].id.length)==menus[i].id)){
			menus[i].style.display="block";
			menus[i].style.visibility="visible";
		}else{
			if(isstatic(container, menus[i].id)) continue;
			menus[i].style.display="none";
			menus[i].style.visibility="hidden";
		}
	}
}

function delayhidemenu(container, id){
	if(document.getElementById(id)!=null){
		window['TimeOut'+container+id]=setTimeout("hidemenu('"+container+"', '"+id+"')",300)
	}
}
function clearhidemenu(container, id){
	if (typeof window['TimeOut'+container+id]!="undefined")
		clearTimeout(window['TimeOut'+container+id])
}
function hidemenu(container, id){
	var menus = document.getElementById(container).getElementsByTagName('ul');
	//close the menu and all it's submenus
	for(i = 0; i<menus.length; i++){
		if(menus[i].id.substr(0, 2)!='m_') continue;
		if(isstatic(container, menus[i].id)) continue;	//for videos.php left index
		if(menus[i].id.length>=id.length && menus[i].id.substr(0, id.length)==id){
			menus[i].style.display="none";
			menus[i].style.visibility="hidden";
		}
	}
}
function isstatic(container, id){
	if(container=='index' && id.length<=4)
		return true;
	else
		return false;
}


function text_focus(el, defaultText){
	textbox = document.getElementById(el)
	
	if(textbox.value == "" || textbox.value == defaultText){
		textbox.value = "";
		textbox.className = 'focus';
		if(textbox.type == "password"){
			textbox.style.backgroundImage = "";
		}
	}
}
function text_blur(el, changeText, backgroundImage){
	textbox = document.getElementById(el)
	text = textbox.value.replace(/^\s+|\s+$/g,"");
	if(text == ''){
		textbox.className = 'blur';
		if(textbox.type == "password"){
			textbox.style.backgroundImage = backgroundImage;
		}else{
			textbox.value = changeText;	
		}
	}
}

function video_search(){
	search_text = document.getElementById('txt_search').value;
	search_text = search_text.replace(/^\s+|\s+$/g,"");
	if(search_text!="")
		window.location = 'video.php?search='+search_text;
	else
		window.location = 'video.php';
}

/**********popup window js***********/
function popOpen(popID, popWidth){
     //All logic goes in here
	//Fade in the Popup and add close button
	$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('');

	//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
	var popMargTop = ($('#' + popID).height() + 80) / 2;
	var popMargLeft = ($('#' + popID).width() + 80) / 2;

	//Apply Margin to Popup
	$('#' + popID).css({
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});

	//Fade in Background
	$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
	$('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=60)'}) is used to fix the IE Bug on fading transparencies 
};

$(document).ready(function() {
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		popClose();
	});
	
});

function popClose(){
	$('#fade , .popup_block').fadeOut(function() {
		$('#fade').remove();  //fade them both out
	});
	return false;
}





/************************************/

