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];}
}

function check_login()
{	
	if (document.getElementById('login_form').email.value=="" || document.getElementById('login_form').email.value=="adresa@email") {
		showDialog("Error", "Please fill in your e-mail address.", "errors");
		document.getElementById('login_form').email.focus();
		return false;
	}
	
	if (document.getElementById('login_form').password.value=="") {
		showDialog("Error", "Please fill in your password.", "errors");
		document.getElementById('login_form').password.focus();
		return false;
	}
	return true;
}

function check_update()
{	
	if (document.profile.fname.value=="") {
		showDialog("Error", "Please fill in your first name.", "errors");
		document.profile.fname.focus();
		return false;
	}

	if (document.profile.lname.value=="") {
		showDialog("Error", "Please fill in your last name.", "errors");
		document.profile.lname.focus();
		return false;
	}

	if (document.profile.postal_address.value == "") {
		showDialog("Error", "Please enter your postal address", "errors");
		document.profile.postal_address.focus();
		return false;
	}

	return true;
}

function check_new_pass()
{	
	if (document.new_pass.old_pass.value=="") {
		showDialog("Error", "Please fill in your current password.", "errors");
		document.new_pass.old_pass.focus();
		return false;
	}

	if (document.new_pass.password.value=="") {
		showDialog("Error", "Please fill in your new password.", "errors");
		document.new_pass.password.focus();
		return false;
	}

	if (document.new_pass.password.value!=document.new_pass.password_again.value) {
		showDialog("Error", "Your new password does not match on repeating it.", "errors");
		document.new_pass.password_again.focus();
		return false;
	}
	return true;
}

function check_register()
{
	if (document.register.fname.value=="") {
		showDialog("Error", "Please fill in your first name.", "errors");
		document.register.fname.focus();
		return false;
	}

	if (document.register.lname.value=="") {
		showDialog("Error", "Please fill in your last name.", "errors");
		document.register.lname.focus();
		return false;
	}

	if (document.register.email.value=="") {
		showDialog("Error", "Please fill in your e-mail address", "errors");
		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)){
			showDialog("Error", "Please fill in a valid e-mail address", "errors");
			document.register.email.focus();
			return false;
	}}

	if (document.register.password.value=="") {
		showDialog("Error", "Please enter a password", "errors");
		document.register.password.focus();
		return false;
	}

	if (document.register.password_again.value!=document.register.password.value) {
		showDialog("Error", "Your password does not match on repeating it", "errors");
		document.register.password_again.focus();
		return false;
	}

	if (document.register.postal_address.value==""){
		showDialog("Error", "Please enter your postal address", "errors");
		document.register.postal_address.focus();
		return false;
	}

	return true;
}

function check_fpassword_form(){
	if (document.f_password.fpass_email.value=="") {
		showDialog("Error", "Please fill in your e-mail address.", "errors");
		document.f_password.fpass_email.focus();
		return false;
	}
	
	return true;	
}

function clear_field(field,name)
{
		if(field.value==name){
			field.value="";
		}
}

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 key(){
		if (document.search.q.value=="" || document.search.q.value=="cautare..."){
			showDialog("Eroare", "Va rugam adaugati textul cautat.", "errors");
			document.search.q.value="";
			document.search.q.focus();
			return false;
		}
		if(document.search.q.value!="") {
			if(document.search.q.value.length<3) {
			showDialog("Eroare", "Va rugam introduceti minim 3 caractere pentru cautare", "errors");
			document.search.q.focus();
			return false;
		}}
}

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>';
}

	function calculate(type,euro,dolar)
	{
		


		reset_(type);
		

		if(type=='euro'){	
			if(document.cursvalutar.euro.value!='' && IsNumeric(document.cursvalutar.euro.value)==true){
				
				rez_lei = document.cursvalutar.euro.value*euro;
				document.cursvalutar.lei.value = rez_lei.toFixed(3);
				
				rez_dolar = (document.cursvalutar.euro.value*euro)/dolar;
				document.cursvalutar.dolar.value = 	rez_dolar.toFixed(3);
			}
		}
		
		if(type=='dolar'){	
			if(document.cursvalutar.dolar.value!='' && IsNumeric(document.cursvalutar.dolar.value)==true){
				
				rez_lei = document.cursvalutar.dolar.value*dolar;
				document.cursvalutar.lei.value = rez_lei.toFixed(3);
				
				rez_euro = (document.cursvalutar.dolar.value*dolar)/euro;
				document.cursvalutar.euro.value = rez_euro.toFixed(3);		

			}
		}


		if(type=='lei'){

			if(document.cursvalutar.lei.value!='' && IsNumeric(document.cursvalutar.lei.value)==true){
				
				rez_euro = document.cursvalutar.lei.value/euro;
				document.cursvalutar.euro.value = rez_euro.toFixed(3);
				
				rez_dolar = document.cursvalutar.lei.value/dolar;
				document.cursvalutar.dolar.value = rez_dolar.toFixed(3);
			}
		}

		
		rez_tva = (document.cursvalutar.lei.value*1.24);
		document.cursvalutar.tva.value = rez_tva.toFixed(3);
		//alert(rez_euro);
		
	}
	
	
	function reset_all()
	{
		document.cursvalutar.dolar.value = "";
		document.cursvalutar.lei.value = "";		
		document.cursvalutar.euro.value = "";
		document.cursvalutar.tva.value = "";
	}
	
	function reset_(no)
	{
		if(no!='dolar') { 
			document.cursvalutar.dolar.value = ""; 
		}
		if(no!='lei') { 
			document.cursvalutar.lei.value = "";	 
		}	
		if(no!='euro') { 
			document.cursvalutar.euro.value = "";	 
		}
	}
	
	function IsNumeric(sText)

	{
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber; 
   }
