function SubmitFormMail(nextStep,type) {


	var tError;
	if (type=='Mail') { tError=CheckInputMail(); }
	if (type=='Phone') { tError=CheckInputPhone(); }
	if (type=='Friend') { tError=CheckInputFriend(); }
	if (tError.length> 0) {
		alert ("Please fill the following fields in correctly:\n\n"+tError);
	}else{

		getContent(nextStep,'dinamic_survey','ajax');
	}
}

function CheckInputPhone() {
	var Error=''
	if (document.forms['contactform'].country.value.length < 2)
		Error=Error+"* Country\n";
	if (document.forms['contactform'].location.value.length < 2)
		Error=Error+"* Location\n";
	return Error;
}
						
function CheckInputMail() {
	var Error=''
	if (document.forms['contactform'].name.value.length < 2)
		Error=Error+"* Name\n";
	if (!CheckEmailForm (document.forms['contactform'].email.value))
		Error=Error+"* E-mail\n";

	if(!Checktelephone())	
		Error=Error+"* Telephone should be numeric\n";
	
	return Error;
}

function CheckInputFriend() {
	var Error=''
	if (document.forms['contactform'].name.value.length < 2)
		Error=Error+"* Name\n";
	if (!CheckEmailForm (document.forms['contactform'].email.value))
		Error=Error+"* E-mail\n";
	if (document.forms['contactform'].friendname.value.length < 2)
		Error=Error+"* Friend Name\n";
	if (!CheckEmailForm (document.forms['contactform'].friendemail.value))
		Error=Error+"* Friend E-mail\n";
	if (document.forms['contactform'].subject.value.length < 2)
		Error=Error+"* Subject\n";
		
		
	return Error;
}
								
function CheckEmailForm (What) {
	What=""+What;
	Ret = true;
	if (What.length < 3) {
		Ret=false;
	}
	if (What.indexOf("@") < 0) {
		Ret=false;
	}
	if (What.indexOf(".") < 0) {
		Ret=false;
	}
	return Ret;
}

function ReplaceNewLines (myinput) {

	var savelastbreak=0;
	var output="";
	for (var i=0; i<myinput.length; i++) {
		if ((myinput.charCodeAt(i)==13) || (myinput.charCodeAt(i)==10)) {
			if (myinput.charCodeAt(i)==10)
				output=output+"<br>";
		}else{
			output=output+myinput.substr(i,1);
		}
	}
	
	return output;
}
			
function Checktelephone()
{
	var ret = true;

	  if(document.forms['contactform'].tel.value!="") 
	 	 if (isNaN(document.forms['contactform'].tel.value))
	   		ret = false;
  
 	return ret;       
}
