// JavaScript Document

function checkEmailForm(){

//return true;

mode=document.emailForm.mode.value;

//alert("זמנית לא ניתן לשלוח אימייל")
//return false;

//name validation
if (mode=="contact" || mode=="busEmail"){
    str=document.emailForm.cName.value;
    var regNstr = "^.{2,30}$";
    var regN = new RegExp(regNstr);
    if (!regN.test(str)) {
     		alert("Name is missing!")
     		return false;
	}
}


if (mode=="addSite" || mode=="advertise" || mode=="busEmail"){
	str=document.emailForm.tel.value;
	var regNstr ="^[0-9\- ,]{8,50}$";
	var re = new RegExp(regNstr);
    if (!re.test(str)) {
     		alert("Phone is missing or incorrect!")
     		return false;	
			}

}


if (mode=="contact" || mode=="busEmail"){
//email validation
    str=document.emailForm.eAdd.value;
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (reg1.test(str) || !reg2.test(str)) {
     		alert("Email is missing or incorrect!")
     		return false;
	}
}


//bus name validation
if (mode=="addSite"){
    str=document.emailForm.busName.value;
    var regNstr = "^.{2,30}$";
    var regN = new RegExp(regNstr);
    if (!regN.test(str)) {
     		alert("Name error!")
     		return false;
	}
}



//text length validation
str=document.emailForm.cMessage.value.length
if (str>1000) {
	alert("Message is too long")
	return false;
	}
else{
		if (str<5){
		alert("Message is too short")
		return false;
		}
	}

window.setTimeout("emailSent(1)",1500);

return true;

}



function emailSent(p){
	
if (mode=="busEmail"){	
var sent="Thank you for your message!";
var msgTitle="";
var msgBody=""+
"<table cellpadding='0' cellspacing='0' style='border:0px solid;font:13px arial' width='430' height='167' background='gui/busEmailBack.gif'>"+
"<tr><td valign='top' align='left'><br><div dir='ltr' style='margin-left:23px;color:#C26E96'>"+sent+"</div></td></tr>"+
"<tr><td>"+
"<div style='margin-right:10px;font:13px arial'></div>"+
"</td></tr>"+
"</table>";
}						  
						  

if (mode=="contact" || mode=="site4you" || mode=="advertise"){
 	var msgTitle="Thank you for your message!"
 	var msgBody="<br><div style='margin-left:10px;font:15px arial'>We'll be happy to assist you,<span> TOOTY Team.</span></div>"
}


if (p==1){
		document.getElementById("eForm").innerHTML=msgBody
		document.getElementById("eTitle").innerHTML=msgTitle
}
else{
		if (mode!="busEmail"){
		document.getElementById("eForm").innerHTML=""
		document.getElementById("eTitle").innerHTML="Your message was not delivered due to an error!"
		}
		else{
		 sent="Your message was not delivered due to an error!"		
		 msgBody=""+
		"<table cellpadding='0' cellspacing='0' style='border:0px solid;font:13px arial' width='430' height='167' background='gui/busEmailBack.gif'>"+
		"<tr><td valign='top'><br><div style='margin-right:10px;color:#C26E96'>"+sent+"</div></td></tr>"+
		"<tr><td>"+
		"<div style='margin-right:10px;font:13px arial'></div>"+
		"</td></tr>"+
		"</table>";			
		document.getElementById("eForm").innerHTML=msgBody
		document.getElementById("eTitle").innerHTML=""			
		}
	}

}