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 filterFormSubmit(filter){

	document.products_menu.filtru.value = filter;

	document.products_menu.submit()

}



function check_newsletter()

{

	if (document.newsletter.email_one.value=="") {

		alert("Va rugam adaugati adresa de e-mail pentru a continua.");

		document.newsletter.email_one.focus();

		return false;

	} else {

		ast=document.newsletter.email_one.value.indexOf("@");

		dot=document.newsletter.email_one.value.lastIndexOf(".");

		if(!(ast>0 && dot>0 && dot>ast)){

			alert("Va rugam adaugati o adresa de e-mail valida pentru a continua.");

			document.newsletter.email_one.focus();

			return false;

	}}



	if (document.newsletter.email_two.value!=document.newsletter.email_one.value) {

		alert("Atentie, adresa de e-mail este gresita la rescriere.");

		document.newsletter.email_two.focus();

		return false;

	}

	

	return true;

}





function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}



function clear_field(field,name)

{

		if(field.value==name){

			field.value="";

		}

}



function focusField(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 checkQuantity(lang, id){

	f = document.getElementById('q' + id);

	v = f.value;

	v = v.replace(',', '.');

	u = document.getElementById('u' + id).value;

	if (lang == 1) {

		if(isNaN(v)){

			alert("Va rugam sa introduceti un numar pentru cantitate.");

			f.focus();

			return false;

		}

		else if(v<=0) {

			alert("Va rugam sa introduceti un numar pozitiv pentru cantitate.");

			f.focus();

			return false;

		}

		else if(u==1 && v!=parseInt(v)){

			alert("Va rugam sa introduceti un numar intreg pentru cantitate.");

			f.focus();

			return false;

		}

	} else {

		if(isNaN(v)){

			alert("Please enter a number for the quantity.");

			f.focus();

			return false;

		}

		else if(v<=0) {

			alert("Please enter a positive number for the quantity.");

			f.focus();

			return false;

		}

		else if(u==1 && v!=parseInt(v)){

			alert("Please enter an integer number for the quantity.");

			f.focus();

			return false;

		}

	}

	

	return true;

}





function checkQuantities(lang, ids, check_total){

	ok = true;

	sum = 0;

	

	for(id in ids){

		if(checkQuantity(lang, ids[id])){

			i = ids[id];

			sum += document.getElementById('q' + i).value * document.getElementById('p' + i).value;

		}

		else return false

	}

	

	if(check_total && sum < 100){

		if(lang==1){

			alert("Comanda minima este de 100 RON.");

		} else {

			alert("Minimum order is 100 RON.");

		}

		

		return false;

	}

	

	return true;

}





function confirmOrder(lang, product, price, q_field, unit){

	v = q_field.value;

	v = v.replace(',', '.');

	

	if(lang==1){

		if(isNaN(v)){

			alert("Va rugam sa introduceti un numar pentru cantitate.");

			q_field.focus();

			return false;

		}

		else if(v<=0) {

			alert("Va rugam sa introduceti un numar pozitiv pentru cantitate.");

			q_field.focus();

			return false;

		}

		else if(unit==1 && v!=parseInt(v)){

			alert("Va rugam sa introduceti un numar intreg pentru cantitate.");

			q_field.focus();

			return false;

		}	

		

		total = Math.round(v * price * 100) / 100;

		if(unit==1) u = 'pieces'; 

		else u = 'kg';

		

		return confirm("Produs: " + product + "\nCantitate: " + v + " " + u + "\nPret total: " + total + " RON\n\nAdauga in cos?");

	}

	else{

		if(isNaN(v)){

			alert("Please enter a number for the quantity.");

			q_field.focus();

			return false;

		}

		else if(v<=0) {

			alert("Please enter a positive number for the quantity.");

			q_field.focus();

			return false;

		}

		else if(unit==1 && v!=parseInt(v)){

			alert("Please enter an integer number for the quantity.");

			q_field.focus();

			return false;

		}	

		

		total = Math.round(v * price * 100) / 100;

		if(unit==1) u = 'pieces'; 

		else u = 'kg';

		

		return confirm("Product: " + product + "\nQuantity: " + v + " " + u + "\nTotal price: " + total + " RON\n\nAdd to cart?");

	}

	

}









function check_review(lang){

	if (lang == 1) {

		if (document.review_form.title.value == "" || document.review_form.title.value == "-") {

			alert("Va rugam sa completati campul Subiect");

			document.review_form.title.focus();

			return false;

		}

		if (document.review_form.name.value == "" || document.review_form.name.value == "-") {

			alert("Va rugam sa completati campul Nume");

			document.review_form.name.focus();

			return false;

		}

		if (document.review_form.town.value == "" || document.review_form.town.value == "-") {

			alert("Va rugam sa completati campul Oras");

			document.review_form.town.focus();

			return false;

		}

		if (document.review_form.mesaj.value == "" || document.review_form.mesaj.value == "-") {

			alert("Va rugam sa completati campul Recomandare");

			document.review_form.mesaj.focus();

			return false;

		}

		if (document.review_form.code.value == "" || document.review_form.code.value == "-") {

			alert("Va rugam sa completati campul Cod");

			document.review_form.code.focus();

			return false;

		}

		return true;

	} else {

		if (document.review_form.title.value == "" || document.review_form.title.value == "-") {

			alert("Please fill in the field Subject");

			document.review_form.title.focus();

			return false;

		}

		if (document.review_form.name.value == "" || document.review_form.name.value == "-") {

			alert("Please fill in the field Name");

			document.review_form.name.focus();

			return false;

		}

		if (document.review_form.town.value == "" || document.review_form.town.value == "-") {

			alert("Please fill in the field Town");

			document.review_form.town.focus();

			return false;

		}

		if (document.review_form.mesaj.value == "" || document.review_form.mesaj.value == "-") {

			alert("Please fill in the field Review");

			document.review_form.mesaj.focus();

			return false;

		}

		if (document.review_form.code.value == "" || document.review_form.code.value == "-") {

			alert("Please fill in the field Code");

			document.review_form.code.focus();

			return false;

		}

		return true;

	}

}



function check_register_en()
{


	if (document.register.email.value=="" || document.register.email.value=="adresa@email") {
		alert("Please add your e-mail to continue.");
		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("Please add a valid email address to continue.");
			document.register.email.focus();
			return false;
	}}

	if (document.register.email_again.value!=document.register.email.value) {
		alert("Email address is wrong on rewrite.");
		document.register.email_again.focus();
		return false;
	}
	
	if (document.register.password.value=="") {
		alert("Please add your password to continue.");
		document.register.password.focus();
		return false;
	}

	if (document.register.password_again.value!=document.register.password.value) {
		alert("Your password is wrong on rewrite.");
		document.register.password_again.focus();
		return false;
	}

	if (document.register.code.value=="") {
		alert("Please add the code in the image above to continue.");
		document.register.code.focus();
		return false;
	}
	
	
	return true;
}





function check_register()
{


	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;
	}
	
	
	return true;
}




