
var comments_list_visib = 0;
var offers_all = 0;

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

var err_arr = {};
err_arr['ro'] = {"last_name" : "Trebuie sa introduceti numele", "first_name" : "Trebuie sa introduceti prenumele", "phone" : "Trebuie sa introduceti un numar de telefon", "email1" : "Trebuie sa introduceti o adresa email valida", "email2" : "Adresa email introdusa nu este valida", "message" : "Trebuie sa introduceti un mesaj"};
err_arr['en'] = {"last_name" : "You must provide your last name", "first_name" : "You must provide your first name", "phone" : "You must provide your phone number", "email1" : "You must provide a valid email adress", "email2" : "The email adress you provided is not valid", "message" : "You have to enter a message"};

function check_request_form(form, lang)
{
	var error = '';
	if (form.last_name.value.length == 0)
		error += err_arr[lang]['last_name'] + ".\n";
	if (form.first_name.value.length == 0)
		error += err_arr[lang]['first_name'] + ".\n";
	if (form.phone.value.length == 0)
		error += err_arr[lang]['phone'] + ".\n";

	var email_err = check_email(form.email.value);

	if (email_err > 0)
	{
		switch (email_err)
		{
			case 1 : error += err_arr[lang]['email1'] + ".\n";
					break;
			case 2 : error += err_arr[lang]['email2'] + ".\n";
					break;
		}
	}

	if (error.length == 0)
		return true;
	else
		alert(error);

	return false;
}

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;
}
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 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 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 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 gallery_zoom(type, lang, id, title)
{
	var mdb_width = jQuery(window).width() - 20;
	var mdb_height = jQuery(window).height() - 20;
	
	if (mdb_width > 1000)
		mdb_width = 1000;
	
	Modalbox.show("_photo_gal.php?id=" + id + "&lang=" + lang + "&type=" + type,
		{title: title,
		width: mdb_width,
		height: mdb_height});
}

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 show_highslide(src)
{
	var a_href = document.createElement('a');
	a_href.href = src;
	
	if (!hs.expand(a_href, { outlineType: 'rounded-white' }))
		window.setTimeout("hs.close(document.getElementById('highslide-wrapper-0'));", 5 * 1000);
}

function show_modal_configurator(id_nissanro)
{
	var mdb_width = jQuery(window).width() - 20;
	var mdb_height = jQuery(window).height() - 20;
	
	if (mdb_width > 1100)
		mdb_width = 1100;
	
	Modalbox.show('hosted_pages/proxyContainer.php?url=hosted_pages/configurator.php?id_nissanro=' + id_nissanro, 
		{title: 'Configurator', width: mdb_width, height: mdb_height});
}


