function checkFieds(FormName,RequiredFields)
{
var FieldList = RequiredFields.split(",");
var BadList = new Array();
var meil = true;
var tel = true;
var finalCall = false;
for(var i = 0; i < FieldList.length; i++) {
	var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');
	s = StripSpacesFromEnds(s);

	if(s.length < 1) {  BadList.push(FieldList[i]); }
	if((FieldList[i]=='cnt_mail') && (s.length > 1))
	{
		meil = isEmail(s);
	}
	if((FieldList[i]=='telefon') && (s.length > 1))
	{
		tel = IsNumeric(s);
		
	}
	}
if((BadList.length < 1) && (meil) && (tel)){finalCall =  true; }

var message = new String();
if(BadList.length > 0) {
for(var i = 0; i < BadList.length; i++) 
	{ 
		if(BadList[i]=='cnt_nume')
			{ message += '\n' + 'Campul "nume" este obligatoriu'; }
		if(BadList[i]=='cnt_sub')
			{ message += '\n' + 'Campul "subiect" este obligatoriu'; }
		 if(BadList[i]=='cnt_mesaj')
			{ message += '\n' + 'Campul "mesaj" este obligatoriu'; }
		 if(BadList[i]=='telefon')
			{ message += '\n' + 'Campul "telefon" este obligatoriu'; }
		if(BadList[i]=='cnt_mail')
			{ message += '\n' + 'Campul "e-mail" este obligatoriu'; }
		if(BadList[i]=='adresa_rezervari')
			{ message += '\n' + 'Campul "adresa" este obligatoriu'; }
		if(BadList[i]=='subiect_contact')
			{ message += '\n' + 'Campul "subiect" este obligatoriu'; }
		if(BadList[i]=='detalii_contact')
			{ message += '\n' + 'Campul "detalii" este obligatoriu'; }
	}//endwhile
	
}//endif badlist	
if(!meil)	{
	finalCall = false;
	message += '\n' + 'Adresa de email e gresita';
}

if(!tel)	{
	finalCall = false;
	message += '\n' + 'Numar de telefon invalid';
}

if(finalCall==false)
{
	alert(message);
	return false;
} else
	{
		return true;
	}
//return message;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function GetItRelocateAdm(locatie,idList)
{
	var FieldList = idList.split(",");
	var fields = new Array();
	var queryString = new String();
	var j=0;
	for(var i = 0; i < FieldList.length; i++)
	{
		//getField = eval("field"+i);
		fields[i] = document.getElementById(FieldList[i]).value;
		j++;
		queryString = queryString + "&field" +j + "=" + fields[i];
	}
	fullLoc = locatie + queryString;
	self.location=fullLoc;	
	
}

function StripSpacesFromEnds(s)
{
	while((s.indexOf(' ',0) == 0) && (s.length> 1)) {
		s = s.substring(1,s.length);
		}
	while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {
		s = s.substring(0,(s.length - 1));
		}
	if((s.indexOf(' ',0) == 0) && (s.length == 1)) { s = ''; }
	return s;
}

function relocate(locatie)
{
	self.location=locatie;
}

function changeOrder(locatie,id)
{
	var toMod = document.getElementById(id).value;
	self.location=locatie + "&toMod=" + toMod;
}

function apritisesamo(dove,nome,caratteristiche) {
  window.open(dove,nome,caratteristiche);
}

function assignBigger_height(id1,id2)
{
	var div_1 = document.getElementById(id1);
	var div_2 = document.getElementById(id2);
	
	//alert(div_1.offsetHeight+" "+div_2.offsetHeight);
	if(div_1.offsetHeight>div_2.offsetHeight)
	{
		div_2.style.height = div_1.offsetHeight-15 + "px";
	} else
		{
			div_1.style.height = div_2.offsetHeight-15 + "px";
		}
	
}

function shadow(id1,id2,pic_name,nr_t)
{
	var div_1 = document.getElementById(id1);
	var div_2 = document.getElementById(id2);
	
	if((pic_name=='umbra_left_tcols') && (nr_t==1))
	{
			document.write("<img src='img/"+pic_name+"_strong.jpg'>");
	} else
	{
	
		//alert(div_1.offsetHeight+" "+div_2.offsetHeight);
		if(div_1.offsetHeight>div_2.offsetHeight)
		{
			document.write("<img src='img/"+pic_name+"_strong.jpg'>");
		} else
			{
				if((div_1.offsetHeight==div_2.offsetHeight)&&(nr_t==2))
				{
					document.write("<img src='img/"+pic_name+"_strong.jpg'>");
				} else
					{
						document.write("<img src='img/"+pic_name+"_light.jpg'>");
					}
			}
	}
	
}

function go_to_page(my_link,my_id,my_max)
{
	my_value = document.getElementById(my_id).value;
	my_value = parseInt(my_value);
	if(my_value<1)
	{
		my_value = 1;	
	}
	if(my_value>my_max)
	{
		my_value = my_max;	
	}
	self.location = my_link + my_value;
}

function home_events(id_1_da,id_1_nu,id_2_da,id_2_nu,id_to_show)
{
	var show_it = false;
	var radio_1_da = document.getElementById(id_1_da);
	var show_tr = document.getElementById(id_to_show);	
	if(radio_1_da.checked==true)
	{
		show_it = true;
		var radio_2_nu = document.getElementById(id_2_nu);
		radio_2_nu.checked = true;
	} else
		{
			var radio_2_da = document.getElementById(id_2_da);
			if(radio_2_da.checked==true)
			{
				show_it = true;
			}
		}
	if(show_it)
	{
		show_tr.style.display = "";
	} else
		{
			show_tr.style.display = "none";
		}
}
function schimbare(id_1_da)
{
	var radio_1_da = document.getElementById(id_1_da);
	if(radio_1_da.checked==true)
	{
		document.getElementById('iarschimbare').style.display = "";	
	} else
		{
			document.getElementById('iarschimbare').style.display = "none";	
		}
}

function filtru(locatie,aid)
{
//	var my_value = document.getElementById(aid).value;
	self.location = locatie;
}

function show_smth(aid)
{
	if(document.getElementById('bcom')!=null)
	{
		document.getElementById('bcom').style.display = "none";
	}
	var my_show = document.getElementById(aid);
	my_show.style.display = "";
}

function load_new_pic(new_pic,old_pic,id,id_pic,watermark,titlu,responseDiv,type)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(responseDiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			return true;
		} 
	}
