function join_list(form)
{
	if (form.email.value=="")
	{
	 	alert (_email_empty);
	 	form.email.focus();
		return;
	}
	else if (!checkEmail(form.email.value))
	{
	 	alert (_email_invalid);
	 	form.email.focus();
		return;
	}
	else 
	{
		form.submit();
		alert(_email_confirm);
	}
}
function validateAndSubmitForm (form)
{
	if (form.name.value=="")
	{
		alert(_contact_name_empty);
		form.name.focus();

		return false;
	}
	if (form.email.value=="")
	{
		alert(_contact_email_empty);
		form.email.focus();

		return false;
	}
	if (!checkEmail(form.email.value))
	{
		alert(_contact_email_invalid);
		form.email.focus();

		return false;
	}
	if (form.phone.value=="")
	{
		alert(_contact_phone_empty);
		form.phone.focus();

		return false;
	}
	
	form.action="gdform.php";
	form.submit();
}

function toggle_div(divId){
    if(document.getElementById(divId).style.display == "none" || document.getElementById(divId).style.display == "")
        document.getElementById(divId).style.display = "block";
    else
        document.getElementById(divId).style.display = "none";
}

function get_affirmation_category(catId){
    location = "affirmations.php?category=" + catId;
}

function sendLink()
{
	var currentURL = document.location.href;
	var poundIndex = currentURL.indexOf("#",0);
	if (poundIndex > 0)
		currentURL = currentURL.substring(0, poundIndex);
	
	var mailToLink = "mailto:?subject=A reccomended article at http://freespirit.org.il&body="+ currentURL;
	location.href = mailToLink;
}




function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function HttpRequest(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}