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_technicals(title, file)
{
	Modalbox.show("<iframe name='"+title+"' frameborder='0' width='100%' height='95%' scrollbars='yes' src='"+file+"'></iframe>", 
		{title: title,
		 width: 820,
		 height: 695}); 
		 
	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("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 fade_in_fade_out(el, way, texts)
{
	var the_op = Math.min(getOpacity(el) + (0.3 * way), 1);
	setOpacity(el, the_op);
	if (way == 1)
	{
		if (the_op < 1)
			timer_id = setTimeout("fade_in_fade_out('" + el + "', 1, '"+texts+"')", 100);
		else
			timer_id = setTimeout("fade_in_fade_out('" + el + "', -1, '"+texts+"')", 4000);
	}
	else
	{
		if (the_op > 0)
			timer_id = setTimeout("fade_in_fade_out('" + el + "', -1, '"+texts+"')", 100);
		else
		{
			change_text(el, texts);
			timer_id = setTimeout("fade_in_fade_out('" + el + "', 1, '"+texts+"')", 150);
		}
	}
}
function stop_fifo(el, timer_id)
{
	clearTimeout(timer_id);
	setOpacity(el, 1);
	timer_id = 0;
}

var the_text_ind = 2;
function change_text(el, texts)
{
	element = document.getElementById(el);
	var arr_length = eval(texts + '.length');
	var pos = 0;
	pos = parseInt(the_text_ind++ / 2) % arr_length;
	
	element.innerHTML = eval(texts + '[' + pos + ']');
}

function setOpacity(el, value)
{
	element = document.getElementById(el);
	var set_value = (value === '') ? '0' : (value < 0.00001) ? 0 : value;
	element.style.opacity = set_value;
	element.style.filter  = "alpha(opacity=" + parseInt(set_value * 100) + ")";
	element.opac = set_value;
}

function getOpacity(el)
{	
	var val = document.getElementById(el).opac;
	if (typeof val != 'undefined')
		return parseFloat(val);
	else
    	return 1.0;
}

var scrolled = 0;
var timerId = 0;
function scrollbar()
{
	var total_width = (document.getElementById("scrollbar").getElementsByTagName('div')[0].offsetWidth)/2;
	var inc = 2;
	
	scrolled += inc;
	if (scrolled > total_width)
	{
		document.getElementById("scrollbar").scrollLeft = 0;
		scrolled = 0;
	}
	else
		document.getElementById("scrollbar").scrollLeft += inc;
	timerId = setTimeout("scrollbar('" + scrolled + "', '" + total_width + "')", 50);
}

function scrollStop()
{
	clearTimeout(timerId);
	timerId = 0;
}
