function changeBgImage (image, id) {
							var element = document.getElementById(id);
							element.style.backgroundImage = "url("+image+")";
						}

function ajax_check_captcha()
{
	
	var resp = makePOSTRequestCallback('_captcha_ajax.php', 'contact_form', null, null, true);
	if (resp == 'true')
	{
		return "true";
	}
	else
	{
		return "false";
	}
}

function fancybox_close()
{
    jQuery('#fancybox-tmp').hide();
    jQuery('#fancybox-overlay').hide();
    jQuery('#fancybox-loading').hide();
    jQuery("#fancybox-wrap").hide();
}

function openDaciaPopup()
{
	fancybox_close();
	jQuery(".iframe").fancybox(
		{
			width: 950,
			height: 650,
			onStart : function () {
				jQuery(".iframe").show();
			},
			onClosed : function () {
				jQuery(this).remove();
				jQuery("#fancybox-frame").remove();
			},
		}
			).trigger('click');
}

function ajax_check_captcha2()
{
	
	var resp = makePOSTRequestCallback('_captcha_ajax.php', 'rezervare_form', null, null, true);
	if (resp == 'true')
	{
		return "true";
	}
	else
	{
		return "false";
	}
}

/*function ajax_check_captcha()
{
	var resp = makePOSTRequestCallback('_captcha_ajax.php', 'contact', null, null, true);
	if (resp == 'true')
		return true;
	else
		return false;
}*/

function popupPromoShow()
{
	Modalbox.show("_promo_popup.php?model=",
			{title: "Promo",
			width: 800 + 20,
			height: 490 + 70});
}

function gallery_zoom(type, lang, id, title)
{
	Modalbox.show("_photo_gal.php?id=" + id + "&lang=" + lang + "&type=" + type,
		{title: title,
		width: 800 + 20,
		height: 625 + 70});
}

function newsletter_zoom(lang, id, title)
{
	Modalbox.show("newsletter.php?lang=" + lang,
		{title: title,
		width: 800 + 20,
		height: 225 + 70});
}

var images = [];
var images_pos = 0;
var images_count = 0;

function slide_next_img()
{
	if ((images_pos + 1) < images_count)
	{
		images_pos++;
	}
	else
	{
		images_pos = 0;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
		document.getElementById("slide_big_href").href = base_href + images[images_pos]["orig_path"];
		document.getElementById("img_desc").innerHTML = images[images_pos]["info"];
	}
}

function slide_prev_img()
{
	if ((images_pos - 1) >= 0)
	{
		images_pos--;
	}
	else
	{
		images_pos = images_count - 1;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
		document.getElementById("slide_big_href").href = base_href + images[images_pos]["orig_path"];
		document.getElementById("img_desc").innerHTML = images[images_pos]["info"];
//		document.getElementById("MB_caption").innerHTML = images[images_pos]["name"];
	}
}

var oss_timerid = 0;
var oss_status = "stop";

function play_pause_ss()
{
	if (oss_status == "stop")
	{
		oss_status = "play";
		document.getElementById("play_pause_ss").innerHTML = "Pause";
		slideshow_me();
	}
	else
		pause_ss();
}

function pause_ss()
{
	oss_status = "stop";
	document.getElementById("play_pause_ss").innerHTML = "Play";
	clearTimeout(oss_timerid);
	oss_timerid = 0;
}

function slideshow_me()
{
	slide_next_img();
	clearTimeout(oss_timerid);
	oss_timerid = setTimeout("slideshow_me()", 3000);
}

function modal_show_img(img, title, width, height)
{
	Modalbox.show("<center><img src='"+img+"' /></center>", {title: title, width: width + 50, height: height + 60});
}

function load_movie(src, width, height, div_id, autostart)
{
	var so = new SWFObject('mediaplayer.swf','mpl',width,height,'7');
	so.addParam('allowfullscreen','false');
	so.addVariable('file', src);
	so.addParam('wmode', 'transparent');
	so.addVariable('backcolor','0xffffff');
	so.addVariable('autostart', autostart);
	so.addVariable('width', width);
	so.addVariable('height', height);
	so.write(div_id);
}
function printit(){  
	
			if (window.print) {
  				 window.print();  
			} 
				else {
			   			var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
						document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
			   			WebBrowser1.ExecWB(6, 2);
					}
}

