function submitForm() {
	updateRTEs();
	return true;
}

function openConnection() {
	req = false;
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	}

	if (window.ActiveXObject && !req) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	
	return req;
}


function sendMail(id) {
	//alert(smes + emes);
						msg=""
						if (document.mform.priority.checked ){
							document.mform.priority.value = 'Yes';
						}
						if (document.mform.name.value == ""){
							msg+="Name is missing.\n"
						}
						if (document.mform.company.value == ""){
							msg+="Company is missing.\n"
						}
						
						if (document.mform.phone.value == ""){
							msg+="Phone is missing.\n"
						}
						if (document.mform.email.value == ""){
							msg+="Email is missing.\n"
						}
						else 
						{
							apos=document.mform.email.value.indexOf("@");
							dotpos=document.mform.email.value.lastIndexOf(".");
							if (apos<1||dotpos-apos<2) 
							  {
							  		msg+="Email is incorrect.\n"
							  }
						}
						if (document.mform.comment.value == ""){
							msg+="Commment is missing.\n"
						}
						
						if (msg!=""){
							alert(msg);
							$('#errorMessage').removeClass('hidden');
							$('#successMessage').addClass('hidden');
							return false
						}
						else 
						{ 
							document.mform.submit();
						}
	}
	
	
function sendNewsletter(id) {
	//alert(smes + emes);
						msg=""
						if(document.getElementById('1').checked)
						{
							if (document.newsletter.name.value == ""){
								msg+="Name is missing.\n"
							}
							if (document.newsletter.email.value == ""){
								msg+="Email is missing.\n"
							}
							else 
							{
								apos=document.newsletter.email.value.indexOf("@");
								dotpos=document.newsletter.email.value.lastIndexOf(".");
								if (apos<1||dotpos-apos<2) 
								  {
								  		msg+="Email is incorrect.\n"
								  }
							}
						}
						else if(document.getElementById('2').checked)
						{
							if (document.newsletter.mol.value == ""){
								msg+="Name is missing.\n"
							}
							if (document.newsletter.company.value == ""){
								msg+="Company is missing.\n"
							}
							
							if (document.newsletter.position.value == ""){
								msg+="Position is missing.\n"
							}
							if (document.newsletter.comp_email.value == ""){
								msg+="Email is missing.\n"
							}
							else 
							{
								apos=document.newsletter.comp_email.value.indexOf("@");
								dotpos=document.newsletter.comp_email.value.lastIndexOf(".");
								if (apos<1||dotpos-apos<2) 
								  {
								  		msg+="Email is incorrect.\n"
								  }
							}
						}
						
						if (msg!=""){
							alert(msg);
							$('#errorMessage').removeClass('hidden');
							$('#successMessage').addClass('hidden');
							return false
						}
						else 
						{ 
							document.newsletter.submit();
						}
	}

	function checkLoginName(name) 
	{
		//alert(name.value);
		var login = name.value;
			ajaxo = openConnection();
			if (!ajaxo) return false;
	
			ajaxo.onreadystatechange = function () {
				if (ajaxo.readyState == 4) {
					if(ajaxo.responseText == 1) {
						alert('Потребителско име: '+login+' е заето!');
						name.focus();
					}
				}
				return true;
			}
	
			ajaxo.open("GET", "checkuser.php5?login="+login, true);
			ajaxo.send(null);
	}