var loader = '<div id="loader" align="center"><img src="/media/img/layout/loader.gif"></div>';
var loader2 = '<div id="loader2" align="center"><img src="/media/img/layout/loader2.gif"></div>';
var close_link = '<div align="right" id="close"><a href="#" onclick="closeEvent(); return false;"><img src="/media/img/layout/close.gif" border="0"></a></div>';

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var ajax;

function getLogin(){
	
	
	//document.getElementById('login_box').innerHTML = '<img src="/media/img/layout/loader.gif">';
	
	
	ajax =  new Ajax.Updater(
         'login_box',
         '/phpBIN/ajax.loginbox.php',
         { method:'get'});
	
}

function chPage(page,order1,order2){
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&page='+page+'&order1='+order1+"&order2="+order2,
         { method:'get'});
}

function userzone(type){
	document.getElementById('organizer_view').style.display='none';
	new Effect.SlideDown('organizer');
	
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type='+type,
         { method:'get'});
}

function addTask(){
	
	if (document.task.subject.value=="") {
		alert("Va rugam adaugati subiectul pentru a continua.");
		document.task.subject.focus();
		return false;
	}
	if (document.task.details.value=="") {
		alert("Va rugam adaugati detalii pentru a continua.");
		document.task.details.focus();
		return false;
	}
	if (document.task.date4.value=="") {
		alert("Va rugam adaugati data start pentru a continua.");
		document.task.date4.focus();
		return false;
	}	
	if (document.task.date3.value=="") {
		alert("Va rugam adaugati data sfarsit pentru a continua.");
		document.task.date3.focus();
		return false;
	}		
	
	subject = document.task.subject.value;
	details = document.task.details.value;
	date4 = document.task.date4.value;
	date3 = document.task.date3.value;
	o_type = document.task.o_type.value;
	
	new Effect.SlideDown('organizer');
	
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&subject='+subject+'&details='+details+'&start_date='+date4+'&end_date='+date3+'&o_type='+o_type,
         { method:'get'});
		 
		 	return false;
}

function updateTask(type){
	
	subject = document.task.subject.value;
	details = document.task.details.value;
	date4 = document.task.date4.value;
	date3 = document.task.date3.value;
	o_type = document.task.o_type.value;
	id = document.task.id.value;
	page = document.task.page.value;
	
	new Effect.SlideDown('organizer');
	
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?update=1&type='+type+'&subject='+subject+'&details='+details+'&start_date='+date4+'&end_date='+date3+'&o_type='+o_type+'&id='+id+'&page='+page,
         { method:'get'});
		 
		 return false;
}

function overTask(id,page){
	
	if(confirm("Task finalizat?")){
	
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&status=0&id='+id+'&page='+page,
         { method:'get'});
		 
		 	return false;
	}
	
}

function startTask(id,page){
	
	if(confirm("Activez task?")){
	
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&status=1&id='+id+'&page='+page,
         { method:'get'});
		 
		 	return false;
	}
	
}

function delTask(id,page)
{
	
	if(confirm("Stergere task?")){
	
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&delete='+id,
         { method:'get'});
		 //+'&page='+page
		 	return false;
	} 
}

function editTask(id,page)
{
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=10&id='+id+'&page='+page,
         { method:'get'});
		 
		 	return false;		
}


function orderTask(page,order1,order2)
{
	
	document.getElementById('organizer_view').style.display='none';
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=2&order1='+order1+'&order2='+order2,
         { method:'get'});
		 //+'&page='+page
 	return false;

}


function updateProfile(){

	if (document.profile.name.value=="") {
		alert("Va rugam adaugati numele pentru a continua.");
		document.profile.name.focus();
		return false;
	}

	if (document.profile.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.profile.password.focus();
		return false;
	}

	if (document.profile.password.value!=document.profile.password_again.value) {
		alert("La rescriere parola nu se potriveste.");
		document.profile.password.focus();
		return false;
	}
	
	name = document.profile.name.value;
	password = document.profile.password.value;
	active_newsletter = document.profile.active_newsletter.checked;
	
	if(active_newsletter==true){
		active_newsletter = 1;
	} else {
		active_newsletter = 0;
	}
	
	new Effect.SlideDown('organizer');
	
	document.getElementById('organizer').innerHTML = loader;
	ajax =  new Ajax.Updater(
         'organizer',
         '/phpBIN/ajax.organizer.php?type=3&name='+name+'&password='+password+'&active_newsletter='+active_newsletter,
         { method:'get'});
		 
	
}

function check_login()
{	
	if (document.login.email.value=="" || document.login.email.value=="adresa@email") {
		alert("Va rugam adaugati adresa de email pentru a continua.");
		document.login.email.focus();
		return false;
	}
	
	if (document.login.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.login.password.focus();
		return false;
	}
	return true;
}

function clear_field(field,name)
	{
		if(field.value==name){
			field.value="";
		}
}