//	var reg_tel =  eval('document.reg_toSite.reg_tel' + '.value'); 
		var queryString = "?new_pic=" + new_pic + "&id=" + id + "&id_pic=" + id_pic + "&watermark=" + watermark + "&old_pic=" + old_pic + "&titlu=" + titlu + "&type=" + type;
		ajaxRequest.open("GET", "include/new_pic.php" + queryString, true);
		ajaxRequest.send(null); 	
}

function ajaxRating(what,id_what,ajaxDiv,rating){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(ajaxDiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	var queryString = "?rating=" + rating + "&what=" + what + "&id_what=" + id_what;
	ajaxRequest.open("GET", "include/vote.php" + queryString, true);
	ajaxRequest.send(null); 
}

function adaugaComm(divId,id_sec,sec)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(divId);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			setTimeout("location.reload(true);",3000);
		}
	}
		
	// var comBtn =  document.getElementById('addComBtn');	
	 //comBtn.value = "Se adauga...";
	 var autor =  document.getElementById('autor_comm');
	 var text =  document.getElementById('corp_comm');
	 var email =  document.getElementById('email');
	 var ws =  document.getElementById('ws');

		var queryString = "?autor=" + autor.value + "&text=" + text.value + "&id_sec=" + id_sec + "&sec=" + sec + "&email=" + email.value + "&ws=" + ws.value;
		ajaxRequest.open("GET", "include/addCom.php" + queryString, true);
		ajaxRequest.send(null); 	
}

