
username = false;



function findTextNode(element)
{
	var num = element.childNodes.length;

	for (var count = 0; count < num; count++)
	{
		var currentNode = element.childNodes[count];

		if (currentNode.nodeType == 3) /* its a text node */
		{
			return currentNode;
		}
		else if (currentNode.nodeType == 1) /* its an element node */
		{
			currentNode = findTextNode(currentNode);
			if (! (currentNode == null))
			{
				return currentNode;
			}		
		}	
	}

	return null;
}

/* searches for the first text node and replaces it */
function replaceLinkText(newText, anchor)
{
	if (anchor.childNodes)
	{
		var textNode = findTextNode(anchor);

		if (! (textNode == null))
		{
			textNode.nodeValue = newText;
		}
	}
}

function getLinkText(anchor)
{
	if (anchor.childNodes)
	{
		var textNode = findTextNode(anchor);

		if (! (textNode == null))
		{
			return textNode.nodeValue;
		}
	}
}


function changeiframe(iframe,url){
	window.frames[iframe].location.href=url;
}

function ask(message, url)
{
	if(confirm(message) )
	{
		parent.location.href = url;
	}
}

var ids=new Array('');

function switchid(id){	
	hideallids(id);
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
function GET(varible) {
	var url = document.location + '';
	q=url.split('?');
	if (q[1]) {
	var pairs = q[1].split('&');
	for (i=0;i<pairs.length;i++) {
	var keyval = pairs[i].split('=');
	if (keyval[0] == varible) {
	var squareid = keyval[1];
	}	}	}	
	return squareid;
}
// this function gets the cookie, if it exists
function Get_Cookie( name ) {		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function isset(test){
	if(test+"" == "undefined"){
		return false;
	}else{
		return true;
	}
}
function AttachScript(src)
{
	var script = document.createElement("SCRIPT");
	script.type = "text/javascript";
	document.getElementsByTagName("body")[0].appendChild(script);
	script.src = src;
}
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}
function toggle(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		if(document.getElementById(id).style.display == 'block') {
			document.getElementById(id).style.display = 'none';
			document.getElementById(id+'head').className='opencat';

		}
		else {
			document.getElementById(id).style.display = 'block';
			document.getElementById(id+'head').className='closecat';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			if(document.id.display == 'block') {
				document.id.display = 'none';
			}
			else {
				document.id.display = 'block';
			}
		}
		else { // IE 4
			if(document.all.id.style.display == 'block') {
				document.all.id.style.display = 'none';
			}
			else {
				document.all.id.style.display = 'block';
			}
		}
	}
}
function toggledesc(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		if(document.getElementById(id).style.display == 'block') {
			document.getElementById(id).style.display = 'none';
			document.getElementById(id+'head').className='descopen';

		}
		else {
			document.getElementById(id).style.display = 'block';
			document.getElementById(id+'head').className='descclose';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			if(document.id.display == 'block') {
				document.id.display = 'none';
			}
			else {
				document.id.display = 'block';
			}
		}
		else { // IE 4
			if(document.all.id.style.display == 'block') {
				document.all.id.style.display = 'none';
			}
			else {
				document.all.id.style.display = 'block';
			}
		}
	}
}
function writit(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}
function appendit(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		//x.innerHTML = '';
		x.innerHTML = x.innerHTML+text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML =  x.innerHTML+text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		//text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

var http_request = false;
function ajax(url, parameters,callback) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
       	// set type accordingly to anticipated content type
          //http_request.overrideMimeType('text/xml');
          http_request.overrideMimeType('text/html');
       }
    } else if (window.ActiveXObject) { // IE
       try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
       }
    }
    if (!http_request) {
       //alert('Cannot create XMLHTTP instance');
       return false;
    }
    
    http_request.onreadystatechange = function alertContents() {
		if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		           //alert(http_request.responseText);
		           result = http_request.responseText;
				  if(callback=="unamecheck") {
					  document.getElementById('signupinfo').innerHTML = result; 
				  }
				  else {
			           eval(callback+"(result)");
				  }
		          // say(result)
		        } else {
		           //alert('There was a problem with the request.');
		        }
		     }
		};
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
}




//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}
broken=Array();

function brokenImage(id,cache,orig,cache_hash,orig_hash,type, flag){
	//ret = img;
	if(broken[id]+"" == "undefined" &&  orig!=""){
		broken[id]=true;
		//if(flag)ajax("/newentry/broken.php?flag=0&cache="+cache_hash+"&orig="+ orig_hash+"&id="+id+"&type="+type,"","");
		return orig;
	}else{
		broken[id]=true;
		//if(flag)ajax("/newentry/broken.php?flag=1&cache="+cache_hash+"&orig="+ orig_hash+"&id="+id+"&type="+type,"","");
		return "http://www.mefeedia.com/images/00000005.jpg";
	}
	
	return "http://www.mefeedia.com/images/00000005.jpg";//"http://mefeedia.com/images/00000005.jpg";
}




