function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Adresa de email incorecta (verificati @ si .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Adresa IP de destinatie este invalida!")
			return false
			}
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Numele domeniului nu este valid.")
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
	   alert("Adresa de email se termina in numele domeniului (3 litere) sau indicativul tarii (2 litere)")
	   return false
	}
	if (len<2) {
	   var errStr="Acestei adrese ii lipseste numele gazdei!"
	   alert(errStr)
	   return false
	}
	return true;
	}
	
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = getyMousePos;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = getyMousePos;
	    } else if (document.getElementById) { // Netcsape 6
	        document.onmousemove = getyMousePos;
		}
yMousePos = 0;		
function getyMousePos(e) {
    if (document.layers) {
            YMousePos = window.pageYOffset;
	    }
     else if (document.all) {
             //yMousePos = event.clientY + document.body.scrollTop;
	     yMousePos = document.documentElement.scrollTop;
	     }
	  else if (document.getElementById) {
		yMousePos = window.pageYOffset;
		}
    //window.status = "yMousePos=" + yMousePos;		
}    					

var val = 10;
function createOverlay(width, height, url)
{
   if(!document.getElementById('overlay_wrapper')){
   	//var top = document.createElement('DIV');
	//alert(url);
	if (url.indexOf('jurizare')==-1)
	{
	    var top = document.createElement('DIV');
	    top.className = 'transparency';
   	    top.id = 'transparency';
   	    top.onclick=function()
   	    {
    		close_form_subscribers('overlay_wrapper', 'transparency');
	    }
	    document.body.appendChild(top); 
	}
	else
	{    
	    var top = parent.document.createElement('DIV');
	    top.className = 'transparency';
   	    top.id = 'transparency';
   	    top.onclick=function()
   	    {
    		close_form_subscribers('overlay_wrapper', 'transparency');
	    }
	    parent.document.body.appendChild(top);
	}
	if (url.indexOf('view2006')!=-1)
	top.style.height='4900%';
	//else alert(parent.document.body.clientWidth);
   	if (document.getElementById('flash'))
   		document.getElementById('flash').style.visibility='hidden';
   	/*top.style.width = '50px';
   	top.style.height = '100%';*/
   	/*top.style.backgroundColor = 'black';
   	top.style.position = 'absolute';
   	top.style.top = 0;
   	top.style.left = 0;*/

    /*top.innerHTML = 'xxx';*/
    //alert(navigator.appName);
    /*if(navigator.appName.indexOf("Microsoft") != -1){
    	top.style.Filter = "alpha(opacity = 10)";
    }
    else
    	top.style.MozOpacity = 0.1;*/
   	//document.body.appendChild(top);
	//for(var i = 10; i < 80; i++){
		//val = i;
		//setTimeout("setOpacity()", 90);
	//setOpacity();
	//}
	if (url.indexOf('jurizare')==-1)
   	    var ov = document.createElement('DIV');
	else
	    var ov = parent.document.createElement('DIV');    
	/*ov.id = 'overlay_wrapper';*/
   	ov.className = 'overlay_wrapper';
   	ov.id = 'overlay_wrapper';
   	ov.style.width = width + 'px';
   	ov.style.height = height + 'px';
   	ov.innerHTML = 'Loading...';
	
	left = (parent.document.body.clientWidth - width)/2;
	ov.style.left = left + 'px';
	//alert(document.documentElement.scrollTop);
	if(url.indexOf("imagess") != -1 || url.indexOf("gallery") != -1)
		ov.style.top = (yMousePos-250) + 'px';
	if (url.indexOf('view2006')!=-1)
	    ov.style.top=yMousePos+'px';	
   	/*ov.style.backgroundColor = 'white';
   	ov.style.position = 'absolute';
   	ov.style.zIndex = 100;*/
	if (url.indexOf('jurizare')==-1)
	    document.body.appendChild(ov);
	else
	    parent.document.body.appendChild(ov);	
   	requestData(url, 'overlay_wrapper');
   	if(url.indexOf("imagess") == -1 && url.indexOf('gallery') == -1)
	
	    if ((url.indexOf('jurizare')==-1)){
		if ((url.indexOf('view2006')==-1))
   		window.location.hash='top';}
	    else 
		parent.window.location.hash='top';
   }
   return false;
}

