control=0;

function init_js(id)
{
flash(0);
step=25
automate_step=148

document.getElementById(id).scrollLeft=30000
maxim=document.getElementById(id).scrollLeft;
document.getElementById(id).scrollLeft=0

$(document).keyup(function(e) {
  if (e.keyCode == 27) if($("#black").is(":visible")) togglePromo();
});


$(function() {
	$('a.lightbox').lightBox(); // Select all links with lightbox class
});


automate(id);


}

function flash(nr)
{
	if(control==0)
	{
	if(nr==0)
	{
		document.getElementById('titluPromo').style.color="#f60";
		$('#titluPromo').animate({fontSize:'22'},500,function(){flash(1);});
	}
	else
	{
		document.getElementById('titluPromo').style.color="#0a306f";
		$('#titluPromo').animate({fontSize:'14'},500,function(){flash(0);});
	}
	}
}

var animale=1;

function togglePromo()
{
	if(!$("#black").is(":visible")) 
	{
	control=1;
	$("body").css("overflow","hidden");
	$("#black").fadeToggle(300,function(){$("#promoDiv").slideToggle(550);});
	}
	else 
	{
	 animale=1;
	 $("body").css("overflow","visible");
	 $("#promoDiv").slideToggle(550,function(){$("#black").fadeToggle(300,function(){control=0;flash(0);automate('galeria');});});
	}
}


function automate(id)
{
if(document.getElementById(id).scrollLeft==0) automate_step*=-1	

else if (document.getElementById(id).scrollLeft==maxim)  automate_step*=-1	
document.getElementById(id).scrollLeft+=automate_step
if(control==0) timer=setTimeout("automate('"+id+"')",1200)
}

function scrollDivRight(id){
clearTimeout(timer);
document.getElementById(id).scrollLeft+=step
timerRight=setTimeout("scrollDivRight('"+id+"')",100)
}

function scrollDivLeft(id){
clearTimeout(timer);
document.getElementById(id).scrollLeft-=step
timerLeft=setTimeout("scrollDivLeft('"+id+"')",100)
} 

function test_direction(numar)
{
	clearTimeout(timer);
	if(numar==1 && automate_step<0) automate_step*=-1;
	if(numar==0 && automate_step>0) automate_step*=-1;
	timer=setTimeout("automate('galeria')",50)
}

function validateForm(string)
{
var y=document.forms["myForm"]["nume"].value
var z=document.forms["myForm"]["mesaj"].value
var x=document.forms["myForm"]["capcha"].value
var t=document.forms["myForm"]["cod"].value

if (y=="")
  {
  alert("Introdu un Nume!");
  return false;
  }
if (z=="")
  {
  alert("Introdu un Mesaj!");
    document.forms["myForm"]["mesaj"].focus();
  return false;
  }
if(x=="" || x.length!=5)
  {
  alert("Introdu textul de verificare format din 5 caractere!");
  document.forms["myForm"]["capcha"].focus();
  return false;
  }
if(hex_md5(x.toUpperCase())!=t)
  {
  alert("Textul de verificare este gresit!");
  document.forms["myForm"]["capcha"].focus();
  return false;
  }

}