function setEltDisplay(id, disp) {if (!document.getElementById)return false;var elt = document.getElementById(id);if (elt)elt.style.display = disp;return false;}
function showElt(id) {setEltDisplay(id, "");return false;}
function hideElt(id) {setEltDisplay(id, "none");return false;}

function open_signup_widget() {
hideElt("signup_link_tbl");
showElt("signup_tbl");
showElt("sect_edit_q");
document.form1.username.focus();
return false;}

function close_signup() {
showElt("signup_link_tbl");
hideElt("signup_tbl");
hideElt("sect_edit_q");
return false;}

// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
  function validateOnSubmit() {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
    if (!validateEmail  (document.forms.form1.email, 'inf_email', true)) {errs += 1;}
    if (!validatePresent(document.forms.form1.pass2,  'inf_pass2'))  { errs += 1;}
    if (!validatePresent(document.forms.form1.pass,  'inf_pass'))  { errs += 1;}
    if (!validatePresent(document.forms.form1.username,  'inf_username'))  { errs += 1;}
	if (!validatePasswords(document.forms.form1.pass, document.forms.form1.pass2, 'inf_pass2', true))  { errs += 1;}

    if (errs>1)  alert('Error in registration - please correct required fields.');
    if (errs==1) alert('Error in registration - please correct required fields.');

	return (errs==0);
  }
  
  
  



function searchMefeedia(q,dir){
	//q = eval("document.searchform.q.value");
	//str.replace(/Microsoft/, "W3Schools")
	if(q!="" &&	 q!="Search Video" &&  q!="Search Users" &&  q!="Search Shows"){
		var str= q+"";
		for(i=0; i<10; i++){
			str = str.replace(/[^a-zA-Z0-9 ]/," ");
		}
		for(i=0; i<10; i++){
			str = str.replace(/  /," ");
		}		
		for(i=0; i<10; i++){
			str = str.replace(/ /,"_");
		}		
		if(typeof(dir) == "undefined" || dir=="")
			dir = "/search/";
		url = ""+dir+str.toLowerCase();
		document.location.href=url;//"/search/"+str.replace(/ /,"_").toLowerCase();
	}else{
		alert("Please enter a search term");
	}	
}

function handleLogin(json){
	if(json==""){
		pleaseLogin('Please login with the correct email/password');
	}else{
		username = json;
		//hidediv('logindiv');
		//hidediv('registerdiv');
		//hidediv('loginlinkdiv');
		//pleaseLogin('Welcome back '+username+'!');
		document.location.href = document.location.href; 
		//document.location.href="/user/"+username;
		//document.location.href="/online.php";
	}
}

function handleLogout(json){
	document.location.href=document.location.href.value+'&logout';
	username=false;
	//hidediv('loggedindiv');
	//showdiv('logindiv');
}

function pleaseLogin(message){
	alert(message);
}
/*
function subscribe(feedid){
	if(username){
		if(document.subscribeimg.src=='/newimages/subscribe.gif'){
			ajax("/newestentry/index_ajax.php?&ajax=1&unsubscribe="+feedid,"","");
			document.subscribeimg.src='/newimages/unsubscribe.gif';
		}else{
			document.subscribeimg.src='/newimages/subscribe.gif';
			ajax("/newestentry/index_ajax.php?ajax=1&subscribe="+feedid,"","");
		}	
	}else{
		pleaseLogin('Please login to subscribe to this feed');
	}
}*/
function ajaxLogin(email,password,remember){
	if(!username){
		if(email!="" && password!=""){
			ajax("/newestentry/index_ajax.php?ajax&login","email="+email+"&password="+password+"&remember="+remember,"handleLogin","");
		}
	}
	//alert(username+password);	
}

function saveFeed(feedid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Feed Saved"){
			replaceLinkText('Save Feed',node);
			ajax("/newestentry/index_ajax.php?ajax=1&unsubscribe="+feedid,"","");
		}else{
			replaceLinkText("Feed Saved",node);
			ajax("/newestentry/index_ajax.php?ajax=1&subscribe="+feedid,"","");
		}
	}else{
		pleaseLogin('Please login to save this feed');
	}
}

function saveFollow(fid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Followed"){
			replaceLinkText('Follow',node);
			ajax("/newestentry/index_ajax.php?ajax=1&unfollow="+fid,"","");
		}else{
			replaceLinkText("Followed",node);
			ajax("/newestentry/index_ajax.php?ajax=1&follow="+fid,"","");
		}
	}else{
		pleaseLogin('Please login to follow this user');
	}
}

function saveEntry(globalid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Saved"){
			replaceLinkText('Save',node);
			ajax("/newestentry/index_ajax.php?ajax=1&unsave="+globalid,"","");
		}else{
			replaceLinkText('Saved',node);
			ajax("/newestentry/index_ajax.php?ajax=1&save="+globalid,"","");
		}
	}else{
		pleaseLogin('Please login to save this video');
	}
}

