var xmlHttp
var Effect;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function validate_login_form()
{
    valid = true;

    if ( document.login_form.username.value == "" || document.login_form.password.value == "")
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    

    return valid;
}

function validate_forgot_password_form()
{
    valid = true;

    if ( document.forgot_password_form.fpwd_username.value == "" || document.forgot_password_form.fpwd_email.value == "")
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   

    return valid;
}



function validate_registration_form()
{
    valid = true;

    if ( document.registration_form.username.value == "" || document.registration_form.password.value == "" || document.registration_form.monkey.value == "" || document.registration_form.email.value == "" || document.registration_form.first_name.value == "" || document.registration_form.last_name.value == "" || document.registration_form.dob.value == "")
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    
    if ( document.registration_form.password.value != document.registration_form.monkey.value)
    {
        alert ( "Your passwords do not match." );
        valid = false;
    }   
    

    return valid;
}

function validate_account_form()
{
    valid = true;

    if ( document.account_form.email.value == "" || document.account_form.first_name.value == "" || document.account_form.last_name.value == "" || document.account_form.dob.value == "")
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    

    

    return valid;
}

function validate_comment_form()
{
    valid = true;

    if ( document.comment_form.content.value == "" )
    {
        alert ( "You didn't say anything!" );
        valid = false;
    }   
    

    

    return valid;
}


function validate_contact_form()
{
        
	valid = true;


	if(document.contact_form.name.value == "" || document.contact_form.address.value == "" || document.contact_form.message.value == "")
	{
	    alert("Please complete all fields marked with *.");
	    valid = false;
	}
	    else if(document.contact_form.message.value.length>400)
	    {
		alert ( "Your message must be less than 400 characters." );
		valid = false;
	    }
    	

	return valid;

}






function showLogin()
{

	document.getElementById('loginSmall').style.display = 'inline';
	
	//document.getElementById('loginName').style.display = 'none';
	
	document.getElementById('search').style.display = 'none';
	

}

function showSearch()
{

	document.getElementById('loginSmall').style.display = 'none';
	
	document.getElementById('loginName').style.display = 'none';
	
	document.getElementById('search').style.display = 'inline';
	
	
	//document.getElementById('loginName').style.display = 'none';
	

}

function showSearch_loggedin()
{


	
	document.getElementById('loginName').style.display = 'none';
	
	document.getElementById('search').style.display = 'inline';
	
	
	//document.getElementById('loginName').style.display = 'none';
	

}

function hideMsg()
{

	//document.getElementById('msgBar').style.display = 'none';

}

function removeMsg()
{

	//if(document.getElementById('msgBar').innerHTML != "")
	//{
	//	document.getElementById('msgBar').style.display = 'block';
	//}
	
	//setTimeout('hideMsg()', 5000);

}

function validate_password_form()
{
    valid = true;

    if ( document.password_form.cur_pwd.value == "" || document.password_form.new_pwd.value == "" || document.password_form.monkey_pwd.value == "" )
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    
    if ( document.password_form.new_pwd.value != document.password_form.monkey_pwd.value)
    {
        alert ( "Your passwords do not match." );
        valid = false;
    }   
    

    return valid;
}

function validate_images_form()
{
    valid = true;
   
 	if ( document.images_form.imagefile.value == "" )
 	{
 		alert ( "Please complete all fields marked with *." );
        	valid = false;
 	}   

    return valid;
}



function popup(page)
{
	window.open(page,'newwindow','scrollbars=yes,status=no,width=500,height=410')
}

function logout(name)
{
	if(confirm("Are you sure you want to log out, " + name + "?"))
	{
		location.href = "/logout/process";
	}

}

function scrollToElement(element_id)
{
	new Effect.ScrollTo(element_id);	

}


function showMoreArticles(group_id, limit)
{
		scrollToElement("page_articles");
		
		document.getElementById("page_articles_loader").innerHTML = '<p class="loading"><img src="images/loader_transparent.gif" alt="Loading" /> Please Wait...</p>';
		
		new Effect.BlindUp('page_articles', { queue: 'front', duration: 0.5 });									
		xmlHttp = GetXmlHttpObject()
		
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!");
			return;
		}
		
		var url = "php/ajax/showMoreArticles.php?group_id=" + group_id;
		url = url + "&limit=" + limit;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = articlesShown;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
} 



function articlesShown() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("page_articles").innerHTML=xmlHttp.responseText;
		
		setTimeout("new Effect.BlindDown('page_articles', { queue: 'end', duration: 2 })", 3000);
		setTimeout("document.getElementById('page_articles_loader').innerHTML = ''", 3000);		
		
		//new Effect.BlindDown('page_articles', { queue: 'end', duration: 2 });			
	}
}


