// JavaScript Document
ron = 10000;
var tipobj;

function initial(){
	if (!tipobj) tipobj = getElem("dhtmltooltip");
}

/////////////////////////////////////////////////////////////////
function getElem(elemID){
	var obj;
	if (document.all){
		obj = document.all(elemID)
	}else if (document.getElementById){
		obj = document.getElementById(elemID)
	}else if (document.layers){
		obj = document.layers[elemID]
	}
	return obj;
}

/////////////////////////////////////////////////////////////////
function validate_login_main(frm){
	if (frm.email.value == ""){
		alert('Introduceti adresa de email !');
		frm.email.focus();
		return false;
	}else if (!checkEmail(frm.email.value)){
		alert('Adresa de email este invalida!');
		frm.email.select();
		return false;
	}else if (frm.parola.value == ""){
		alert('Introduceti parola!');
		frm.parola.focus();
		return false;
	}
	
	frm.action = "login.php";
	frm.submit();
}

/////////////////////////////////////////////////////////////////
function validate_news(frm){
	if (frm.email_news.value == ""){
		alert('Introduceti adresa de email !');
		frm.email_news.focus();
		return false;
	}else if (!checkEmail(frm.email_news.value)){
		alert('Adresa de email este invalida!');
		frm.email_news.select();
		return false;
	}
	frm.action = "newsletter.php";
	frm.submit();
}

/////////////////////////////////////////////////////////////////
function checkEmail(email){
	var regex = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,4}$/ 
	if (!regex.test(email)) return false; 
	return true; 
} 	

/////////////////////////////////////////////////////////////////
function validare_parere(frm,n){
	for (i=1; i<=n; i++){
		id_criteriu = getElem("id_"+i).value;
		suma = 0;
		for (j=0; j<5; j++) suma += frm.elements[id_criteriu][j].checked;
		if (suma==0){
			alert("Selectati o nota pentru fiecare criteriu!");
			return false;
		}
	}
	
	if (frm.nume.value == ""){
		alert('Introduceti numele !');
		frm.nume.focus();
		return false;
	}else if (frm.email.value != "" && !checkEmail(frm.email.value)){
		alert('Adresa de email este invalida !');
		frm.email.select();
		return false;
	}else if (frm.parere.value == ""){
		alert('Scrieti parerea dumneavoastra !');
		frm.parere.select();
		return false;
	}
	
	return true;
}

/////////////////////////////////////////////////////////////////
function resize(){
	width = getElem('poza').width;
	getElem('td_poza').width = width;
}

/////////////////////////////////////////////////////////////////
function validare_recomanda(frm){
	if (frm.email_vizitator.value==""){
		alert("Introduceti adresa dumneavoastra de email.");
		frm.email_vizitator.focus();
		return false;
	}else if (!checkEmail(frm.email_vizitator.value)){
		alert('Adresa de email este invalida!');
		frm.email_vizitator.select();
		return false;
	}else if (frm.email_prieten.value==""){
		alert("Introduceti adresa de email.");
		frm.email_prieten.focus();
		return false;
	}else if (!checkEmail(frm.email_prieten.value)){
		alert('Adresa de email este invalida!');
		frm.email_prieten.select();
		return false;
	}
	return true;
}

/////////////////////////////////////////////////////////////////

	function checkPrice(price){
		var regex = /^[\d]+(\.[\d]{1,2})?$/ 
		if (!regex.test(price)) return 0; 
		return price; 
	} 	

/////////////////////////////////////////////////////////////////

function pop_harta(){
	window.open('pop_up_image.php?harta=1','pop_img','scrollbars=no,height=460,width=490,resizable=yes');
}

/////////////////////////////////////////////////////////////////
function show_pagina(nr){
	var n = 6;
	for (i=1; i<=n; i++){
		if (i==nr){
			if (getElem('pagina_'+i)) showByID('pagina_'+i);
			if (getElem('tag_'+i)) getElem('tag_'+i).className = "buton_apasat";
		}else{
			if (getElem('pagina_'+i)) hideByID('pagina_'+i);
			if (getElem('tag_'+i)) getElem('tag_'+i).className = "";
		}
	}
//	getElem('cumpara_acum').focus();
}

///////////////////////////////////////////////////////////////
function hideByID(ID){
	if (getElem(ID)){getElem(ID).style.display = "none";}
	else if (ID){
		d = ID.split(",");
		for (i=0,n=d.length; i<n; i++){
			if (getElem(d[i])){getElem(d[i]).style.display = "none";}
		}
	}
}

///////////////////////////////////////////////////////////////
function showByID(ID){
	if (getElem(ID)){getElem(ID).style.display = "";}
	else if (ID){
		d = ID.split(",");
		for (i=0,n=d.length; i<n; i++){
			if (getElem(d[i])){getElem(d[i]).style.display = "";}
		}
	}
}

///////////////////////////////////////////////////////////////
function open_imagini(IDProdus, IDImagine){
	window.open('pop_up_image.php?IDProdus='+IDProdus+'&IDImagine='+IDImagine,'pop_img','scrollbars=no,height=250,width=350,resizable=yes');
}

///////////////////////////////////////////////////////////////
function open_mostre(IDProdus, IDMostra){
	window.open('pop_up_image.php?IDProdus='+IDProdus+'&IDMostra='+IDMostra,'pop_img','scrollbars=no,height=250,width=350,resizable=yes');
}

/////////////////////////////////////////////////////////////
function open_compara(IDProdus){
	window.open('compara.php?IDProdus='+IDProdus,'compara','scrollbars=yes,height=600,width=800,resizable=yes');
}

/////////////////////////////////////////////////////////////
function validate_cautare(frm){
	if (frm.key.value.length < 3){ 
		alert ("Introduceti un cuvant de cel putin 3 caractere!");
		frm.key.select();
		return false;
	}
	frm.action = "cauta.php";
	frm.method = "get";
	frm.submit();
}

/////////////////////////////////////////////////////////////
/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=0; //Customize x offset of tooltip
var offsetypoint=20; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

/////////////////////////////////////////////////////////////
function ddrivetip(thetext, thecolor, thewidth){
	if (ns6||ie){
//		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
//		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML=thetext;
		enabletip=true;
		return false;
	}
}

/////////////////////////////////////////////////////////////
function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px";
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
		else
			tipobj.style.top=curY+offsetypoint+"px";
		tipobj.style.visibility="visible";
	}
}

/////////////////////////////////////////////////////////////
function hideddrivetip(){
	if (ns6||ie){
		enabletip=false;
		tipobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
//		tipobj.style.backgroundColor='';
		tipobj.style.width='';
		}
}

document.onmousemove=positiontip;
