/**
 * @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 popup(page)
{
	window.open(page,'newwindow','scrollbars=yes,status=no,width=400,height=182')
}



function validate_contact_form()
{
    
	msg = "";
    valid = true;

    if ( document.contact_form.message.value == "" )
    {
		msg = msg + "You must enter a message.\n";
        valid = false;
    }   
	
    if ( document.contact_form.name.value == "" )
    {
		msg = msg + "You must enter your name.\n";
        valid = false;
    }   	
	
    if ( document.contact_form.captcha_code.value == "" )
    {
		msg = msg + "You must enter the security code.\n";		
        valid = false;
    }   	

	
	if (document.contact_form.email.value != "")
	{
	
		apos = document.contact_form.email.value.indexOf("@");
		dotpos = document.contact_form.email.value.lastIndexOf(".");
		
		if (apos < 1 || dotpos - apos < 2)
		{
			msg = msg + "The email address entered is not valid.\n";		
			valid = false;
		}
		
	}
	
	if(document.contact_form.email.value == "" && document.contact_form.tel.value == "")
    {
		msg = msg + "You must enter either your telephone number or email address.\n";		
        valid = false;
    }   	

	if(valid == false)       
	{
        alert (msg);		
	}
	   

    return valid;
	
}