function setOpacity()
{
	//alert(document.getElementById('transparency').style.Filter);
	if(navigator.appName.indexOf("Microsoft") != -1){
		document.getElementById('transparency').style.Filter = "alpha(opacity = " + val +")";
	}
	else
		document.getElementById('transparency').style.MozOpacity = val/100;

	if(val < 70){
		val += 5;

		setTimeout("setOpacity()", 120);
	}
	else val = 10;
}
function close_form(div_id, transparency_id)
{
	if(document.getElementById(div_id)){
		document.getElementById(div_id).parentNode.removeChild(document.getElementById(div_id));
		if(document.getElementById(transparency_id)){
			document.getElementById(transparency_id).parentNode.removeChild(document.getElementById(transparency_id));
		}
		window.location.reload();
	}
}

function close_form_subscribers(div_id, transparency_id)
{
	if(document.getElementById(div_id)){
		document.getElementById(div_id).parentNode.removeChild(document.getElementById(div_id));
		if(document.getElementById(transparency_id)){
			document.getElementById(transparency_id).parentNode.removeChild(document.getElementById(transparency_id));
		}
		//window.location.reload();
	}
	if (document.getElementById('flash'))
		document.getElementById('flash').style.visibility='visible';
	else if (document.getElementById('jurizare'))
		frames['jurizare'].document.getElementById('flash').style.visibility='visible';
		//alert("a");
}

function checkSection(thenewone,cat_id)
{
	var f = document.forms['comp_sub'];
	already=new Array();
	for (i=0;i<f.length;i++)
		if ((f.elements[i].type=='checkbox')&&(f.elements[i].name.slice(0,4)=='comp')&&(f.elements[i].checked==true)&&(f.elements[i].name!=thenewone.name))
		{
			already.push(f.elements[i].id);
		}
	if (already.length==0)	
		document.getElementById('form_fields').innerHTML = 'Loading...';
	getRegisterForm(already,thenewone.id,thenewone.checked,cat_id);
}

function createOverlayAdmin(width, height, url)
{
   if(!document.getElementById('overlay_wrapper')){

   	var ov = document.createElement('DIV');
   	ov.className = 'overlay_wrapper';
   	ov.id = 'overlay_wrapper';
   	ov.style.width = width + 'px';
   	ov.style.height = height + 'px';
   	ov.innerHTML = 'Loading...';
	left = (document.body.clientWidth - width)/2;
	ov.style.left = left + 'px';
   	document.body.appendChild(ov);
   	requestData(url, 'overlay_wrapper');
   	window.location.hash='top';
   }
   return false;
}

function add_field(url)
{
	createOverlayAdmin(400, 300, url);
	return false;
}

function add_criteria(url)
{
	createOverlayAdmin(500, 350, url);
	return false;
}

function delete_field(url)
{
	if(confirm("Sunteti sigur ca doriti sa stergeti campul?")){
		window.location.href = url;
	}
	return false;
}

function delete_criteria(url)
{
	if(confirm('Sunteti sigur ca doriti sa stergeti criteriul?'))
	   window.location.href = url;

	return false;
}

function add_section(url)
{
	createOverlayAdmin(900, 650, url);
	return false;
}

function delete_section(url)
{
	if(confirm("Sunteti sigur ca doriti sa stergeti sectiunea?")){
		window.location.href = url;
	}
	return false;
}

function add_category(url)
{
	createOverlayAdmin(500, 300, url);
	return false;
}

function delete_category(url)
{
	if(confirm("Sunteti sigur ca doriti sa stergeti categoria?")){
		window.location.href = url;
	}
	return false;
}


function openPreview(id)
{
	var oForm = document.getElementById(id);
    var sBody = getRequestBody(oForm);
    if(oFCKeditor !== undefined){
    	sBody += "&";
    	var sParam = encodeURIComponent('content');
        sParam += "=";
        sParam += encodeURIComponent(GetContents('content'));
        sBody += sParam;
    }

    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("post", '/admin/nlbodies/preview', true);
    oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                //saveResult(oXmlHttp.responseText);
                //document.getElementById('form_wrapper').innerHTML = oXmlHttp.responseText;
                //alert(oXmlHttp.responseText);
                //eval(oXmlHttp.responseText);
                //window.location.href='/admin/nlbodies/preview?flag=preview';
                window.open('/admin/nlbodies/preview?flag=preview', 'Preview', 'status=1, width=800, height=700, scrollbars=1');
            } else {
                //saveResult("An error occurred: "+ oXmlHttp.statusText);
                alert("An error occurred: "+ oXmlHttp.statusText);
            }
        }
    };
    oXmlHttp.send(sBody);
}