function check_register(thisform)
{
	if (document.register.name.value=="") {
		alert("Va rugam adaugati Numele pentru a continua.");
		document.register.name.focus();
		return false;
	}


	if (document.register.email.value=="" || document.register.email.value=="adresa@email") {
		alert("Va rugam adaugati adresa de e-mail pentru a continua.");
		document.register.email.value="";
		document.register.email.focus();
		return false;
	} else {
		ast=document.register.email.value.indexOf("@");
		dot=document.register.email.value.lastIndexOf(".");
		if(!(ast>0 && dot>0 && dot>ast)){
			alert("Va rugam adaugati o adresa de e-mail valida pentru a continua.");
			document.register.email.focus();
			return false;
	}}

	if (document.register.email_again.value!=document.register.email.value) {
		alert("Atentie adresa de email este gresita la rescriere.");
		document.register.email_again.focus();
		return false;
	}
	
	if (document.register.password.value=="") {
		alert("Va rugam adaugati parola pentru a continua.");
		document.register.password.focus();
		return false;
	}

	if (document.register.password_again.value!=document.register.password.value) {
		alert("Atentie parola este gresita la rescriere.");
		document.register.password_again.focus();
		return false;
	}

	if (document.register.code.value==""){
		alert("Va rugam adaugati codul de siguranta din imaginea de mai sus pentru a continua.");
		document.register.code.focus();
		return false;
	}
/*	
	if (document.register.conditii.checked==false) {
		alert("Pentru a continua trebuie sa fiti de acord cu regulamentul.");
		document.register.conditii.focus();
		return false;
	}
*/
	return true;
}

function OnOver(TheId) {
	document.getElementById(TheId).style.background='#80a6c3';
}

function OnOut(TheId) {
	
	document.getElementById(TheId).style.background='#bcd0df';
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId);
	oLeft = o.offsetLeft ;           // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent ;   // Get parent object reference
		oLeft += oParent.offsetLeft; // Add parent left position
		o = oParent;
	}
	// Return left postion
	return oLeft;
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId);
	oTop = o.offsetTop       ;     // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent ; // Get parent object reference
		oTop += oParent.offsetTop; // Add parent top position
		o = oParent;
	}
	// Return top position
	return oTop;
}

function viewEvent(id,subject,details,start_date,end_date){
	//
	
	document.getElementById('organizer_view').innerHTML = loader2;
	
	var top = getAbsoluteTop(id);
	var left = getAbsoluteLeft(id);
	left = left - 300;
	var resp = document.getElementById('organizer_view');
	resp.style.top = top+2+'px';
	resp.style.left = left+0+'px';
		
	//cp.call('cgi.php',"&img="+img, response);
	resp.innerHTML=close_link+'<div id="organizer_title"><h2>'+subject+'</h2></div>'+'<div id="organizer_text">'+details+'</div><div id="organizer_date" align="center">'+start_date+' - '+end_date+'</div>';
	document.getElementById('organizer_view').style.display='';
	
	new Effect.Appear('organizer_view');
}
function closeEvent() {
	//document.getElementById('organizer_view').style.display='none';
	new Effect.Puff('organizer_view');
}

function key(){
		if (document.search.q.value=="" || document.search.q.value=="cautare..."){
			alert("Va rugam adaugati textul cautat.");
			document.search.q.value="";
			document.search.q.focus();
			return false;
		}
		if(document.search.q.value!="") {
			if(document.search.q.value.length<3) {
			alert("Va rugam introduceti minim 3 caractere pentru cautare");
			document.search.q.focus();
			return false;
		}}
}
function clear_field(field,name)
{
		if(field.value==name){
			field.value="";
		}
}

function check_recomanda(r_link)
{

		if (document.recomanda.name_exp.value=="" || document.recomanda.name_exp.value=="Nume expeditor") {
			alert("Va rugam adaugati numele dvs pentru a continua.");
			document.recomanda.name_exp.focus();
			return false;
		}
		if (document.recomanda.email_exp.value=="" || document.recomanda.email_exp.value=="E-mail expeditor") {
			alert("Va rugam adaugati e-mailul dvs pentru a continua.");
			document.recomanda.email_exp.focus();
			return false;
		}
		if (document.recomanda.name_dest.value=="" || document.recomanda.name_dest.value=="Nume destinatar") {
			alert("Va rugam adaugati numele destinatarului pentru a continua.");
			document.recomanda.name_dest.focus();
			return false;
		}
		if (document.recomanda.email_dest.value=="" || document.recomanda.email_dest.value=="E-mail destinatar") {
			alert("Va rugam adaugati e-mailul destinatarului pentru a continua.");
			document.recomanda.email_dest.focus();
			return false;
		}

		ajax =  new Ajax.Updater(
			"send2prieten",
			"/cgi2.php?r_link="+r_link+"&name_exp="+document.recomanda.name_exp.value+"&name_dest="+document.recomanda.name_dest.value+"&email_dest="+document.recomanda.email_dest.value+"&email_exp="+document.recomanda.email_exp.value,
			{method:'get'});

		return false;
}
function show_recomanda(send2f){


	var left = getAbsoluteLeft('ico2');
	var top = getAbsoluteTop('ico2');;
	
	var resp = document.getElementById('send2prieten');
	resp.style.top = top+15+'px';
	resp.style.left = left-50+'px';
		


	//cp.call('cgi.php',"&img="+img, response);
	document.getElementById('send2prieten').style.display='';
		
	//new Effect.SlideDown('send2prieten');
	
	document.getElementById('send2prieten').innerHTML = loader2;
	ajax =  new Ajax.Updater(
         'send2prieten',
         '/phpBIN/ajax.send2prieten.php?send2f='+send2f,
         { method:'get'});
	
	new Effect.Appear('send2prieten');
	
}

function close_send2prieten(){	
	new Effect.Puff('send2prieten');
}

function demo_swf(){
   	document.getElementById('demo').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="307" height="226"><param name="movie" value="/media/promo/demo-organizer.swf" /><param name="quality" value="high" /><embed src="/media/promo/demo-organizer.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="307" height="226"></embed></object>';
}
