// JavaScript Document

function subscribeDada(src){
	 var letter_mail = document.getElementById('letter_mail').value;
	var temp = 0;
	if(CheckEmailDada(letter_mail)==true){
		document.getElementById(src).innerHTML='<br><br><br><center><img src="assets/ajax-loader.gif"><br>Loading...</center><br><br><br>';
		var req = Inint();
		req.onreadystatechange = function () { 
		if (req.readyState==4) {
			if (req.status==200) {
				document.getElementById(src).innerHTML=req.responseText; 
			} 
		}
		 };
		 	
	
			 var url = "includes/dadaInserMail.php?mail="+letter_mail;
			 
			 req.open("GET", url); 
			 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");     
			 req.send(null);
				
	}
}

function CheckEmailDada(email){
	    var firstchunk,indx,secondchunk;

    if (email == ""){
       return false;
    }

    //get the zero-based index of the "@" character
    indx = email.indexOf("@");

    //if the string does not contain an @ then then return true
    if (indx == -1 ){
		return false;
    }

    //if the first part of email is < 2 chars and second part < 7 chars
    //(arbitrary but workable criteria) then reject the input address

    firstchunk = email.substr(0,indx); //up to but not including the "@"

    //start at char following the "@" and include up to end of email addr
    secondchunk = email.substr(indx + 1); 

    //if the part  following the "@" does not include a period "." then
    //also return false
    if ((firstchunk.length < 2 ) || (secondchunk.length < 7) ||
    (secondchunk.indexOf(".") == -1)){ 
		return false;
	}
		return true;
}