function checkEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
		return true;
	}
	alert("Va rugam introduceti o adresa de e-mail valida.")
	return false;
}


function checkEmail2(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.customer_email.value)) {
		return true;
	}
	alert("Va rugam introduceti o adresa de e-mail valida.")
	return false;
}


function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	}
	else {
	   return true;
	}
}

function contact_form(url) {
	var popUpWidth = 496;
	var popUpHeight = 385;
	var popUpTop = (screen.height - popUpHeight) / 2;
	var popUpLeft = (screen.width - popUpWidth) / 2;
	window.open(url,'Contact', 'top='+popUpTop+',left='+popUpLeft+',height='+popUpHeight+',width='+popUpWidth+',scrollbars=no');
}

function popup(url, title, features) {
	window.open(url, title, features);
}

function focus(targetId) {
	document.getElementById(targetId).focus();
}

function toggle_cat(catid) {
	if(document.getElementById) {
		target = document.getElementById("cat" + catid);
		children = target.childNodes;

		for(var i = 0; i < target.childNodes.length; i++) {
			if(i > 1) {
				if(target.childNodes[i].style.display == "block") {
					target.childNodes[i].style.display = "none";
				}
				else {
					target.childNodes[i].style.display = "block";
				}
			}
		}
	}
}

function toggle_inline(targetId) {
	if(document.getElementById) {
		target = document.getElementById(targetId);

		if (target.style.display == "") {
			target.style.display = "none";
		}
		else {
			target.style.display = "";
		}
	}
}

function toggle( targetId ){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if (target.style.display == "block"){
			target.style.display = "none";
		}
		else {
			target.style.display = "block";
		}
	}
}

function decode_html(text) {
	var newtext = text.replace(/&amp;/g,"&");
	newtext = newtext.replace(/&lt;/g,"<");
	newtext = newtext.replace(/&gt;/g,">");
	newtext = newtext.replace(/<br \/>/g,"\r\n");
	newtext = newtext.replace(/<br \/>/g,"\n");
	newtext = newtext.replace(/<br \/>/g,"\r");
	newtext = newtext.replace(/<br>/g,"\r\n");
	newtext = newtext.replace(/<br>/g,"\n");
	newtext = newtext.replace(/<br>/g,"\r");
	newtext = newtext.replace(/&quot;/g,"\"");
	newtext = newtext.replace(/&#039;/g,"'");
	return(newtext);
}

function setState(which, state) {
	document.getElementById(which).style.display = state;
	if (self["timer"+which]!=null) clearTimeout(self["timer"+which]);
}

function explicatii( targetId, state ) {
	var states = new Array("none", "block");
	if (document.getElementById(targetId).style.display==states[state] && self["timer"+targetId]!=null)
		clearTimeout(self["timer"+targetId]);
	else {
		if (state==0)
			self["timer"+targetId]=setTimeout("setState('"+targetId+"', '"+states[state]+"')", 350);
		else
			setState(targetId, states[state]);
	}
}

function enlarge(img, w, h) {
	l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	window.open('/mareste/'+img+'/', 'enlargedimg', 'width='+w+',height='+h+',top='+t+',left='+l+',location=no,menubar=no,status=no,resizable=yes,scrollbars=no,toolbar=no');
}

function checkValid(id, msg, regula, valoare) {
	var prefix = "* ";
	var suffix = "\n";
	switch(regula) {
		case 'required':
						if (document.getElementById(id).value=="")
							return prefix+msg+suffix;
						break;
		case 'select':
						if (document.getElementById(id).options[document.getElementById(id).selectedIndex].value=="")
							return prefix+msg+suffix;
						break;
		case 'numeric':
						var validch = "0123456789.-";
						var isNumber=true;
						var ch;
						var val = document.getElementById(id).value;
						for (i=0; i<val.length && isNumber == true; i++) {
							ch = val.charAt(i);
							if (validch.indexOf(ch) == -1)
								return prefix+msg+suffix;
						}
						break;
		case 'email':
						var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'float':
						var filter=/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'integer':
						var validch = "0123456789";
						var isNumber=true;
						var ch;
						var val = document.getElementById(id).value;
						for (i=0; i<val.length && isNumber == true; i++) {
							ch = val.charAt(i);
							if (validch.indexOf(ch) == -1)
								return prefix+msg+suffix;
						}
						break;
		case 'limitpercent':
						if (document.getElementById(id).value<0 || document.getElementById(id).value>100)
							return prefix+msg+suffix;
						break;
		case 'notzero':
						if (document.getElementById(id).value==0)
							return prefix+msg+suffix;
						break;
		case 'date':
						msg = isDate(document.getElementById(id).value);
						if (msg != "0") {
							return prefix+msg+suffix;
						}
						break;
		case 'lessthan':
						if (document.getElementById(id).value > valoare)
							return prefix+msg+suffix;
						break;
	}
	return "";
}

function checkProfile() {
	msg = checkValid('firstname', 'Completati prenumele dvs.', 'required');
	msg += checkValid('lastname', 'Completati numele dvs.', 'required');
	msg += checkValid('telephone1', 'Completati numarul de telefon mobil', 'required');
	msg += checkValid('telephone1', 'Numarul de telefon mobil trebuie sa fie numeric', 'numeric');
	msg += checkValid('code', 'Completati CNP-ul', 'required');
	msg += checkValid('code', 'CNP-ul trebuie sa fie numeric', 'numeric');

	if (msg != '') {
		alert(msg);
		return false;
	}
	else {
		return true;
	}
}

function checkReqInfo() {
	msg = checkValid('customer_name', 'Completati numele dvs.', 'required');
	msg += checkValid('customer_email', 'Completati e-mailul dvs.', 'required');
	if(document.getElementById('customer_email').value != '') {
		msg += checkValid('customer_email', 'Introduceti o adresa de e-mail valida', 'email');
	}
	msg += checkValid('request', 'Nu ati completat informatiile dorite', 'required');

	if (msg != '') {
		alert(msg);
		return false;
	}
	else {
		return true;
	}
}

function tab(prefix,which) {
	max = 20;
	for(i=1; i<=max; i++) {
		if(document.getElementById('tab'+prefix+i)) {
			$("#tab"+prefix+i).hide();
			$("#tabanch"+prefix+i+" span").removeClass("tabtitlefocused");
			$("#tabanch"+prefix+i+" span").addClass("tabtitleunfocused");
		}
	}
	$("#tabanch"+prefix+which+" span").removeClass("tabtitleunfocused");
	$("#tabanch"+prefix+which+" span").addClass("tabtitlefocused");
	$("#tab"+prefix+which).show();
}