function validatenews()
{
var x=document.forms["myForm2"]["email"].value;

if (x=="")
  {
  alert("Introdu o adresa de Email!");
  return false;
  }
if (x.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
{  alert("Introdu un Email valid!");
  return false;
}

}

function validateMesaj()
{
var x=document.forms["myForm"]["email"].value
var y=document.forms["myForm"]["nume"].value
var z=document.forms["myForm"]["mesaj"].value
if (y=="")
  {
  alert("Introdu un Nume!");
  return false;
  }
 if (x=="")
  {
  alert("Introdu o adresa de Email!");
  return false;
  }
if (x.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
{  alert("Introdu un Email valid!");
  return false;
}

if (z=="")
  {
  alert("Introdu un Mesaj!");
  return false;
  }
}

function validateVanzari()
{
var x=document.forms["myForm"]["titlu"].value
var y=document.forms["myForm"]["descriere"].value
var z=document.forms["myForm"]["valabil"].value
var k=document.forms["myForm"]["file"].value

if (x=="")
  {
  alert("Introdu un Titlu!");
  return false;
  document.forms["myForm"]["titlu"].focus();
  }
 if (y=="")
  {
  alert("Introdu o Descriere!");
  return false;
  document.forms["myForm"]["descriere"].focus();
  }
 
k=k.toLowerCase();

if (k!="" && (k.lastIndexOf(".jpg")==-1 && k.lastIndexOf(".jpeg")==-1))
{ 
  alert("Introdu o poza in format .jpg sau .jpeg!");
  return false;
}
if (z!="" && z.search(/(^\d+$)/) == -1)
{  alert("Introdu o valoare numerica.");
  document.forms["myForm"]["valabil"].focus();
  return false;
}

if (z<1 || z>300)
  {
  alert("Valabilitatea poate fi intre 1 si 300.");
  document.forms["myForm"]["valabil"].focus();
  return false;
  }


}

function validateFormular()
{
var x=document.forms["formular"]["nume"].value
var y=document.forms["formular"]["tel"].value
var z=document.forms["formular"]["animal"].value
var k=document.forms["formular"]["rasa"].value

$("#info_add").fadeOut(300);

var reg = /^([0-9])+$/;

if (x=="")
  {
  document.getElementById("info_add").innerHTML="<img src=\"./imagini/cancel-48.png\" width=\"24\"> Introduceți un nume și un prenume.";
  document.forms["formular"]["nume"].focus();
  $("#info_add").fadeIn(300);
  return false;
  }
if (y=="")
  {
  document.getElementById("info_add").innerHTML="<img src=\"./imagini/cancel-48.png\" width=\"24\"> Introduceți un număr de telefon.";
  document.forms["formular"]["tel"].focus();
  $("#info_add").fadeIn(300);
  return false;
  }
else if(reg.test(y)==false)
  {
  document.getElementById("info_add").innerHTML="<img src=\"./imagini/cancel-48.png\" width=\"24\"> Introduceți un număr de telefon format doar din cifre.";
  document.forms["formular"]["tel"].focus();
  $("#info_add").fadeIn(300);
  return false;
  }
if (z=="")
  {
  document.getElementById("info_add").innerHTML="<img src=\"./imagini/cancel-48.png\" width=\"24\"> Introduceți numele animalului dumneavoastră.";
  document.forms["formular"]["animal"].focus();
  $("#info_add").fadeIn(300);
  return false;
  }
if (k=="")
  {
  document.getElementById("info_add").innerHTML="<img src=\"./imagini/cancel-48.png\" width=\"24\"> Introduceți rasa animalului dumneavoastră.";
  document.forms["formular"]["rasa"].focus();
  $("#info_add").fadeIn(300);
  return false;
  }
return true;
}


function sendForm()
{
var xmlhttp;


before=document.getElementById("trimite").innerHTML;

document.getElementById("trimite").innerHTML='<img src="./imagini/ajax-loader.gif" style="height:25px;"/>'; 


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	$("#info_add").fadeIn(300);
	document.getElementById("info_add").innerHTML=xmlhttp.responseText;
	document.getElementById("trimite").innerHTML=before;
    }
  }

file="./core/clienti.php?";

var x=document.forms["formular"]["nume"].value;
var y=document.forms["formular"]["tel"].value;
var z=document.forms["formular"]["animal"].value;
var k=document.forms["formular"]["rasa"].value;


query="nume="+x+"&tel="+y+"&animal="+z+"&rasa="+k;

file+=query;
 
xmlhttp.open("GET",file,true);
xmlhttp.send();
}

var xmlHttp; // xmlHttp variable
var xmlHttp_aux;


function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.
var objXMLHttp=null // Sets objXMLHttp to null as default.
if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.
objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.
}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
} // End ElseIf.
return objXMLHttp
} 

function iframe_form(form,from,to)
{
if(from=="promoInner") before=document.getElementById("promoInfo").innerHTML;
else before=document.getElementById(from).innerHTML;

$("#"+to).fadeOut(250,function(){
	document.getElementById("formLoader").contentWindow.document.body.innerHTML="";
	document.forms[form].target="formLoader";
	document.forms[form].submit();
	
	
	if(from=="promoInner") document.getElementById(from).innerHTML='<table><tr><td style="text-align:center;height:127px;"><img src="imagini/ajax-loader.gif"/></td></tr></table>';
	else document.getElementById(from).innerHTML='<tr><td style="text-align:center;height:127px;"><img src="imagini/ajax-loader.gif"/></td></tr>';
	
	$("#formLoader").load(function()
		{	
			if(from=="promoInner")
			{
				before=unescape(before);
				var test=before.split('&amp;');
				before=test[0];
				for(i=1;i<test.length;i++) before+="&"+test[i];
				ajax_request(before,'promoInner');
			}
			else document.getElementById(from).innerHTML=before;
			
			var mySplitResult = document.getElementById("formLoader").contentWindow.document.body.innerHTML.split(":");
			if(mySplitResult[0]=="redirect") 
			{
			 window.location=mySplitResult[1];
			 return true;
			}
			else document.getElementById(to).innerHTML=document.getElementById("formLoader").contentWindow.document.body.innerHTML;
						
			$("#"+to).fadeIn(250);
			
			return true;
		});
	
	});
}

function ajax_request(file,to,mod)
{
xmlHttp_aux=GetXmlHttpObject()
if (xmlHttp_aux==null){ 
alert ("Browser does not support HTTP Request")
return // Returns.
} // End If.

$("#"+to).fadeOut(500,function(){
xmlHttp_aux.open("GET",file,true);
xmlHttp_aux.onreadystatechange = function () { 
if (xmlHttp_aux.readyState == 4) { 
var ajaxDisplay = document.getElementById(to);

	var mySplitResult = xmlHttp_aux.responseText.split(":");
	if(mySplitResult[0]=="redirect") window.location=mySplitResult[1];
	else document.getElementById(to).innerHTML= xmlHttp_aux.responseText;
	
	if(mod=="1") $("#"+to).fadeIn(500);
	else togglePromo();
}
};
xmlHttp_aux.send(null);

});}