function getComments(divId,limit,pagenr,id_sec,sec)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(divId);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
		
	 //var comBtn =  document.getElementById('addComBtn');	
	 //comBtn.value = "Se adauga...";
	// var limit =  document.getElementById('autor_comm');
	 //var text =  document.getElementById('corp_comm');
		var queryString = "?limit=" + limit + "&pagenr=" + pagenr + "&id_sec=" + id_sec + "&sec=" + sec + "&divId=" + divId;
		ajaxRequest.open("GET", "include/getCom.php" + queryString, true);
		ajaxRequest.send(null); 		
	
	
}

function m_fil(m_value,aid)
{
	var osd = document.getElementById(aid);
	osd.value = m_value;	
}

function make_invizible(aid)
{
	var s_aid = "cb_"+aid;
	var my_inp = document.getElementById(aid);
	var s_my_inp = document.getElementById(s_aid);
	if(s_my_inp.checked==true)
	{
		my_inp.value = "-";
		my_inp.disabled = true;
	} else
		{
			my_inp.value = "";
			my_inp.disabled = false;
		}
}

function open_n_add(aid_nr, aid_nume,m_text,aid_alr,aid_mname)
{
	var my_nr = document.getElementById(aid_nr).value;
	var my_nume = document.getElementById(aid_nume).value;
	var my_mname = document.getElementById(aid_mname).value;
	var my_alr = document.getElementById(aid_alr).value;
	var my_titlu = m_text + my_nume;
	var my_window = "include/new_win.php?nr="+my_nr+"&titlu="+my_titlu+"&my_alr="+my_alr+"&mname="+aid_mname;
	window.open(my_window,"Adauga","status=0,toolbar=0,location=0,menubar=0,width=450,height=550,scrollbars=1");
	
}

function adauga_m(id_s,contor,already,aid_to)
{
	var new_already = new String;
	already = StripSpacesFromEnds(already);
	if(already.length>0)
	{
		already = already+",";	
	}
	for(var i=0;i<=contor;i++)
	{
		var new_aid = id_s+"_"+i;
		var as = document.getElementById(new_aid);
		if(as!=undefined)
		{
			new_already = new_already+as.value+",";
		}
	}
	new_already = new_already.substr(0,new_already.length-1);
	already = already+new_already;
	var div_to = window.opener.document.getElementById(aid_to).value = already;
	window.close();
//	div_to.value = already;
}

function hideDiv(aid)
{
	var hide_div =  document.getElementById(aid);
	hide_div.style.display = "none";
}

function showDiv(aid)
{
	var show_div =  document.getElementById(aid);
	show_div.style.display = "";
}

function limitChar(textarea,limit,infodiv)
{
	var textv = textarea.value;
	var textvLength = textv.length;
	var displayTo = document.getElementById(infodiv);
	
	if(textvLength>limit)
	{
		displayTo.innerHTML = "0 caractere ramase";
		textarea.value = textv.substr(0,limit);
	} else
		{
			displayTo.innerHTML = limit-textvLength+" caractere ramase";
		}	
}

function searchIt(aid)
{
	var toSearch = document.getElementById(aid).value;
	self.location = "index.php?pag=cauta&word="+toSearch;
}

function searcIta()
{
	var toSearch = document.getElementById('cautaa').value;
	var sct = "";
	for(i=1;i<=9;i++)
	{
		build = "s"+i;
		var selec = document.getElementById(build);
		if(selec.checked==true)
		{
			sct = sct+"&"+build+"=1";
		}
	}
	self.location="index.php?pag=cauta&ca=true&sect="+sct+"&word="+toSearch;;
}

function upd(id)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(divId);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			setTimeout("location.reload(true);",3000);
		}
	}
		
	// var comBtn =  document.getElementById('addComBtn');	
	 //comBtn.value = "Se adauga...";
		var queryString = "?id=" + id;
		ajaxRequest.open("GET", "upd.php" + queryString, true);
		ajaxRequest.send(null); 	
}