function print_page(link)
{
	windowW = 726;
	windowH = 600;
	windowX = (screen.width / 2) - (windowW / 2);
	windowY = (screen.height / 2) - (windowH / 2);
	var EB = window.open("printeaza-pagina.html?pagina=" + link, 
		"print_page", "width = " + windowW + ", height = " + windowH + 
		", fullscreen = 0, toolbar = 0, location = 0, directories = 0, status = 0, menubar = 0, scrollbars = yes, resizable = 0", 
		true);
	EB.resizeTo(windowW, windowH);
	EB.moveTo(windowX,windowY);
	EB.focus();
}

var scrolled = 0;
function scroll_gallery()
{
	var width = document.getElementById('top_gallery2_table').offsetWidth;
	var inc = 1;
	
	scrolled += inc;
	if (scrolled < width)
	{
		document.getElementById('top_gallery2').scrollLeft += inc;
		gal_timer = setTimeout("scroll_gallery('"+ scrolled +"', '"+ width +"')", 100);
	}
	else
	{
		clearTimeout(gal_timer);
		gal_timer = 0;
	}
}

function stopScroll()
{
	clearTimeout(gal_timer);
	gal_timer = 0;
}

if (document.addEventListener)
	document.addEventListener("DOMContentLoaded", DOMLoaded, false);
window.onload = DOMLoaded;
function DOMLoaded()
{
	
}

function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function check_email(email)
{
	errors = 0;
	var ero="`=[];\',/\\#$%^&*()+{}:\"<>?| ";
	var ned="@.";
	var er=0;

	var a = email;
	if (a.length==0)
		errors = 1;
	else
		if (a.length<4)
			errors = 2;
		else
		{
			for (j=0; j<=ero.length-1; j++)
				if (a.indexOf(ero.substring(j,j+1))!=-1)
					er=1;
			for (j=0; j<=ned.length-1; j++)
			{
				aos = a.split(ned.substring(j,j+1));
				for (var i=0; i < aos.length-1; i++)
					if (aos[i]<1)
						er=1;
				if (a.indexOf(ned.substring(j,j+1))==-1)
					er=1;
			}
			if (er==1)
			errors = 2;
		}

	return errors;
}

function add_remove_newsletter(fform, flang, faction)
{
	var email = (fform.email.value == 'email') ? '' : fform.email.value;
	var email_error = check_email(email);
	if (email_error > 0)
	{
		if (flang != "ro")
		{
			if (email_error == 1)
				alert("You have to enter a valid email address!\n\n");
			else if (email_error == 2)
				alert("The email address you enterd is not valid!\n\n");
		}
		else
		{
			if (email_error == 1)
				alert("Trebuie sa introduceti o adresa de email valida!\n\n");
			else if (email_error == 2)
				alert("Adresa de email introdusa nu este valida!\n\n");
		}
		return;
	}
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			switch (xmlHttp.responseText)
			{
				case "Succes":
					if (flang != "ro")
					{
						if (faction == "add")
							alert("You have successfully subscribed to our newsletter.\n\n"
								+ "If you wish to unsubscribe, please send us an e-mail to contact@mail with the subject 'Unsubscribe'\n\n"
								+ "Thank you!");
						else
							alert("You have unsubscribed from our newsletter!\n\n"
								+ "If you wish to subscribe again, please fill the subscription form!\n\n"
								+ "Thank you!");
					}
					else
					{
						if (faction == "add")
							alert("Ati fost inclus in baza noastra de date pentru a primi newsletter.\n\n"
								+ "Daca doriti sa va dezabonati trimiteti un e-mail la adresa contact@mail cu subiectul 'Dezaboneaza'\n\n"
								+ "Va multumim!");
						else
							alert("Ati renuntat la optiunea de a primi newsletter!\n\n"
								+ "Daca doriti sa va re-abonati completati formularul de abonare newsletter!\n\n"
								+ "Va multumim!");
					}
					break;
				case "Date insuficiente":
					if (flang != "ro")
					{
						alert("You haven't provided all the necesary info!\n\n"
							+ "Please try again!");
					}
					else
					{
						alert("Nu ati introdus toate datele necesare!\n\n"
							+ "Va rugam reincercati!");
					}
					break;
				case "Eroare DB":
					if (flang != "ro")
					{
						alert("An error has occured while processing your request!\n\n"
							+ "Please try again!");
					}
					else
					{
						alert("A aparut o eroare in procesarea datelor dvs!\n\n"
							+ "Va rugam reincercati!");
					}
					break;
				case "Eroare User":
					if (flang != "ro")
					{
						if (faction == "add")
							alert("You have already subscribed to our newsletter!\n\n"
								+ "Thank you!");
						else
							alert("You are not subscribed to our newsletter!\n\n"
								+ "Thank you!");
					}
					else
					{
						if (faction == "add")
							alert("Sunteti deja inscris la newsletter!\n\n"
								+ "Va multumim!");
						else
							alert("Nu sunteti inscris la newsletter!\n\n"
								+ "Va multumim!");
					}
					break;
			}
		}
	}
	var vars = "?action=" + faction + "&email=" + email;
	xmlHttp.open ("GET", "_newsletter.php" + vars, true); // add vars
	xmlHttp.send (null);
}

