function errFunc(){
	alert('A aparut o eroare. Va rugam incercati din nou!');
	window.location.reload();
}

function validate_ask(){
	var nume_client = document.forms[0].nume_client.value;
	var email_client = document.forms[0].email_client.value;
	var telefon_client = document.forms[0].telefon_client.value;
	var oras_client = document.forms[0].oras_client.value;
	var destinatie_client = document.forms[0].destinatie_client.value;
	var errorc = 0;
	if(nume_client == ''){ document.getElementById('nume_client_alert').style.display = ''; errorc++; } else { document.getElementById('nume_client_alert').style.display = 'none'; }
	if(email_client == ''){ document.getElementById('email_client_alert').style.display = ''; errorc++; } else { document.getElementById('email_client_alert').style.display = 'none'; }
	if(telefon_client == ''){ document.getElementById('telefon_client_alert').style.display = ''; errorc++; } else { document.getElementById('telefon_client_alert').style.display = 'none'; }
	if(oras_client == ''){ document.getElementById('oras_client_alert').style.display = ''; errorc++; } else { document.getElementById('oras_client_alert').style.display = 'none'; }
	if(destinatie_client == ''){ document.getElementById('destinatie_client_alert').style.display = ''; errorc++; } else { document.getElementById('destinatie_client_alert').style.display = 'none'; }
	if(echeck(email_client) == false){ document.getElementById('email_client_alert').style.display = ''; errorc++; } else { document.getElementById('email_client_alert').style.display = 'none'; }
	if(errorc != 0){
		document.getElementById('alert_me').style.display = '';
	} else {
		document.getElementById('the_table').style.display = 'none';
		document.getElementById('loading_t').style.display = '';
		var request = new Ajax.Request('cere_oferta.php',{asynchronous:true,method:'post',parameters:'act=oferta&'+Form.serialize(document.forms[0]),onSuccess: function(t){ alert('Va multumim pentru alegerea facuta!'); mycounter = 0; Windows.closeAll(); }, onFailure:errFunc});
	}
	return false;
}

var cere_vacanta_personalizata = function() {
		Windows.closeAll();
		var win = new Window('ofertawin_' + Math.random(), {className: "dialog",minWidth:430,minHeight:320,resizable:false,closable:true,minimizable:false,maximizable:false,width:430, height:320,showEffect:Effect.Grow,hideEffect: Effect.Shrink, destroyOnClose: true});
		win.getContent().innerHTML = document.getElementById('formular_vacanta_cere').innerHTML;
		win.setDestroyOnClose(true);
		win.showCenter();
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
} 



function _escape(str){
	str = str.replace(/ /g, '+');
	str = str.replace(/%/g, '%25');
	str = str.replace(/\?/, '%3F');
	str = str.replace(/&/, '%26');
	return str;
}

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;
}

function changeclasses(strTag,strClass) {
	for (i=0;i<document.getElementsByTagName(strTag).length; i++) {
		if (document.getElementsByTagName(strTag).item(i).className == strClass) {
			document.getElementsByTagName(strTag).item(i).style.display = 'none';
		}
	}
}


function switch_classes(id, classname, classname2){
	changeclasses('div', classname);
	document.getElementById('arhiva_'+id).style.display = '';
	for(z=0;z<classname2;z++){
		document.getElementById('button_'+z).style.color = 'black';
	}
	document.getElementById('button_'+id).style.color = 'red';

}


function launch_support_1_0(){
	var request_url_1_0 = "http://www.perfect-tour.ro/livesupport/request.php?l=razvanm&x=1&deptid=0&page=www.revelion2010.com.ro" ;
	newwin = window.open( request_url_1_0, 1, 'scrollbars=no,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=450,height=400' ) ;
	newwin.focus() ;
}
function launch_support_2_0(winhref){
	var request_url_2_0 = "http://www.perfect-tour.ro/livesupport/request.php?l=razvanm&x=1&deptid=0&page="+winhref;
	newwin = window.open( request_url_2_0, 2, 'scrollbars=no,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=450,height=400' ) ;
	newwin.focus() ;
}

function check_form(){
		formf = document.getElementById('ceredisp');
		imagesi = ['nume', 'oras', 'email', 'telefon'];
		documei = [formf.nume.value, formf.oras.value, formf.email.value, formf.telefon.value];
		if( (formf.nume.value == '') || (formf.oras.value == '') || (formf.email.value == '') || 
			(formf.telefon.value == '')) {
				for(k=0; k<imagesi.length; k++){
					imageloc = imagesi[k];
					formloc = documei[k];
					if(formloc == ''){
						document.getElementById(imageloc+'i').src = "http://www.perfect-tour.ro/imagini/deny.png";
					} else {
						document.getElementById(imageloc+'i').src = "http://www.perfect-tour.ro/imagini/ok.png";
					}
				}
				alert('Va rugam completati toate campurile');
				return false;
		} else {
				for(k=0; k<imagesi.length; k++){
					imageloc = imagesi[k];
					document.getElementById(imageloc+'i').src = "http://www.perfect-tour.ro/imagini/ok.png";
				}
				var str = formf.email.value;
				var emailerr = 0;
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/;
				if(reg.test(str) == false) {
				  emailerr++;
				}
				if(emailerr != 0){
					if(formloc == ''){
						document.getElementById('emaili').src = "http://www.perfect-tour.ro/imagini/deny.png";
					} else {
						document.getElementById('emaili').src = "http://www.perfect-tour.ro/imagini/ok.png";
					}
					alert('Email invalid');
					return false;
				}
				return true;
		}
		return false;
}

function cere_detalii(){
	Effect.toggle('cerere_detalii','slide');
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiresec){
	var exdate=new Date();
	exdate.setTime(exdate.getTime()+expiresec);
	document.cookie=c_name+ "=" +escape(value)+((expiresec==null) ? "" : ";expires="+exdate.toGMTString());
}


function close_footer(){
	setCookie('FooterCookie', 'close', 600000);
	$('promotie_footer').style.display = 'none';
	$('footer_extra').style.display = 'none';
}

function open_footer(){
	$('promotie_footer').style.display = 'none';
	$('footer_extra').style.display = 'none';
	if(getCookie('FooterCookie') != 'close'){
		$('promotie_footer').style.display = '';
		$('footer_extra').style.display = '';	
	}
}

function update_idei(html){
	document.getElementById('idei_rasp').innerHTML = html;
}

function cauta_idee(idea){
	for (i=0;i<idea.idee.length;i++) {
		if (idea.idee[i].checked) {
			ideea = idea.idee[i].value;
		}
	}
	window.location.hash = '#bottom';
	var add_loading = '<br /><br /><center><img src="http://www.perfect-tour.ro/images/idei/loading.gif" alt="loading" /></center>';
	update_idei(add_loading);
	var request = new Ajax.Request('cere_idei.php',{asynchronous:true,method:'post',parameters:'tip='+ideea+'&',onSuccess: function(t){ update_idei(t.responseText) }, onFailure:errFunc});
	//alert(ideea);
	return false;
}
