
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 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;
		           eval(callback+"(result)");
		          // say(result)//document.getElementById('myspan').innerHTML = 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://mefeedia.com/images/00000005.jpg";
	}
	
	return "http://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){
	//q = eval("document.searchform.q.value");
	//str.replace(/Microsoft/, "W3Schools")
	if(q!="" && q!="Search Video"){
		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(/ /,"_");
		}		
		url = "/search/"+str.toLowerCase();
		document.location.href=url;//"/search/"+str.replace(/ /,"_").toLowerCase();
	}else{
		alert("Please enter a search term");
	}	
}


//ajax("index.php", "q="+quote+"&flash=true&user_id=<?php echo $user_id; ?>","say") ;//alert(quote)