function adaugaAnimal()
{
	string='<tr><td style="width:100px;">Nume:</td><td><input type="text" name="nume'+animale+'" id="nume'+animale+'" style="width:160px;"></td></tr><tr><td>Data nașterii:</td><td>';
	string+='<select name="Ddata'+animale+'" id="Ddata'+animale+'" style="width:55px;"><option value="0">Zi</option>';
	for(i=1;i<=31;i++)
				if(i<10) string+='<option value="0'+i+'">0'+i+'</option>';
				else string+='<option value="'+i+'">'+i+'</option>';
	string+='</select>';
			
	string+='<select name="Mdata'+animale+'" id="Mdata'+animale+'" style="width:55px;"><option value="0">Lună</option>';
	for(i=1;i<=12;i++)
				if(i<10) string+='<option value="0'+i+'">0'+i+'</option>';
				else string+='<option value="'+i+'">'+i+'</option>';
	string+='</select>';
			
	string+='<select name="Ydata'+animale+'" id="Ydata'+animale+'" style="width:55px;"><option value="0">An</option>';
	for(i=1980;i<=2050;i++) string+='<option value="'+i+'">'+i+'</option>';
	string+='</select></td></tr><tr><td>Sex:</td><td><select name="sex'+animale+'" id="sex'+animale+'" style="width:165px;"><option value="0">Alege sexul</option><option value="1">Mascul</option><option value="2">Femelă</option></select></td></tr><tr><td>Rasă:</td><td><input type="text" name="rasa'+animale+'" id="rasa'+animale+'" style="width:160px;"></td></tr><tr><td colspan="2">&nbsp;</td></tr>';
	$("#animale").append(string);
	animale++;
}


function validateClient()
{
	form="clients";
	
	var numec=document.forms[form]["numec"].value;
	if(numec==''){
		alert("Introdu un nume, pentru a putea trimite informatiile.");
		document.forms[form]["numec"].focus();
		return false;
	}
	var prenumec=document.forms[form]["prenumec"].value;
	if(prenumec==''){
		alert("Introdu un prenume, pentru a putea trimite informatiile.");
		document.forms[form]["prenumec"].focus();
		return false;
	}
	var tel=document.forms[form]["tel"].value;
	if(tel==''){
		alert("Introdu un numar de telefon, pentru a putea trimite informatiile.");
		document.forms[form]["tel"].focus();
		return false;
	}
	var reg=/^([0-9])+$/;
	if(reg.test(tel)==false){
		alert("Introdu un numar de telefon valid [format doar din cifre], pentru a putea trimite informatiile.");
		document.forms[form]["tel"].focus();
		return false;
	}
	var email=document.forms[form]["email"].value;
	if(email==''){
		alert("Introdu o adresa de email, pentru a putea trimite informatiile.");
		document.forms[form]["email"].focus();
		return false;
	}
	var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email)==false){
		alert("Introdu o adresa de email valida, pentru a putea trimite informatiile.");
		document.forms[form]["email"].focus();
		return false;
	}
	
	var adresa=document.forms[form]["adresa"].value;
	if(adresa==''){
		alert("Introdu o adresa, pentru a putea trimite informatiile.");
		document.forms[form]["adresa"].focus();
		return false;
	}
	for(i=0;i<animale;i++)
	{
		var nume=document.forms[form]["nume"+i].value;
		var z=document.forms[form]["Ddata"+i].value;
		var l=document.forms[form]["Mdata"+i].value;
		var a=document.forms[form]["Ydata"+i].value;
		var sex=document.forms[form]["sex"+i].value;
		var rasa=document.forms[form]["rasa"+i].value;
		
		if(nume==''){
		alert("Introdu numele animalului, pentru a putea trimite informatiile.");
		document.forms[form]["nume"+i].focus();
		return false;
		}
		if(z==0){
		alert("Selecteaza ziua nasterii animalului, pentru a putea trimite informatiile.");
		document.forms[form]["nume"+i].focus();
		return false;
		}
		if(l==0){
		alert("Selecteaza luna nasterii animalului, pentru a putea trimite informatiile.");
		document.forms[form]["nume"+i].focus();
		return false;
		}
		if(a==0){
		alert("Selecteaza anul nasterii animalului, pentru a putea trimite informatiile.");
		document.forms[form]["nume"+i].focus();
		return false;
		}
		if(sex==0){
		alert("Alege sexul animalului, pentru a putea trimite informatiile.");
		document.forms[form]["sex"+i].focus();
		return false;
		}
		if(rasa==''){
		alert("Introdu rasa animalului, pentru a putea trimite informatiile.");
		document.forms[form]["rasa"+i].focus();
		return false;
		}
	}
	
	
	return true;
}