function drive_test_form()
{								
	jQuery("#TestDriveDialog").dialog("open");
//return false;
}
function check_test_form()
{
	
	var mesaj="m";
	try
	{
	
	if(document.getElementById("tmodel").value== 'm0')
			{
				mesaj="Trebuie ales un model!";
				throw mesaj;
			}
	
	else
	if ((document.getElementById("tname_first").value.length == 0))
			{
				mesaj="Trebuie introdus prenumele!";
				throw mesaj;
			}	
	else 
			if ((document.getElementById("tname_last").value.length == 0))
			{
				mesaj="Trebuie introdus numele!";
				throw mesaj;
			}
			else
				if ((document.getElementById("tprivat").value.length == 0))
					{
						mesaj="Trebuie introdus numarul de telefon privat!";
						throw mesaj;
					}
				else
					if ((document.getElementById("date_start").value.length == 0))
					{
						mesaj="Trebuie introdusa data!";
						throw mesaj;
					}
					else
						if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test((field = jQuery("#temail")).val()))
						{
						mesaj= "Trebuie introdus o adresa de mail valida!";
						throw mesaj;
						}
						/*	
						else
						if (jQuery("#taccept")[0].checked)
							if((document.getElementById("tprivat").value.length == 0)&&((document.getElementById("tmobil").value.length == 0))&&(document.getElementById("tbirou").value.length == 0))
							{
							mesaj= "Trebuie introdus un nr de telefon!";
							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;
		}
		
	}
	
	return true;
}



jQuery(function() {	
jQuery("#TestDriveDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 480,
			//height: 120,
			resizable: false,
			buttons: {
						Cancel: function() {
							jQuery(this).dialog("close");
						}
					}
				});
jQuery("#validationErrorDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 480,
			height: 120,
			resizable: false,
			buttons: {
						Cancel: function() {
							jQuery(this).dialog("close");
							jQuery(this).dialog({title : "Eroare"});
							// titile 
						}
					}
				});
});

function service_form(){
	jQuery("#ServiceDialog").dialog("open");
//	jQuery("#ServiceContents").html("mesaj");
//	return false;
}
function check_service_form()
{
	//debugger;
	var mesaj = "m";
	// alert("check_service_form");
	try
	{
	if(document.getElementById("smodel").value== 'p0')
			{
				mesaj="Trebuie ales un model!";
				throw mesaj;
			}
	else
	if ((document.getElementById("sname_first").value.length == 0))
			{
				mesaj="Trebuie introdus prenumele!";
				throw mesaj;
			}	
	else 
			if ((document.getElementById("sname_last").value.length == 0))
			{
				mesaj="Trebuie introdus numele!";
				throw mesaj;
			}
			else
				if ((document.getElementById("sprivat").value.length == 0))
					{
						mesaj="Trebuie introdus numarul de telefon privat!";
						throw mesaj;
					}
				else
					if ((document.getElementById("sdata").value.length == 0))
					{
						mesaj="Trebuie introdusa data!";
						throw mesaj;
					}
					else
						if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test((field = jQuery("#semail")).val()))
						{
						mesaj= "Trebuie introdus o adresa de mail valida!";
						throw mesaj;
						}	
						/*
						else
						if (jQuery("#saccept")[0].checked)
							if((document.getElementById("sprivat").value.length == 0)&&((document.getElementById("smobil").value.length == 0))&&(document.getElementById("sbirou").value.length == 0))
							{
							mesaj= "Trebuie introdus un nr de telefon!";
							throw mesaj;
							}
							*/
				
	}
	
	catch (ex)
	{
		alert(ex);
		if (ex!=null)
		{
		
			if (mesaj != "m")
				document.ex=mesaj;
			jQuery("#validationErrorContents").html(ex);
			jQuery("#validationErrorDialog").dialog('option', 'title', 'Eroare');
			jQuery("#validationErrorDialog").dialog("open");
			return false;
		}
		
	}
	
	return true;
}


jQuery(function() {	
jQuery("#ServiceDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 480,
			//height: 120,
			resizable: false,
			buttons: {
						Cancel: function() {
							jQuery(this).dialog("close");
						}
					}
				});	
});

function brosura_form(){
	jQuery("#BrosuraDialog").dialog("open");
//	jQuery("#BrosuraContents").html("mesaj");
//	return false;
}
function check_brosura_form()
{
	//debugger;
	var mesaj="m";
	try
	{
	if(document.getElementById("bmodel").value== 'p0')
			{
				mesaj="Trebuie ales un model!";
				throw mesaj;
			}
	else
	if(document.getElementById("prin").value== 'b0')
			{
				mesaj="Trebuie aleasa o modalitate prin care sa fie trimisa brosura!";
				throw mesaj;
			}
	else
	if ((document.getElementById("bname_first").value.length == 0))
			{
				mesaj="Trebuie introdus prenumele!";
				throw mesaj;
			}	
	else 
			if ((document.getElementById("bname_last").value.length == 0))
			{
				mesaj="Trebuie introdus numele!";
				throw mesaj;
			}
			else 
			if ((document.getElementById("adresa1").value.length == 0))
			{
				mesaj="Trebuie introdusa adresa!";
				throw mesaj;
			}
			else 
			if ((document.getElementById("oras").value.length == 0))
			{
				mesaj="Trebuie introdus orasul!";
				throw mesaj;
			}
			else
				if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test((field = jQuery("#bemail")).val()))
						{
						mesaj= "Trebuie introdusa o adresa de mail valida!";
						throw mesaj;
						}	
				
	}
	
	catch (ex)
	{
		if (ex!=null)
		{
		//debugger;
		document.ex=mesaj;
		jQuery("#validationErrorContents").html(ex);
		jQuery("#validationErrorDialog").dialog('option', 'title', 'Eroare');
		jQuery("#validationErrorDialog").dialog("open");
		return false;
		}
		
	}
	
	return true;
}


