/**
 * @author Administrator
 */


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 subscribeToMailingList()
{

	if (document.mailing_form.email.value == "" || document.mailing_form.email.value == "e-mail address" || !isEmailValid(document.mailing_form.email.value))
	{
		alert("Please provide a valid e-mail address!");
	}
	else {
	
		email = document.mailing_form.email.value;
		
		document.getElementById("subscribe_box").innerHTML = "Please Wait";
		
		xmlHttp = GetXmlHttpObject()
		
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!");
			return;
		}
		
		var url = "php/ajax/subscribeToMailingList.php?email=" + email;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = subscribed;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
	}

} 



function subscribed() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("subscribe_box").innerHTML=xmlHttp.responseText;
	}
}


function unsubscribeFromMailingList()
{

	if (document.mailing_form.email.value == "" || document.mailing_form.email.value == "e-mail address" || !isEmailValid(document.mailing_form.email.value))
	{
		alert("Please provide a valid e-mail address!");
	}
	else {
	
		email = document.mailing_form.email.value;
		
		document.getElementById("subscribe_box").innerHTML = "Please Wait";
		
		xmlHttp = GetXmlHttpObject()
		
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!");
			return;
		}
		
		var url = "php/ajax/unsubscribeFromMailingList.php?email=" + email;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = unsubscribed;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
	}

} 



function unsubscribed() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("subscribe_box").innerHTML=xmlHttp.responseText;
	}
}


function isEmailValid(email)
{
	
	valid = true;
	
	apos = email.indexOf("@");
	dotpos = email.lastIndexOf(".");
	
	if (apos<1||dotpos-apos<2) 
	{
	    valid = false;		
	}		
	
	return valid;

}
    
    



function showLogin()
{

	//document.getElementById('login').style.display = 'block';
	new Effect.ScrollTo('col_wide', { duration: 1 });	
	//new Effect.Highlight('login_box');
	
	new Effect.Highlight('login_box', { queue: 'end', startcolor: '#EF1DDC', endcolor: '#FFFFFF' });
	


}



function hideLogin()
{

	document.getElementById('login').style.display = 'none';

}



function validate_mailing_form()
{
        
        valid = true;
        

		if ( document.mailing_form.email.value == "" || document.mailing_form.email.value == "e-mail address" )
		{
		    alert ( "Please type in your e-mail address!" );
		    valid = false;
		}          
    
    
    return valid;
    
    
    
}

function showThreadForm()
{
	document.getElementById('threadform').style.display = 'block';
	document.getElementById('threadbutton').style.display = 'none';


}

function showPostForm()
{
	document.getElementById('postform').style.display = 'block';
	document.getElementById('postbutton').style.display = 'none';


}


function popup(page, height)
{
	
	window.open(page,'newwindow','scrollbars=yes,status=no,width=500,height=' + height)
}


function validate_account_form()
{
        
        valid = true;
        

		if ( document.account_form.email.value == "" || document.account_form.username.value == ""  )
		{
		    alert ( "Please complete all fields marked with an asterisk *." );
		    valid = false;
		}          
    
    
    return valid;
    
    
    
}

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.replace_main.checked == 1 )
    {
 	if ( document.images_form.main.value == "" )
 	{
 		alert ( "Please complete all fields marked with *." );
        	valid = false;
 	}
 
    }
    
    
   

    return valid;
}



function validate_contact_form()
{
        
        valid = true;
        

		if ( document.contact_form.fromname.value == "", document.contact_form.fromaddress.value == "" || document.contact_form.message.value == "" )
		{
		    alert ( "Please complete all fields marked with an asterisk *." );
		    valid = false;
		}          
    
    
    return valid;
    
    
    
}




function validate_registration_form()
{
    valid = true;

    if ( document.registration_form.reg_email.value == "" || document.registration_form.reg_username.value == "" || document.registration_form.password.value == "" || document.registration_form.monkey.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_thread_form()
{
    valid = true;

    if ( document.thread_form.title.value == "" || document.thread_form.content.value == "" )
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    


    return valid;
}



function validate_post_form()
{
    valid = true;

    if ( document.post_form.content.value == "" )
    {
        alert ( "Please complete all fields marked with *." );
        valid = false;
    }   
    


    return valid;
}




function showBubble(name)
{

	document.getElementById('bubble').style.display = 'block';
	document.getElementById('bubble').style.background = 'url(../images/bubble_' + name + '.gif)';
	

}


function hideBubble()
{


	document.getElementById('bubble').style.display = 'none';
	
}

function validate_login_form()
{
        
        valid = true;
        

		if ( document.login_form.username.value == "" || document.login_form.password.value == "" )
		{
		    alert ( "Please complete all fields." );
		    valid = false;
		}          
    
    
    return valid;
    
    
    
}