function updateSave(globalid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Updated"){
			replaceLinkText('Update',node);
			//ajax("/newestentry/index_ajax.php?ajax=1&unsave="+globalid,"","");
		}else{
			replaceLinkText('Updated',node);
			ajax("/newestentry/index_ajax.php?ajax=1&saveupdate="+globalid,"","");
		}
	}else{
		pleaseLogin('Please login to update this video');
	}
}


function updateUserWhite(userid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Updated"){
			replaceLinkText('Update',node);
			//ajax("/newestentry/index_ajax.php?ajax=1&unsave="+userid,"","");
		}else{
			replaceLinkText('Updated',node);
			ajax("/newestentry/index_ajax.php?ajax=1&white="+userid,"","");
		}
	}else{
		pleaseLogin('Please login to update this user');
	}
}

function updateUserBlack(userid,node){
	//alert(globalid);	
	if(username){
		text = getLinkText(node);
		if(text=="Updated"){
			replaceLinkText('Update',node);
			ajax("/newestentry/index_ajax.php?ajax=1&unblack="+userid,"","");
		}else{
			replaceLinkText('Updated',node);
			ajax("/newestentry/index_ajax.php?ajax=1&black="+userid,"","");
		}
	}else{
		pleaseLogin('Please login to update this user');
	}
}

function usernameLookup(uname,node){
	//alert(globalid);	
	if(uname){
		ajax("/newestentry/index_ajax.php?ajax=1&unamelookup="+uname,"","unamecheck");
	}
}

function toggleTheater(){ 
 document.bgColor = "#333333";
//	if(document.bgColor =="#333333"){
	//   document.bgColor = "#FFFFFF";
	//}else{
	 
	//}

}


function addComment(globalid,userid){
	comment  = eval("document.commentform.comment.value");
	replyid = eval("document.commentform.parent_comment_id.value");
	if(document.commentform.commentnotification.checked == 0){commentnotification=0;}
	else if(document.commentform.commentnotification.checked == 1){commentnotification=1;}
	if(userid == "0" || userid == "") {
		author = eval("document.commentform.commentnamein.value");
		email = eval("document.commentform.commentemailin.value");
		website = eval("document.commentform.commenturlin.value");
		//var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
		var emailPattern = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;
		//var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
		if(author=="") {
			alert('Please enter your name.')
		}else if(comment=="") {
			alert('Please enter a comment.')
		}else if(email=="") {
			alert('Please enter a valid email address.')
		}else if(emailPattern.test(email) != true) {
			alert('Email address appears invalid. Please check and resubmit.')
		}
		else {
			ajax("/newestentry/index_ajax.php?globalid="+globalid+"&author="+author+"&email="+email+"&website="+website+"&replyid="+replyid+"&cf="+commentnotification+"&comment="+comment,"","");
			eval("document.commentform.comment.disabled = true;");
			eval("document.commentform.submit.value = 'Comment Sent';");
			eval("document.commentform.submit.disabled = true;");
			showdiv("responddone");
		}
	}else{
		if(comment=="") {
			alert('Please enter a comment.')
		}
		else {
			ajax("/newestentry/index_ajax.php?globalid="+globalid+"&replyid="+replyid+"&cf="+commentnotification+"&comment="+comment,"","");
			eval("document.commentform.comment.disabled = true;");
			eval("document.commentform.submit.value = 'Comment Sent';");
			eval("document.commentform.submit.disabled = true;");
			//hidediv("respond");
			showdiv("responddone");
		}
	}
	//pleaseLogin("Your comment has been added, thanks!");
		
}
function Tag(globalid){
	tag  = eval("document.tagform.tag.value");
	ajax("/newestentry/index_ajax.php?ajax=1","globalid="+globalid+"&tag="+tag,"alert('The video has been tagged.')");
	hidediv('AddTagDiv');
 }
 
 function Share(globalid){
 	hidediv('ShareDiv2');
	list  = eval("document.shareform.emails.value");
	from  = eval("document.shareform.emailfrom.value");
	subject  = eval("document.shareform.subject.value");
	message  = eval("document.shareform.message.value");
	
	url="/newestentry/index_ajax.php?";
	if(list!="List Email Addresses")
		url+="&emails="+list;
	
	if(list=="") {
			alert('You did not enter an email address to send this video to.')
	}else{
		ajax(url+"&share=1&subject="+subject+"&globalid="+globalid+"&emailfrom="+from+"&message="+message,"","alert('Your video has been shared.')");
	}
 }
//ajax("index.php", "q="+quote+"&flash=true&user_id=<?php echo $user_id; ?>","say") ;//alert(quote)

function jump(obj){ 
	if(obj.selectedIndex != 0){ 
    	window.location=obj.options[obj.selectedIndex].value;
    }
} 

