function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		    alert("Enter valid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    alert("Enter valid email address")
		   return false
		}
 
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Enter valid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Enter valid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Enter valid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Enter valid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Enter valid email address")
		    return false
		 }

 		 return true					
	}

function ValidateFormEmail(){
	var emailID=document.alerts.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Enter your email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


function ajaxFunctions2(){
	var ajaxRequests2;
	try{
		ajaxRequests2 = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequests2 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequests2 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}

	}
	return ajaxRequests2;
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

function changeOpac(opacity, id) {
	if(id == "ty-subscribe"){
		document.getElementById(id).style.display = "block";
		document.getElementById("subscribe").style.display = "none";
	}
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function saveEmail(){
	htmlRequest = ajaxFunctions2();
	if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
		alert ("Browser does not support HTTP Request");
		return;
	} 
	//alert(alerts.email.value);
	if(!ValidateFormEmail()){
		return;	
	}
	
	htmlRequest.open('POST', '/includes/saveEmail.php');
	htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//alert('email2='+document.alerts.email.value);
	htmlRequest.onreadystatechange = function(){
		if(htmlRequest.readyState == 4){
			//alert(htmlRequest.responseText);
			if(htmlRequest.responseText.match("success") != null){
				opacity("subscribe", 100, 0, 500);
				opacity("ty-subscribe", 0, 100, 500);
			}
			//document.getElementById("shoppingcart").innerHTML = htmlRequest.responseText;
		}
	}
	htmlRequest.send('email='+document.alerts.email.value); 
	//setTimeout("doTYClick()",1000);
} 