jQuery(function() {	
jQuery("#BrosuraDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 480,
			//height: 120,
			resizable: false,
			buttons: {
						Cancel: function() {
							jQuery(this).dialog("close");
						}
					}
				});	
});

function accesorii_form()
{
	jQuery("#AccesoriiDialog").dialog("open");
//	jQuery("#AccesoriiContents").html("mesaj");
//	return false;
}
function check_accesorii_form()
{
	//debugger;
	var mesaj="m";
	try
	{
	if(document.getElementById("amodel").value== 'p0')
			{
				mesaj="Trebuie ales un model!";
				throw mesaj;
			}
	else
	if ((document.getElementById("aname_first").value.length == 0))
			{
				mesaj="Trebuie introdus prenumele!";
				throw mesaj;
			}	
	else 
			if ((document.getElementById("aname_last").value.length == 0))
			{
				mesaj="Trebuie introdus numele!";
				throw mesaj;
			}
			else
				if ((document.getElementById("aprivat").value.length == 0))
					{
						mesaj="Trebuie introdus numarul de telefon privat!";
						throw mesaj;
					}
					else
						if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test((field = jQuery("#aemail")).val()))
						{
						mesaj= "Trebuie introdusa o adresa de mail valida!";
						throw mesaj;
						}	/*
						else 
						if (jQuery("#aaccept")[0].checked)
							if((document.getElementById("aprivat").value.length == 0)&&((document.getElementById("amobil").value.length == 0))&&(document.getElementById("abirou").value.length == 0))
							{
							mesaj= "Trebuie introdus un nr de telefon!";
							throw mesaj;
							}
							else
								if ((document.getElementById("accesorii").value.length == 0))
									{
										mesaj="Trebuie alese accesoriile!";
										throw mesaj;
									}
									*/
				
	}
	
	catch (ex)
	{
		if (ex!=null)
		{
		//debugger;
		document.ex=mesaj;
		jQuery("#validationErrorContents").html(ex);
		jQuery("#validationErrorDialog").dialog('option', 'title', 'Eroare');
		jQuery("#validationErrorDialog").dialog("open");
		return false;
		}
		
	}
	
	return true;
}


jQuery(function() {	
jQuery("#AccesoriiDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 480,
			//height: 120,
			resizable: false,
			buttons: {
						Cancel: function() {
							jQuery(this).dialog("close");
						}
					}
				});	
});

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 switch_offers()
{
	if (offers_all)
	{
		jQuery(".hidden_offer_items").hide("slow");
		document.getElementById("btn_toate_ofertele").src = base_href + "i/toate_ofertele.gif";
		offers_all = 0;
	}
	else
	{
		jQuery(".hidden_offer_items").show("slow");
		document.getElementById("btn_toate_ofertele").src = base_href + "i/toate_ofertele_i.gif";
		offers_all = 1;
	}
}

function hide_offers()
{
	if (offers_all)
	{
		jQuery(".hidden_offer_items").hide("slow");
		document.getElementById("btn_toate_ofertele").src = base_href + "i/toate_ofertele.gif";
		offers_all = 0;
	}
}