function checkContactForm(){

	re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;

	var email, subject, txt_message, vercode, dataRight = true;

	message = "";

	name = document.contactFrm.name.value;

	email = document.contactFrm.email.value;

	subject = document.contactFrm.subject.value;

	txt_message = document.contactFrm.message.value;

	vercode = document.contactFrm.vercode.value;

	

	if (name.length==0){

	   message += "\n -  Name";

	   dataRight=false;

	}

	if (email.length==0){

	   message += "\n -  E-mail address";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Your E-Mail is Incorrect";

	}

	if (subject.length==0){

		message += "\n -  About";

		dataRight=false;

	}

	if (txt_message.length==0){

		message += "\n -  Message";

		dataRight=false;

	}

	if (vercode.length==0){

		message += "\n -  Verification code";

		dataRight=false;

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nYou failed to correctly fill in the form:\n" + message + "\n\nPlease re-enter and click the Send button again!";

	   }

	   alert(message);

	}

	return dataRight;

}



function checkContactFormRU(){

	re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;

	var email, subject, txt_message, vercode, dataRight = true;

	message = "";

	name = document.contactFrm.name.value;

	email = document.contactFrm.email.value;

	subject = document.contactFrm.subject.value;

	txt_message = document.contactFrm.message.value;

	vercode = document.contactFrm.vercode.value;

	

	if (name.length==0){

	   message += "\n -  Имя";

	   dataRight=false;

	}

	if (email.length==0){

	   message += "\n -  Введите свой E-mail";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Неправильно введенный E-mail адрес";

	}

	if (subject.length==0){

		message += "\n -  О";

		dataRight=false;

	}

	if (txt_message.length==0){

		message += "\n -  Сообщение";

		dataRight=false;

	}

	if (vercode.length==0){

		message += "\n -  Код для подтверждения";

		dataRight=false;

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nФорма заполнена неверно:\n" + message + "\n\nПожалуйста заполните снова и нажмите кнопку „Отправить”!";

	   }

	   alert(message);

	}

	return dataRight;

}



function checkContactFormBG(){

	var re =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	var name, email, txt_message, vercode, dataRight = true;

	message = "";

	

	name = document.contactFrm.name.value;

	email = document.contactFrm.email.value;

	txt_message = document.contactFrm.message.value;

	vercode = document.contactFrm.vercode.value;

	

	if (name.length==0){

	   message += "\n -  Моля въведете Име";

	   dataRight=false;

	}

	if (email.length==0){

	   message += "\n -  Моля въведете E-mail";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Въведеният E-Mail е грешен";

	}

	if (txt_message.length==0){

		message += "\n -  Моля въведете Съобщение";

		dataRight=false;

	}

	if (vercode.length==0){

		message += "\n -  Моля въведете Код за потвърждение";

		dataRight=false;

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nНе сте въвели коректно всички полета от формата:\n" + message + "\n\nМоля въведете отново сгрешените полета и натиснете бутона 'Изпрати'!";

	   }

	   alert(message);

	}

	return dataRight;

}



function validateMail(inputobj, elemid, minChars, regValidation) {

	  var message = "";

	  var regExp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	  var flagerror = false;



	  if(inputobj.value.length < minChars)

	  {

		message="Полето тябва да е поне " + minChars + " символ" + ((minChars==1)?".":"а.");

		flagerror = true;

	  }



	  if(!(regExp.test(inputobj.value) && regValidation) )

	  {

		message +="Enter valid e-mail.";

		flagerror = true;

	  }



	  if( flagerror) 

	  {

		message = "Error: " + message;

		var elem = document.getElementById(elemid);

		var elem_ = document.getElementById(elemid + "_");

		elem.style.display = 'inline';

		elem_.style.display = 'inline';

		elem.innerHTML = message;

	  }

	  else 

	  {

		var elem = document.getElementById(elemid);

		var elem_ = document.getElementById(elemid + "_");

		elem.style.display = 'none';

		elem_.style.display = 'none';

	  }

}



function clearText(clear_id) {

	document.getElementById(clear_id).value = '';

}

	

function show_panel(show,butt,text){

	if(document.getElementById(show).style.display == 'none') {

		document.getElementById(show).style.display = 'inline';

		document.getElementById(butt).value = 'hidden '+text;		

	}	

	else {

		document.getElementById(show).style.display = 'none';

		document.getElementById(butt).value = 'show '+text;				

	}	

}