function showCriteria(div_id)
{
	divs=document.getElementById('criteria').getElementsByTagName('div');
    //alert(divs.length);
	for (i=0;i<divs.length;i++)
		if (divs[i].id!='crit_'+div_id)
			document.getElementById(divs[i].id).style.display='none';
		else
			document.getElementById(divs[i].id).style.display='block';
}


/*function verfriend(email) {
  var cauta1 = email.indexOf('@');
  var cauta2 = email.indexOf('.');
  if (cauta1 == -1 || cauta2 == -1)
  {
  	document.getElementById('email').style.visibility = 'visible';
  	return false;
  } else {
  	document.getElementById('email').style.visibility = 'hidden';
  	return true;
  }
}*/

function checkSelection(f, select_obj)
{
	/*wr = f.getElementsByTagName('div')
	//alert(wr.length);
	if(wr[0].className == "pers_info"){
		if(select_obj.options[1].selected){
			if(f.hasCNP.value == 0){
				if(wr[0].style.display == "none"){
					wr[0].style.display = "block";
				}
			}
		}
		else{
				if(wr[0].style.display == "block"){
						wr[0].style.display = "none";
				}
		}
	}*/

	wr = f.getElementsByTagName('div')
    //alert(wr.length);
    for(var i = 0; i < wr.length; i++){
            if(wr[i].className == "pers_info")
                    break;
    }
    if(wr[i] != undefined && wr[i].className == "pers_info"){
            if(select_obj.options[1].selected){
                    if(f.hasCNP.value == 0){
                            if(wr[i].style.display == "none"){
                                    wr[i].style.display = "block";
                            }
                    }
            }
            else{
                            if(wr[i].style.display == "block"){
                                            wr[i].style.display = "none";
                            }
            }
    }
	else{
		if(select_obj.options[1].selected){
			if(f.hasCNP.value == 0){
				if(document.getElementById('pers_info').style.display == "none"){
					document.getElementById('pers_info').style.display = "block";
				}
			}
		}
		else{
			if(document.getElementById('pers_info').style.display == "block"){
					document.getElementById('pers_info').style.display = "none";
			}
		}
	}
}


function validateFieldsA(f)
{
	szError = "";
	if(f.name.value.lenght <= 0){
		szError += "Introduceti numele campului!\n";
	}
	if(szError.length > 0){
		alert(szError);
		return false;
	}
}

/*function changeJury(competition)
{
	comps=new Array();
	comps[0]='Web_Space';comps[1]='Web_Promo';comps[2]='Web_Graphic';
	//alert(comps);
	for(i=0;i<3;i++)
		if (comps[i]!=competition)
			document.getElementById(comps[i]).style.display='none';
		else
			document.getElementById(comps[i]).style.display='block';
}*/

function verreguli(camp)
{
	if(camp.checked) {
		spion=true;
	} else {
		spion=false;
	}
	if(spion == true) {
		//document.getElementById('trimite').disabled=false;
	} else {
		alert('Trebuie sa fii de acord cu regulile de inscriere pentru a inscrie blogul!');
		//document.getElementById('trimite').disabled=true;
	}
	return spion;
}

function validateblog()
{
	var blog = document.getElementById('blog_url').value;
	var nume = document.getElementById('blog_name').value;
	var camp = document.getElementById('ch');
	var bemail = document.getElementById('b_e_mail').value;
	var gardian = true;
	if (blog.match('http://') == null) {
		alert('Adres RSS trebuie sa continta http://');
		gardian = false;
	} else if(blog.length <= 0) {
		alert('Introdu adresa RSS a blogului!');
		gardian = false;
	} else if (nume.length <= 0) {
		alert('Introdu numele blogului!');
		gardian = false;
	} else if (emailCheck(bemail) == false) {
		gardian = false;
	} else if (verreguli(camp) == false) {
		//alert('Introdu numele blogului!');
		gardian = false;
	}
	return gardian
}

function validatesearch()
{
	cautare = document.getElementById('cuvant').value;
	if(cautare.length <= 0) {
		alert('Nu ati introdus nimic!');
		return false;
	} else {
		return true;
	}
}