function makePOSTRequestCallback(url, form_name, callbackFunction, params, sync)
{
	var parameters = getFormParams(form_name);
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
	 	// set type accordingly to anticipated content type
	    //http_request.overrideMimeType('text/xml');
	    http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	    try {
	       http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	 }
	}
	if (!http_request)
	{
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	
	if (!sync)
	{
		http_request.onreadystatechange = function ()
		{
			 if (http_request.readyState == 4)
	      {
	         if (http_request.status == 200)
	         {
	            var response = http_request.responseText;
					var functionToCall = callbackFunction +
					'(response,'+params+')';
					if(debug)
					{
						// alert(response);
						// alert(functionToCall);
					}
					eval(functionToCall);
	         }
	         else
	         {
	            alert('There was a problem with the request.');
	         }
	      }
		};
	}
		
	if (sync)
	{
		http_request.open('POST', url, false);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		
		//alert(parameters['captcha_check']);
		
		http_request.send(parameters);
		
		if (http_request.status == 200)
			return http_request.responseText;
		else
			alert('There was a problem with the request.');
	}
	else
	{
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
}

function makePOSTRequest(url, form_name, div_id)
{
	var parameters = getFormParams(form_name);
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
	 	// set type accordingly to anticipated content type
	    //http_request.overrideMimeType('text/xml');
	    http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	    try {
	       http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	 }
	}
	if (!http_request)
	{
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	
	http_request.onreadystatechange = function ()
		{
			 if (http_request.readyState == 4)
	      {
	         if (http_request.status == 200)
	         {
	            if (div_id && document.getElementById(div_id))
	            {
	            	document.getElementById(div_id).innerHTML = http_request.responseText;
	            }
	            else
	            {
	            	alert(http_request.responseText);
	            }
	         }
	         else
	         {
	            alert('There was a problem with the request.');
	         }
	      }
		};
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function getFormParams(form_name)
{
	var inps = document.forms[form_name].getElementsByTagName("input");
	var sels = document.forms[form_name].getElementsByTagName("select");
	var texts = document.forms[form_name].getElementsByTagName("textarea");
	
	var all = {};
	
	for (var x=0; x<inps.length; x++) all[inps[x].name] = inps[x].value;
	for (var x=0; x<sels.length; x++) all[sels[x].name] = sels[x].value;
	for (var x=0; x<texts.length; x++) all[texts[x].name] = texts[x].value;
	
	var str = "";
	for (var k in all)
	{
		str += k + "=" + encodeURI(all[k]) + "&";
	}
	
	return str;
}
function show_pdf(title, file)
{
	// alert();
	var mdb_width = jQuery(window).width() - 20;
	var mdb_height = jQuery(window).height() - 20;
	
	if (mdb_width > 1200)
		mdb_width = 1200;
	
	Modalbox.show("<iframe name='"+title+"' frameborder='0' width='100%' height='97%' scrollbars='yes' src='"+file+"'></iframe>", 
		{title: title,
		 width: mdb_width,
		 height: mdb_height});

	return false;
}

function checkSearch()
{
	if(document.getElementById('q').value.length<=2)
		{
		 jQuery('#validationErrorContents').html('Trebuie introdus un cuvant pentru a fi cautat!');
		 
		 jQuery('#validationErrorDialog').dialog('open');
		
					return false;
		}
	return true;
}

function body_onload(el)
{
	if (self.document.location.hash && 
		((self.document.location.hash == "#popupthanksmessage") || (self.document.location.hash == "popupthanksmessage")))
	{
		//alert("popupthanksmessage");
		jQuery("#validationErrorContents").html("Datele au fost salvate. Va multumim!");
		// jQuery("#validationErrorDialog").attr("title", "Succes");
		// jQuery("#ui-dialog-title-validationErrorDialog").html("Succes");
		// $('.selector').dialog({ title: 'Dialog Title' });
		// $('.selector').dialog('option', 'title', 'Dialog Title');
		jQuery("#validationErrorDialog").dialog('option', 'title', 'Succes');
		jQuery("#validationErrorDialog").dialog("open");
		
		// jQuery("#validationErrorDialog").attr("title", "Error");
		
		self.document.location.hash = "";
	}
	
//	jQuery('.detalii_model_right_text').jScrollPane();
	
	if (document.getElementById("ss_container"))
		ss_play();
		
		
	if (jQuery("#div_oferta") && (jQuery("#div_oferta").length > 0))
	{
		// alert("attaching");
		jQuery("#div_oferta").mouseout(function()
		{
		      // hide_offers();
		});
	}
	
	// jQuery('.detalii_model_right .jScrollPaneTrack').css("left", "370px");
	
	// alert(jQuery('.detalii_model_right_text .jScrollPaneTrack').length);

	// left: 370px;
	/*
	if (jQuery('.sub_menu_content') != null)
	{
		// alert(jQuery('.sub_menu_content').length);
		// alert(jQuery('.sub_menu_content').jScrollHorizontalPane);
		// jQuery('.sub_menu_content').show();
		jQuery('.sub_menu_content').jScrollHorizontalPane({scrollbarHeight:10, scrollbarMargin:0});
		
		// jQuery('.sub_menu_content').hide();
	}
	*/

}



function print_page(link)
{
	windowW = 726;
	windowH = 600;
	windowX = (screen.width / 2) - (windowW / 2);
	windowY = (screen.height / 2) - (windowH / 2);
	var EB = window.open("printeaza-pagina.html?pagina=" + link, 
		"print_page", "width = " + windowW + ", height = " + windowH + 
		", fullscreen = 0, toolbar = 0, location = 0, directories = 0, status = 0, menubar = 0, scrollbars = yes, resizable = 0", 
		true);
	EB.resizeTo(windowW, windowH);
	EB.moveTo(windowX,windowY);
	EB.focus();
}

function checkContactForm()
{
	// alert("checkContactForm");
	var mesaj="m";
	try
	{
		if(document.getElementById("surname").value.length == 0)
		{
			mesaj="Trebuie introdus prenumele!";
			throw mesaj;
		}
		else
		{
			if(document.getElementById("name").value.length == 0)
				{
					mesaj="Trebuie introdus numele!";
					throw mesaj;
				}
			else
			{
				if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test((field = jQuery("#email")).val()))
				{
					mesaj= "Trebuie introdus o adresa de mail valida!";
					throw mesaj;
				}
				/*if(document.getElementById("email").value.length == 0)
				{
					mesaj="Trebuie introdusa adresa de e-mail!";
					throw mesaj;
				}*/
			}
		}
	}
	catch(ex)
	{
		if (ex!=null)
		{
			document.ex=mesaj;
			jQuery("#validationErrorContents").html(ex);
			jQuery("#validationErrorDialog").dialog('option', 'title', 'Eroare');
			jQuery("#validationErrorDialog").dialog("open");
			return false;
		}
	}
}

function OpenForm()
{
	jQuery("#TestDriveContens").html();
 	jQuery("#TestDriveDialog").dialog("open");	
	return false;
}

function changeBgImage (image, id)
{
	var element = document.getElementById(id);
	element.style.backgroundImage = "url("+image+")";
}


