function checkValid(id, msg, regula) {
	switch(regula) {
		case 'zona':
			if ( (!document.getElementById('zona1').checked) && (!document.getElementById('zona2').checked) && (!document.getElementById('zona3').checked) && (!document.getElementById('zona4').checked) )
				return msg;
		
		break;
		
		case 'required':
						if (document.getElementById(id).value=="")
							return msg;
						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 msg;
						}
						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 msg;

						break;

	}

	return "";

}
function verificaFormular(care) {
	msg = "Va rugam completati urmatoarele campuri:\n";
	msg += "______________________________________________________\n";
	msg += "\r\n";

	switch(care) {

		case "register":

					msg1 = "";

					msg1 += checkValid("email_login", "E-mailul pentru contul dvs.\r\n", "required");

					msg1 += checkValid("parola_login", "Parola pentru contul dvs.\r\n", "required");

					msg1 += checkValid("email_login", "Adresa de e-mail pentru contul dvs trebuie sa fie valida.\r\n", "email");

					msg1 += checkValid("nume_hotel", "Numele unitatii.\r\n", "required");
										
					msg1 += checkValid("pret_camera", "Pretul/camera pornind de la ...\r\n", "required");
					
					msg1 += checkValid("judet1", "Judetul. \r\n", "required");
					
					msg1 += checkValid("oras1", "Orasul. \r\n", "required");
					
					msg1 += checkValid("adresa_unitate", "Adresa unitatii. \r\n", "required");
					
					msg1 += checkValid("descriere_scurta", "Scurta descriere. \r\n", "required");
					
					msg1 += checkValid("zona", "Zona. \r\n", "zona");

					msg1 += checkValid("nume_contact", "Numele persoanei de contact. \r\n", "required");
					
					msg1 += checkValid("telefon_contact", "Telefonul persoanei de contact. \r\n", "required");
					
					break;

		case "newsletter":
					msg1 = "";

					msg1 += checkValid("newsletter", "Adresa de e-mail pentru newsletter.\r\n", "required");
					
					msg1 += checkValid("newsletter", "Adresa de e-mail pentru newsletter trebuie sa fie valida.\r\n", "email");


					break;					

		case "modifica":

					msg1 = "";

					msg1 += checkValid("nume_hotel", "Numele unitatii.\r\n", "required");
					
					msg1 += checkValid("nr_camere", "Numarul de camere.\r\n", "required");
					
					msg1 += checkValid("pret_camera", "Pretul/camera pornind de la ...\r\n", "required");
					
					msg1 += checkValid("tarife", "Tarife. \r\n", "required");

					msg1 += checkValid("judet1", "Judetul. \r\n", "required");
					
					msg1 += checkValid("oras1", "Orasul. \r\n", "required");
					
					msg1 += checkValid("adresa_unitate", "Adresa unitatii. \r\n", "required");
					
	}

	if (msg1!="") {

		alert(msg+msg1);

		return false;

	}
	return true;
}

//vizualizare foto
var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
    winFeatures = "," + winFeatures
  else 
    winFeatures = "" 
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth 
           + ",height=" + winHeight + winFeatures)
  }
function closePopWin(){    // close pop-up window if it is open 
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close() 
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft	
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }
//-->
function popMsg(id, vezi){
  openPopWin("http://www.centrefrumusete.ro/vezifoto.php?idfoto="+id+"&view="+vezi, 650, 650) 
  popWin.document.close()
  }
  
  function veziOS(id){
  openPopWin("vezioferta.php?oferta="+id, 650, 560,"scrollbars=0") 
  popWin.document.close()
  }
  
  function veziUnitate(id){
  openPopWin("veziunitate.php?unitate="+id, 650, 560,"scrollbars=1") 
  popWin.document.close()
  }
  
function getOrase(){
	var judet = $F('judet');
	var url = 'http://www.centrefrumusete.ro/getOrase.php?judet='+judet;
	new Ajax.Updater('orascontainer', url,
	{
		method: 'get',
		onLoading: function(){

		},
		onLoaded: function(){

		}
	});

}

function getOraseUnitati(){
	var judet = $F('judet');
	var url = 'http://www.centrefrumusete.ro/getOraseUnitati.php?judet='+judet;
	new Ajax.Updater('orascontainer', url,
	{
		method: 'get',
		onLoading: function(){

		},
		onLoaded: function(){

		}
	});

}

function getSortOrase(){
	var judet = $F('judet');
	var url = 'http://www.centrefrumusete.ro/getOrase.php?judet='+judet+'&sort=1';
	new Ajax.Updater('orascontainer', url,
	{
		method: 'get',
		onLoading: function(){
		},
		onLoaded: function(){
		}
	});

}

function getSortOrase2(selected){
	var judet = $F('judet');
	var url = 'http://www.centrefrumusete.ro/getOrase2.php?judet='+judet+'&sort=1&selected='+selected;
	new Ajax.Updater('orascontainer', url,
	{
		method: 'get',
		onLoading: function(){
		},
		onLoaded: function(){
		}
	});

}

function sorteaza(tip){
	if (((document.getElementById('judet')).value!='')&& (document.getElementById('oras').value!='')){
	window.location='http://www.centrefrumusete.ro/'+tip+'/'+document.getElementById('oras').value;
	}else if (((document.getElementById('judet').value)!='')&& (document.getElementById('oras').value=='')){
	window.location='http://www.centrefrumusete.ro/'+tip+'/judet/'+document.getElementById('judet').value;
	}
	else 
	alert("Nu ati selectat judetul");
	
}

function getOraseModifica(sel){
	var judet = $F('judet');
	var url = 'http://www.centrefrumusete.ro/getOraseMod.php?judet='+judet+"&sort=1&sel="+sel;
	new Ajax.Updater('orascontainer', url,
	{
		method: 'get',
		onLoading: function(){

		},
		onLoaded: function(){

		}
	});
}