function changePic(img)
{

	opacity('photo', 100, 30, 1000);

	//document.getElementById('photo').innerHTML='';
	imgs = document.getElementById('photo').getElementsByTagName('img');
	/*if(imgs[0]){
		imgs[0].src = "/files/lucrari2006_500x375/"+img.id;
		imgs[0].style.width='500px';
		imgs[0].style.height='375px';
	}*/
	new_img=new Image();
	new_img.src="/files/lucrari2006_500x375/"+img.id;
	new_img.style.width='500px';
	new_img.style.height='375px';
	document.getElementById('photo').removeChild(imgs[0]);
	document.getElementById('photo').appendChild(new_img);
	opacity('photo', 30, 100, 1000);
/*if (img.alt.length>0)
		document.getElementById('descr').innerHTML=img.alt;
	else
		document.getElementById('descr').innerHTML='&nbsp;';*/
}

function fadingEffect(obj, flag)
{

	obj.style.MozOpacity = increment/100;
	if(flag == "up")
		increment++;
	else increment--;

	//return increment;
}

function doFading()
{
         setTimeout("doFading()", 3000);
		fadingEffect(document.getElementById('photo'), direction);
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

}


function search()
{
	var cautare = document.getElementById('textfield4').value;
	if(cautare.length <= 0) {
		alert('Nu ati introdus nimic!');
		return false;
	} else if (cautare.length <= 3) {
		alert('Cuvantul este mai mic de 4 caractere!');
		return false;
	} else {
		return true;
	}
}

function goPrint(url)
{
	var baby = window.open('/pages/printpage?page='+url, 'Internetics', 'width=800, height=600, status=1, scrollbars=1');
	baby.print();
	return false;
}
fee1=0;
fee2=0;
fee3=0;
term1=0;
term2=0;
dif=0;
var hotel = [];
function setfee(tip,value)
{
	if(tip=='1')
	{
		/*document.getElementById('trsp').checked=true;*/
		fee3=0;
		fee1=value;
	}
	if(tip=='2')fee2=value;
	if(tip=='3')
	{
		var pers;
		if(fee1==150)pers=1;
		else if(fee1==500)pers=4;
		else if(fee1==900)pers=10;
		fee3=value*pers;
	}
	var att=fee1;
	var acc=(fee2*dif)+fee3;
	var tot=att+acc;
	/*document.getElementById('totfee').innerHTML=tot;
	document.getElementById('attfee').innerHTML=att;
	document.getElementById('accfee').innerHTML=acc;*/
	document.getElementById('total').value=tot;
}
function setfee2(hotel_id,room_type,value)
{
	var nr_rooms;
	if(value==0)
	{
		if(document.getElementById('hotel'+room_type+hotel_id))
		{
			if(document.getElementById('hotel'+room_type+hotel_id).checked)
			{
				document.getElementById('rooms'+room_type+hotel_id).disabled=false;
			}
			else 
			{
				if(hotel[hotel_id]==undefined){hotel[hotel_id]=[];/*alert("undefined");*/}
				hotel[hotel_id][room_type]=0;
				document.getElementById('rooms'+room_type+hotel_id).value='';
				document.getElementById('rooms'+room_type+hotel_id).disabled=true;
			}
		}
		else
		{
			alert("No such element! "+'hotel'+room_type+hotel_id);
			return;
		}
	}
	else
	{
		if(!document.getElementById('rooms'+room_type+hotel_id)){alert("No such element! "+'rooms'+room_type+hotel_id);return;}
		if(hotel[hotel_id]==undefined){hotel[hotel_id]=[];/*alert("undefined");*/}
		nr_rooms=document.getElementById('rooms'+room_type+hotel_id).value;
		/*alert("hotel["+hotel_id+"]["+room_type+"]="+value+"*"+nr_rooms);*/
		hotel[hotel_id][room_type]=value*nr_rooms;
	}
	var totalptdoi=0;
	for(var h in hotel)
	{
		var h2=hotel[h];
		for(var r in h2){/*alert("hotel["+h+"]["+r+"]: "+hotel[h][r]);*/totalptdoi+=hotel[h][r];}
	}
	setfee(2,totalptdoi);
}
function setfeeck(tip,value)
{
	term1=document.getElementById('cin').value;
	term2=document.getElementById('cout').value;
	if(term2<term1)dif=0;
	else if(term1==0)dif=0;
	else if(term2==0)dif=0;
	else dif=(term2-term1)/(24*3600);
	var att=fee1;
	var acc=(fee2*dif)+fee3;
	var tot=att+acc;
	document.getElementById('totfee').innerHTML=tot;
	document.getElementById('attfee').innerHTML=att;
	document.getElementById('accfee').innerHTML=acc;
	document.getElementById('total').value=tot;
}