function show_panel_add(show){

	if(document.getElementById(show).style.display == 'none') {

		document.getElementById(show).style.display = 'inline';

		//document.getElementById(butt).value = 'hidden '+text;		

	}	

	else {

		document.getElementById(show).style.display = 'none';

		//document.getElementById(butt).value = 'show '+text;				

	}	

}



function hide_panel(hide) {

	document.getElementById(hide).style.display = 'none';

}



function show_old() {

	if(document.getElementById('search_type').value == 'time')

		show_panel('old');

	else

		hide_panel('old');

}



var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)

var bustcacheparameter="";



function createRequestObject(){

	try	{

		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

	}	catch(e)	{

		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');

	};

	return xmlhttp;

};



function ajaxpage(url, containerid, requesttype){

	var page_request = createRequestObject();

	if (requesttype=='get'){

		if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

		page_request.open('GET', url+bustcacheparameter, true)

		page_request.send(null)

	} else if (requesttype=='post') {

		page_request.open('POST', url, true);

		page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

		page_request.setRequestHeader("Content-length", poststr.length);

		page_request.setRequestHeader("Connection", "close");

		page_request.send(poststr);

	};



	page_request.onreadystatechange=function(){

		loadpage(page_request, containerid)

	}



}



function loadpage(page_request, containerid){

	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {

		document.getElementById(containerid).innerHTML=page_request.responseText;

	};

}







function checkRentForm(){

	re = /([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)/;

	var email,  dataRight = true;

	message = "";



	email = document.frm.email.value;

	

	if (email.length==0){

	   message += "\n -  E-mail address";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Your E-Mail is Incorrect";

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nYou failed to correctly fill in the form:\n" + message + "\n\nPlease re-enter and click the Send button again!";

	   }

	   alert(message);

	}

	return dataRight;

}



function checkRentFormRU(){

	re = /([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)/;

	var email, dataRight = true;

	message = "";



	email = document.frm.email.value;



	if (email.length==0){

	   message += "\n -  Введите свой E-mail";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Неправильно введенный E-mail адрес";

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nФорма заполнена неверно:\n" + message + "\n\nПожалуйста заполните снова и нажмите кнопку „Отправить”!";

	   }

	   alert(message);

	}

	return dataRight;

}



function checkRentFormBG(){

	var re =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	var email, dataRight = true;

	message = "";

	

	email = document.frm.email.value;

	

	if (email.length==0){

	   message += "\n -  Моля въведете E-mail";

	   dataRight=false;

	}

	if (email.length!=0 && email.match(re)==null){

	   dataRight=false;

	   message += "\n -  Въведеният E-Mail е грешен";

	}

	

	if (!dataRight){

		if (message != ""){

		   message ="\nНе сте въвели коректно всички полета от формата:\n" + message + "\n\nМоля въведете отново сгрешените полета и натиснете бутона 'Изпрати'!";

	   }

	   alert(message);

	}

	return dataRight;

}

var $ = function(elem)
{
	return document.getElementById(elem);	
}

function check_payment(frm, lang)
{
	if (!frm) return;
	var inputs = frm.getElementsByTagName('input');
	var i = 0;
	var toValidate = true;
	
	while (inputs[i])
	{
		if (inputs[i].type == "hidden") 
		{
			i++;
			continue;
		}
		if ((inputs[i].value == "") || (inputs[i].value == "0.00"))
		{
			toValidate = false;
		}
		i++;	
	}
	
	var okurl = $('ok_return_url');
	okurl.value = 'http://orco.bg/paymentsuccess.php?n=' + $('name').value + '&e=' + $('email').value + '&t=' + $('phone').value + '&a=' + $('address').value + '&p=' + $('amount').value + '&d=' + $('notes').value + '&lang=' + lang;
	$('description').value = $('notes').value;
	var okstr = okurl.value;	
	okurl.value = okstr.substr(0, 254);
	
	if (toValidate == false)
	{
		if (lang == "bg") alert("Моля попълнете всички задължителни полета обозначени с *");	
		if (lang == "en") alert("Please fill in all the fields marked with *");	
		if (lang == "ru") alert("Пожалуйста, заполните все обязательные поля, отмеченные *");	
	}
	return toValidate;
}

