var registerformsubmit = false;
var loginformsubmit = false;
var sendformsubmit = false;
var movierate=new Array();
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
function checkSendCodeForm(form){
	if (form.email.value == ""){
		var dialog_obj = {width:250, height:150,title:'Atentie',html:"Completeaza campul email"};
		addDialog(dialog_obj);
		return false;
	}else{
		if(!echeck(form.email.value)){
			dialog_obj = {width:250, height:150,title:'Atentie',html:"Email invalid"};
			addDialog(dialog_obj);
		}else{
			loadModal();
			var http = ajaxFunction();//don't worry about this
			var my_link = "./sendCode.php?email="+form.email.value;
			http.open("GET", my_link, true);
			http.onreadystatechange = function(){
				checkSendCodeFormResponse(http, form);
			}
			http.send(null);
		}
		return false;
	}
}
function checkSendCodeFormResponse(http, form){
	var msg = "";
	if (http.readyState == 4)
	{
		removeModal();
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		sResults = sResults.split("&");
		lcode = sResults[0];
		msg = "";
		form.send.value="trimite";
		var boo=false;
		form.email.disabled=boo;
		form.send.disabled=boo;
		if (lcode == "-1"){
			var dialog_obj = {width:250, height:150,title:'Atentie',html:"Acest email nu exista in baza de date"};
			addDialog(dialog_obj);
		}else{
			if (lcode == "0"){
				dialog_obj = {width:250, height:150,title:'Atentie',html:"Contul dumneavoastra este deja activat"};
				addDialog(dialog_obj);
			}else{
				dialog_obj = {width:250, height:150,title:'Atentie',html:"Email trimis"};
				addDialog(dialog_obj);
			}
		}
	}
}
function checkLoginForm(form){
	loadModal();
	if(loginformsubmit){
		return loginformsubmit;
	}else{
		var http = ajaxFunction();//don't worry about this
		var my_link = "./checkLogin.php?email="+form.email.value+"&password="+form.password.value;
		http.open("GET", my_link, true);
		http.onreadystatechange = function(){
			checkLoginFormResponse(http, form);
		}
		http.send(null);
		return loginformsubmit;
	}
}
function checkLoginFormResponse(http, form){
	var msg = "";
	if (http.readyState == 4)
	{
		removeModal();
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		sResults = sResults.split("&");
		lcode = sResults[0];
		msg = "";
		if (lcode == "false") msg += "Email sau parola incorecte\n";
		if (msg != ''){
			var dialog_obj = {width:250, height:150,title:'Atentie',html:msg};
			addDialog(dialog_obj);
			return false;
		}
		else{
			form.submit();
			return true;
		}
	}else{
		return false;
	}
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

		 return true					
}
	function ajaxFunction()
	{
		var xmlHttp;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		return xmlHttp;
	}
function voteout(v,jtype, jvalue){
	var vd = document.getElementById('votedesc_'+jvalue);
	vd.innerHTML = "";
	setVoteStars(movierate[jvalue],jtype,jvalue);
}
function voteover(v, jtype,jvalue){
	arr = ["", "Nota 1", "Nota 2", "Nota 3", "Nota 4", "Nota 5"];
	if(jtype=='movie'){
		arr = ["", "Slab", "Asa si asa", "Merita vazut", "Foarte bun", "Film de oscar"];
	}
	var vd = document.getElementById('votedesc_'+jvalue);
	vd.innerHTML = "<div class=\"vdesc\" style=\"position:absolute;\">"+arr[v]+"</div>";
	setVoteStars(v,jtype,jvalue);
}
function loginUpdate(){
	var id_user = checkIdUser('Logheaza-te pentru a completa pagina');
}
function vote(v,id,jtype,jvalue){
	var id_user = checkIdUser('Logheaza-te pentru a vota');
	if(id_user==0) return;
	var http = ajaxFunction();//don't worry about this
	var my_link = "./dovote.php?v="+v+"&id="+id+"&jtype="+jtype+"&jvalue="+jvalue;
	http.open("GET", my_link, true);
	http.onreadystatechange = function(){
		voteResponse(http, id,jtype,jvalue);
	}
	http.send(null);
}
function deletevote(id,jtype,jvalue){
	var id_user = Get_Cookie('id_user');
	if(id_user==null){
		return;
	}
	var http = ajaxFunction();//don't worry about this
	var my_link = "./deletevote.php?id="+id+"&jtype="+jtype+"&jvalue="+jvalue;
	http.open("GET", my_link, true);
	http.onreadystatechange = function(){
		voteResponse(http, id,jtype,jvalue);
	}
	http.send(null);
}
function voteResponse(http, id,jtype,jvalue){
	if (http.readyState == 4)
	{
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		sResults = sResults.split("&");
		if(sResults[3]!="-1"){
			var dialog_obj = {width:250, height:150,title:'Vot',html:sResults[0]};
			addDialog(dialog_obj);
		}
		if(sResults[1]=="err") return;
		movierate[jvalue] = sResults[1];
		var v = sResults[2]=='1'?'vot':'voturi';
		var y=''
		if(sResults[3]!="-1"){
			y=", votul tau "+sResults[3]+" <a href='javascript:;' title=\"sterge\" onclick='deletevote("+id+",\""+jtype+"\","+jvalue+")'><img src=\"images/close.gif\" border=\"0\" /></a>&nbsp;";
		}
		document.getElementById("therating_"+jvalue).innerHTML = sResults[1]+"/5 ("+sResults[2]+" "+v+y+")";
		setVoteStars(sResults[1],jtype,jvalue)
	}
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function setVoteStarsHtml(no, parent){
	var nn = no - Math.floor(no) <0.5?0:1;
	var html = "";
	var star = "";
	var n=0;
	for(var i=1; i<=Math.floor(no); i++){
		html += "<img src=\"images/star.jpg\" />";
	}
	if(nn==1){
		html += "<img src=\"images/hstar.jpg\" />";
	}
	for(var i=Math.floor(no)+nn+1; i<=5; i++){
		html += "<img src=\"images/staru.jpg\" />";
	}
	document.getElementById(parent).innerHTML=html;
}
function setVoteStars(no,jtype,jvalue){
	var nn = no - Math.floor(no) <0.5?0:1;
	var star = "";
	for(var i=1; i<=Math.floor(no); i++){
		star = "star.jpg";
		document.getElementById("star"+i+"_"+jvalue).src = "images/"+star;
	}
	if(nn==1){
		star = "hstar.jpg";
		document.getElementById("star"+i+"_"+jvalue).src = "images/"+star;
	}
	for(var i=Math.floor(no)+nn+1; i<=5; i++){
		star = "staru.jpg";
		document.getElementById("star"+i+"_"+jvalue).src = "images/"+star;
	}
}
function sendcomment(form){
	var id_user = checkIdUser('Logheaza-te pentru a trimite comentarii');
	if(id_user==0) return false;
	if (tinyMCE.get('comment').getContent()==""){
		var dialog_obj = {width:250, height:150,title:'Atentie',html:"Comentariu nu poate fi gol"};
		addDialog(dialog_obj);
		return false;
	}
	return true;
}
function changecb(cb){
	Set_Cookie("cb_"+cb.id, cb.checked, '', '/', '', '' );
}
function increaseDownlods(id,id1){
	document.getElementById(id).innerHTML = "Descarcari:&nbsp;"+(parseInt(document.getElementById(id).innerHTML.split("Descarcari:&nbsp;")[1])+1);
//	document.location = 'downloadSubtitle.php?id='+id1;
}
function checkSearch(form){
	if(Get_Cookie("cb_movies")=="false" && Get_Cookie("cb_subtitles")=="false" && Get_Cookie("cb_actors")=="false"){
		var dialog_obj = {width:250, height:150,title:'Atentie',html:'Selecteaza filme, subtitrari sau actori.'};
		addDialog(dialog_obj);
		return false;
	}
	if(form.q.value.length<3){
		dialog_obj = {width:250, height:150,title:'Atentie',html:'Introdu cel putin 3 caractere.'};
		addDialog(dialog_obj);
		return false;
	}
	return true;
}
function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}
function checkModifyMyAccount(form){
	var id_user = checkIdUser('Logheaza-te');
	if(id_user==0) return;
	msg='';
	if (form.name.value == "") msg += "- Nume<br />";
	if (form.location.value == "") msg += "- Locatia<br />";
	if (!isUrl(form.website.value)&&form.website.value!="") msg += "- Website invalid<br />";
	if (msg != ''){
		msg = "Verificati urmatoarele campuri:<br />" + msg;
		var dialog_obj = {width:250, height:200,title:'Atentie',html:msg};
		addDialog(dialog_obj);
		return false;
	}
	return true;
}
var act_v='';
function searchActors(inp,holder,display,offset){
	if(inp.value == act_v){
		return;
	}else{
		act_v = inp.value;
	}
	var http = ajaxFunction();//don't worry about this
	var my_link = "./searchActors.php?q="+inp.value;
	http.open("GET", my_link, true);
	http.onreadystatechange = function(){
		searchActorsResponse(http,holder,inp,display,offset);
	}
	http.send(null);
}
function searchActorsResponse(http,holder,inp,display,offset){
	if (http.readyState == 4)
	{
		var actors = document.getElementById(display);
		var _close = document.getElementById("close"+display);
		var cast = document.getElementById(holder);
		var cast1 = document.getElementById("save");
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		if(sResults=='' || inp.value==''){
			actors.innerHTML = '';
			actors.style.display = 'none';
			cast1.style.paddingBottom = "0px";
			_close.style.display = 'none';
		}else{
			sResults = sResults.split("!@#$");
			var html = '<ul style="width:200px; position:relative;">';
			for(var i=0;i<sResults.length;i++){
				var tmp = sResults[i].split("----");
				if(tmp[0]!=''){
					html += '<li style="padding:1px;" ><a href="javascript:;" onclick="addActor(\''+Url.encode(tmp[0])+'\', \''+tmp[1]+'\', \''+tmp[2]+'\', \''+holder+'\', \''+inp.id+'\', \''+display+'\');">'+tmp[0]+'</a></li>';
				}
			}
			html += '</ul>';
			actors.innerHTML = html;
			actors.style.display = 'block';
			_close.style.display = 'block';
			var c1 = document.getElementById("cast");
			var c2 = document.getElementById("dirs");
			var i1=0;
			for(var i=0;i<c1.childNodes.length;i++){
				if(c1.childNodes.item(i).id!=undefined){
					i1++;
				}
			}
			var i2=0;
			for(var i=0;i<c2.childNodes.length;i++){
				if(c2.childNodes.item(i).id!=undefined){
					i2++;
				}
			}
			var c = (Math.ceil(i1/3)*16);
			c = holder=='dirs'?c:0;
			var off = actors.offsetHeight-c-offset;
			var off = off<0?0:off;
			cast1.style.paddingBottom = off+"px";
		}
	}
}
function addActor(name,nameenc,id,holder,inp1,display){
	name = Url.decode(name);
	var actors = document.getElementById(display);
	var inp = document.getElementById(inp1);
	var cast1 = document.getElementById("save");
	var _close = document.getElementById("close"+display);
	inp.value='';
	actors.innerHTML = '';
	actors.style.display = 'none';
	_close.style.display = 'none';
	if(document.getElementById(holder+"_"+holder+id)==null){
		var cast = document.getElementById(holder);
		var html = cast.innerHTML;
		cast.innerHTML = html+'<li class="actcast" id="'+holder+"_"+holder+id+'" captio="'+holder+'"><div style="cursor:move">'+name+'&nbsp;<a href="javascript:;" onclick="removeMe(\''+holder+"_"+holder+id+'\')"><img src="./images/close.gif" border="0" /></a></div></li>';
		Sortable.create(holder,{dropOnEmpty:true,containment:[holder],constraint:false,onChange:function(){}});
	}else{
		if(holder=='cast'){
			var dialog_obj = {width:250, height:150,title:'Atentie',html:"Actorul exista in lista."};
			addDialog(dialog_obj);
		}else{
			dialog_obj = {width:250, height:150,title:'Atentie',html:"Regizorul exista in lista."};
			addDialog(dialog_obj);
		}
	}
	cast1.style.paddingBottom = '0px';
}
function removeMe(id){
	document.getElementById(id).parentNode.removeChild(document.getElementById(id));
}
function myBlur(id,display){
	setTimeout('theBlur(\''+id+'\', \''+display+'\')', 200)
}
function theBlur(id,display){
	document.getElementById(id).value='';
	var actors = document.getElementById(display);
	var _close = document.getElementById("close"+display);
	actors.innerHTML = ''
	actors.style.display = 'none';
	var cast1 = document.getElementById("save");
	_close.style.display = 'none';
	cast1.style.paddingBottom = '0px';
	act_v = '';
}
function searchMovies(inp,holder,display,offset){
	if(inp.value == act_v){
		return;
	}else{
		act_v = inp.value;
	}
	var http = ajaxFunction();//don't worry about this
	var my_link = "./searchMovies.php?q="+inp.value;
	http.open("GET", my_link, true);
	http.onreadystatechange = function(){
		searchMoviesResponse(http,holder,inp,display,offset);
	}
	http.send(null);
}
function searchMoviesResponse(http,holder,inp,display,offset){
	if (http.readyState == 4)
	{
		var actors = document.getElementById(display);
		var _close = document.getElementById("close"+display);
		var cast = document.getElementById(holder);
		var cast1 = document.getElementById("save");
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		if(sResults=='' || inp.value==''){
			actors.innerHTML = '';
			actors.style.display = 'none';
			cast1.style.paddingBottom = "0px";
			_close.style.display = 'none';
		}else{
			sResults = sResults.split("!@#$");
			var html = '<ul style="width:200px; position:relative;">';
			for(var i=0;i<sResults.length;i++){
				var tmp = sResults[i].split("----");
				if(tmp[0]!=''){
					html += '<li style="padding:1px;" ><a href="javascript:;" onclick="addMovie(\''+Url.encode(tmp[0])+'\', \''+tmp[1]+'\', \''+tmp[2]+'\',  \''+tmp[3]+'\', \''+holder+'\', \''+inp.id+'\', \''+display+'\');">'+tmp[0]+' ('+tmp[3]+')</a></li>';
				}
			}
			html += '</ul>';
			actors.innerHTML = html;
			actors.style.display = 'block';
			_close.style.display = 'block';
			var c1 = document.getElementById("umovies");
			var c2 = document.getElementById("dmovies");
			var c = c2.offsetHeight;
			c = holder=='umovies'?c:0;
			var off = actors.offsetHeight-c-offset;
			var off = off<0?0:off;
			cast1.style.paddingBottom = off+"px";
		}
	}
}
function addMovie(name,nameenc,id,year,holder,inp1,display){
	name = Url.decode(name);
	var actors = document.getElementById(display);
	var inp = document.getElementById(inp1);
	var cast1 = document.getElementById("save");
	var _close = document.getElementById("close"+display);
	inp.value='';
	actors.innerHTML = '';
	actors.style.display = 'none';
	_close.style.display = 'none';
	if(document.getElementById(holder+"_"+holder+id)==null){
		var cast = document.getElementById(holder);
		var html = cast.innerHTML;
		cast.innerHTML = html+'<li id="'+holder+"_"+holder+id+'" captio="movies"><div>'+name+'&nbsp;('+year+')&nbsp;<a href="javascript:;" onclick="removeMe(\''+holder+"_"+holder+id+'\')"><img src="./images/close.gif" border="0" /></a></div></li>';
	}else{
		var dialog_obj = {width:250, height:150,title:'Atentie',html:"Filmul exista in lista."};
		addDialog(dialog_obj);
	}
	cast1.style.paddingBottom = '0px';
}

function loadModal(){
	try{
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
//				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
//				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG20");//use background and opacity
		}
		
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
	}catch(err){
	}
}
function removeModal() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	return false;
}
function updateMovie(){
	loadModal();
	var msg='';
	var movie_title = document.getElementById('movie_title');
	var movie_website = document.getElementById('movie_website');
	var movie_year = document.getElementById('movie_year');
	var movie_length = document.getElementById('movie_length');
	var movie_genres = document.getElementById('movie_genres');
	var dirs = document.getElementById('dirs');
	var cast = document.getElementById('cast');
	if(movie_title.value=="") msg += "- Titlu<br />";
	if (!isUrl(movie_website.value)&&movie_website.value!="") msg += "- Site oficial invalid<br />";
	if(msg != ''){
		msg = "Verificati urmatoarele campuri:<br />" + msg;
		removeModal();
		var dialog_obj = {width:250, height:200,title:'Atentie',html:msg};
		addDialog(dialog_obj);
		return;
	}
	var genres=new Array();
	for(var i=0;i<movie_genres.childNodes.length;i++){
		var it = movie_genres.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='movie_genre'&&it.childNodes[0].checked){
				genres.push(it.childNodes[0].id.split('-')[1]);
			}
		}catch(err){}
	}
	var _dirs=new Array();
	for(var i=0;i<dirs.childNodes.length;i++){
		it = dirs.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='dirs'){
				_dirs.push(it.id.replace(/dirs_dirs/, ''));
			}
		}catch(err){}
	}
	var _cast=new Array();
	for(var i=0;i<cast.childNodes.length;i++){
		it = cast.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='cast'){
				_cast.push(it.id.replace(/cast_cast/, ''));
			}
		}catch(err){}
	}
	var url = "./do_update_movie.php";
	var params = "title="+movie_title.value+"&website="+movie_website.value+"&year="+movie_year.value+"&length="+movie_length.value+"&genres="+genres.toString()+"&dirs="+_dirs.toString()+"&cast="+_cast.toString()+"&id_movie="+document.getElementById('id_movie').value;
	var http = ajaxFunction();//don't worry about this
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4) {
			sResults = http.responseText; //results is now whatever the feedback from the asp page was
			sResults = sResults.split("!@#$");
			switch(sResults[0]){
				case "-2":
					var dialog_obj = {width:250, height:150,title:'Atentie',html:"Logheaza-te pentru a adauga un film."};
					addDialog(dialog_obj);
				break;
				case "-1":
					dialog_obj = {width:250, height:150,title:'Atentie',html:'Logheaza-te pentru a face modificari.'};
					addDialog(dialog_obj);
				break;
				case "0":
					deleteMovieFields();
					dialog_obj = {width:250, height:200,title:'Atentie',html:'Filmul a fost adaugat.<br />Va fi adaugat pe site dupa ce va fi verificat.<br />Multumim.'};
					addDialog(dialog_obj);
				break;
				default:
					dialog_obj = {width:250, height:200,title:'Atentie',html:'Modificarile tale au fost salvate.<br />Vor trebui verificate inainte sa apara pe site.<br />Multumim.'};
					addDialog(dialog_obj);
				break;
			}
			removeModal();
		}
	}
	http.send(params);
	
}

function updateActor(){
	loadModal();
	var msg='';
	var act_name = document.getElementById('act_name');
	var act_dob = document.getElementById('act_dob');
	var act_dod = document.getElementById('act_dod');
	var act_pob = document.getElementById('act_pob');
	var umovies = document.getElementById('umovies');
	var dmovies = document.getElementById('dmovies');
	if(act_name.value=="") msg += "- Nume<br />";
	if(msg != ''){
		msg = "Verificati urmatoarele campuri:<br />" + msg;
		removeModal();
		var dialog_obj = {width:250, height:150,title:'Atentie',html:msg};
		addDialog(dialog_obj);
		return;
	}
	var umovs=new Array();
	for(var i=0;i<umovies.childNodes.length;i++){
		var it = umovies.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='movies'){
				umovs.push(it.id.replace(/umovies_umovies/, ''));
			}
		}catch(err){}
	}
	var dmovs=new Array();
	for(var i=0;i<dmovies.childNodes.length;i++){
		it = dmovies.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='movies'){
				dmovs.push(it.id.replace(/dmovies_dmovies/, ''));
			}
		}catch(err){}
	}
	var url = "./do_update_actor.php";
	var params = "name="+act_name.value+"&act_dob="+act_dob.value+"&act_dod="+act_dod.value+"&act_pob="+act_pob.value+"&umovs="+umovs.toString()+"&dmovs="+dmovs.toString()+"&id_actor="+document.getElementById('id_actor').value;
	var http = ajaxFunction();//don't worry about this
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4) {
			sResults = http.responseText; //results is now whatever the feedback from the asp page was
			sResults = sResults.split("!@#$");
			switch(sResults[0]){
				case "-2":
					var dialog_obj = {width:250, height:150,title:'Atentie',html:"Logheaza-te pentru a adauga un actor."};
					addDialog(dialog_obj);
				break;
				case "-1":
					dialog_obj = {width:250, height:150,title:'Atentie',html:"Logheaza-te pentru a face modificari."};
					addDialog(dialog_obj);
				break;
				case "0":
					deleteActorFields();
					dialog_obj = {width:250, height:200,title:'Atentie',html:"Actorul a fost adaugat.<br />Va fi adaugat pe site dupa ce va fi verificat.<br />Multumim."};
					addDialog(dialog_obj);
				break;
				default:
					dialog_obj = {width:250, height:200,title:'Atentie',html:"Modificarile tale au fost salvate.<br />Vor trebui verificate inainte sa apara pe site.<br />Multumim."};
					addDialog(dialog_obj);
				break;
			}
			removeModal();
		}
	}
	http.send(params);	
}
function deleteActorFields(){
	document.getElementById('act_name').value='';
	document.getElementById('act_dob').value='';
	document.getElementById('act_dod').value='';
	document.getElementById('act_pob').value='';
	document.getElementById('umovies').innerHTML='';
	document.getElementById('dmovies').innerHTML='';
}
function deleteMovieFields(){
	document.getElementById('movie_title').value='';
	document.getElementById('movie_website').value='';
	document.getElementById('movie_length').value='';
	document.getElementById('dirs').innerHTML='';
	document.getElementById('cast').innerHTML='';
	document.getElementById('movie_year').selectedIndex=0
	var movie_genres = document.getElementById('movie_genres');
	for(var i=0;i<movie_genres.childNodes.length;i++){
		var it = movie_genres.childNodes.item(i);
		try{
			if(it.attributes["captio"].value=='movie_genre'){
				it.childNodes[0].checked = false;
			}
		}catch(err){}
	}
}
function selAll(cb){
	var subs = document.getElementsByName("cb");
	for(var i=0;i<subs.length;i++){
		subs.item(i).checked = cb.checked;
	}
}
function doAdminAction(url,name){
	var arr = document.getElementsByName("cb");
	var ids='';
	loadModal();
	for(var i=0;i<arr.length;i++){
		if(arr.item(i).checked==true){
			try{
				ids+=arr.item(i).parentNode.parentNode.id.split(name)[1]+',';
			}catch(err){}
		};
	}
	if(ids==''){
		alert('No items selected');
		removeModal();
		return;
	}
	var params = "ids="+ids;
	var http = ajaxFunction();//don't worry about this
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4) {
			sResults = http.responseText; //results is now whatever the feedback from the asp page was
			sResults = sResults.split("!@#$");
			deleteTheFields(sResults[0].split(","),name);
			alert("Done.");
			removeModal();
		}
	}
	http.send(params);
}
function deleteTheFields(ids,name){
	for(var i=0;i<ids.length-1;i++){
		try{
			removeMe(name+ids[i]);
		}catch(err){}
	}
}
function addSubtitleWin(id){
	var id_user = checkIdUser('Logheaza-te pentru a adauga subtitrari');
	if(id_user==0) return;
	var FO = { movie:"uploader_subtitle.swf", width:"250", height:"320", majorversion:"8", build:"0", xi:"true",wmode:"transparent",flashvars:"id="+id+"&amp;id_user="+id_user+"&serverURL=http://"+window.location.hostname, id:"uploader_subtitle", name:"uploader_subtitle"};
	UFO.create(FO, "dialog");
	var dialog_obj = {width:280, height:435,title:'Adauga Subtitrare',buttons:{"Adauga Subtitrare": function() {uploader_subtitle.doAddSubtitle();},"Renunta": function() {$("#dialog").dialog('close')}},html:""};
	addDialog(dialog_obj);
}
function checkIdUser(txt){
	var id_user = Get_Cookie('id_user');
	if(id_user==null){
		var dialog_obj = {width:280, height:150,title:'Atentie',html:txt};
		addDialog(dialog_obj);
		return 0;
	}else{
		return id_user;
	}
}
function addFotoUserWin(id,type){
	var id_user = checkIdUser('Logheaza-te pentru a adauga imagini');
	if(id_user==0) return;
	var FO = { movie:"uploader_avatar.swf", width:"200", height:"150", majorversion:"8", build:"0", xi:"true",wmode:"transparent",flashvars:"id="+id+"&amp;type="+type+"&serverURL=http://"+window.location.hostname,id:"uploader_avatar",name:"uploader_avatar"};
	UFO.create(FO, "dialog");
	
	var dialog_obj = {width:250, height:265,title:'Adauga Avatar',buttons:{"Adauga Avatar": function() {uploader_avatar.doAddImage();},"Renunta": function() {$("#dialog").dialog('close')}},html:""};
	addDialog(dialog_obj);
}
function updateTips(t) {
	var tips = $("#validateTips");
	tips.text(t).effect("highlight",{},1500);
}

function addFpasswordWin(){
	var html = '<p id="validateTips">Introdu adresa de email cu care te-ai inregistrat pe site.</p>';
	html += '<p style="padding-top:10px">';
	html += '<form action="javascript:doSendPassword();">';
	html += '<ul class="registerul">';
	html += '<li>Email</li><li><input type="text" id="email" name="email" style="width:95%" /></li>';
	html += '</ul>';
	html += '</form>';
	html += '</p>';
	var dialog_obj = {width:330, height:230,title:'Am uitat parola',buttons:{"Trimite parola":function(){doSendPassword();},"Renunta": function() {$("#dialog").dialog('close')}},html:html};
	addDialog(dialog_obj);
}
function doSendPassword(){
	var email = $("#email"),
	allFields = $([]).add(email);

	var bValid = true;
	allFields.removeClass('ui-state-error');
	bValid = bValid && checkLength(email,"email",6,80);
	bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email incorect. Exemplu: user@example.com");	
	if(bValid){
		var http = ajaxFunction();//don't worry about this
		var my_link = "./sendPassword.php?email="+email.val();
		http.open("GET", my_link, true);
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4) {
				sResults = http.responseText; //results is now whatever the feedback from the asp page was
				sResults = sResults.split("&");
				switch(sResults[0]){
					case "-1":
						t="Acest email nu exista in baza de date.";
						email.addClass('ui-state-error');
						email.focus();
						updateTips(t);
					break;
					case "1":
						sendPassOK();
					break;
				}
			}
		}
		http.send(null);
	}
}
function addChangePasswordWin(){
	var html = '<p id="validateTips">Completati toate campurile.</p>';
	html += '<p style="padding-top:10px">';
	html += '<form action="javascript:doChangePassword();">';
	html += '<ul class="registerul">';
	html += '<li>Parola veche</li><li><input type="password" id="passwordold" name="passwordold" style="width:95%" /></li>';
	html += '<li>Parola noua</li><li><input type="password" id="password" name="password" style="width:95%" /></li>';
	html += '<li>Verificare parola</li><li><input type="password" id="password1" name="password1" style="width:95%" /></li>';
	html += '</ul>';
	html += '</form>';
	html += '</p>';
	var dialog_obj = {width:330, height:310,title:'Schimba parola',buttons:{"Schimba parola":function(){doChangePassword();},"Renunta": function() {$("#dialog").dialog('close')}},html:html};
	addDialog(dialog_obj);
}
function doChangePassword(){
	var passwordold = $("#passwordold"),
	password = $("#password"),
	password1 = $("#password1"),
	allFields = $([]).add(passwordold).add(password).add(password1);

	var bValid = true;
	allFields.removeClass('ui-state-error');
	bValid = bValid && checkLength(passwordold,"parola veche",5,16);
	bValid = bValid && checkLength(password,"parola",5,16);
	bValid = bValid && checkLength(password1,"verificare parola",5,16);
	bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Parola trebuie sa contina a-z, 0-9");
	bValid = bValid && checkEqual(password, password1,"Parola trebuie sa fie identica cu verificare parola");
	if(bValid){
		var http = ajaxFunction();//don't worry about this
		var my_link = "./checkPassword.php?op="+passwordold.val()+"&p="+password.val();
		http.open("GET", my_link, true);
		http.onreadystatechange = function(){
			if (http.readyState == 4)
			{
				sResults = http.responseText; //results is now whatever the feedback from the asp page was
				sResults = sResults.split("&");
				lcode = sResults[0];
				if (lcode == "-1"){
					t = "Parola veche a fost introdusa gresit.";
					passwordold.addClass('ui-state-error');
					passwordold.focus();
					updateTips(t);
				}else{
					t = "Parola dumneavoastra a fost schimbata.";
					$('#dialog').dialog('close');
					var dialog_obj = {width:300, height:150,title:'Schimba parola',html:t};
					addDialog(dialog_obj);
				}
			}
		}
		http.send(null);
	}
}
function addNewstitleWindow(){
	var html = '<p id="validateTips">Introdu adresa ta de email.</p>';
	html += '<p style="padding-top:10px">';
	html += '<form action="javascript:doAddNewsletter();">';
	html += '<ul class="registerul">';
	html += '<li>Email</li><li><input type="text" id="email" name="email" style="width:95%" /></li>';
	html += '</ul>';
	html += '</form>';
	html += '</p>';
	var dialog_obj = {width:330, height:230,title:'Newsletter',buttons:{"Abonare":function(){doAddNewsletter();},"Renunta": function() {$("#dialog").dialog('close')}},html:html};
	addDialog(dialog_obj);
}
function doAddNewsletter(){
	var email = $("#email"),
	allFields = $([]).add(email);

	var bValid = true;
	allFields.removeClass('ui-state-error');
	bValid = bValid && checkLength(email,"email",6,80);
	bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email incorect. Exemplu: user@example.com");	
	if(bValid){
		var http = ajaxFunction();//don't worry about this
		var my_link = "./doAddNewsletter.php?email="+email.val();
		http.open("GET", my_link, true);
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4) {
				sResults = http.responseText; //results is now whatever the feedback from the asp page was
				sResults = sResults.split("&");
				switch(sResults[0]){
					case "-1":
						t="Acest email exista in baza de date.";
						email.addClass('ui-state-error');
						email.focus();
						updateTips(t);
					break;
					case "1":
						addEmailOK();
					break;
				}
			}
		}
		http.send(null);
	}
}
function addRegisterWin(){
	var html = '<p id="validateTips">Completati toate campurile.</p>';
	html += '<p style="padding-top:10px">';
	html += '<form action="javascript:doRegister();">';
	html += '<ul class="registerul">';
	html += '<li>Email</li><li><input type="text" id="email" name="email" style="width:95%" /></li>';
	html += '<li>Nume utilizator</li><li><input type="text" name="name" id="name" style="width:95%" /></li>';
	html += '<li>Sex</li><li><input type="radio" id="m" name="sex" value="masculin" checked="checked" /><label for="m">Masculin</label>&nbsp;<input type="radio" id="f" name="sex" value="feminin" /><label for="f">Feminin</label></li>';
	html += '<li>Anul nasterii</li>';
	html += '<li>';
	html += '<select name="yob" id="yob">';
	$date = new Date();
	$y = $date.getFullYear();
	for(var i=$y; i>1900; i--){
		html += '<option>'+i+'</option>';
	}
	html += '</select>';
	html += '</li>';
	html += '<li>Locatie</li><li><input type="text" style="width:95%" name="location" id="location" /></li>';
	html += '<li>Parola</li><li><input type="password" style="width:95%" name="password" id="password" /></li>';
	html += '<li>Verificare parola</li><li><input type="password" style="width:95%" name="password2" id="password2" /></li>';
	html += '<li>Cod de securitate</li><li><input type="text" style="width:25%" name="code" id="code" /></li>';
	html +='<li><img src="./CaptchaSecurityImages.php?width=100&height=40&characters=5&r='+Math.random()+'" /></li>';
	html += '</ul>';
	html += '</form>';
	html += '</p>';
	var dialog_obj = {width:330, height:570,title:'&#206;nregistreaza-te',buttons:{"Inregistreaza-te":function(){doRegister();},"Renunta": function() {$("#dialog").dialog('close')}},html:html};
	addDialog(dialog_obj);
}
function doRegister(){
	var name = $("#name"),
	email = $("#email"),
	tips = $("#validateTips"),
	location = $("#location"),
	password = $("#password"),
	password2 = $("#password2"),
	code = $("#code"),
	allFields = $([]).add(name).add(email).add(tips).add(location).add(password).add(password2).add(code);

	var bValid = true;
	allFields.removeClass('ui-state-error');
	bValid = bValid && checkLength(email,"email",6,80);
	bValid = bValid && checkLength(name,"nume utilizator",3,16);
	bValid = bValid && checkLength(location,"locatie",2,40);
	bValid = bValid && checkLength(password,"parola",5,16);
	bValid = bValid && checkLength(password2,"verificare parola",5,16);
	bValid = bValid && checkRegexp(name,/^([0-9a-zA-Z ])+$/i,"Nume utilizator trebuie sa contina a-z, A-Z, 0-9 sau spatiu.");
	bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email incorect. Exemplu: user@example.com");
	bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Parola trebuie sa contina a-z, 0-9");
	bValid = bValid && checkEqual(password, password2,"Parola trebuie sa fie identica cu verificare parola");
	bValid = bValid && checkCode(code, Get_Cookie('security_code'),"Codul trebuie sa fie identic cu cel din imagine");
	
	if(bValid){
		var http = ajaxFunction();//don't worry about this
		var my_link = "./checkEmail.php?email="+email.val()+"&username="+name.val();
		http.open("GET", my_link, true);
		http.onreadystatechange = function(){
			checkEmailResponse(http);
		}
		http.send(null);
	}
}
function checkEmailResponse(http){
	if (http.readyState == 4)
	{
		sResults = http.responseText; //results is now whatever the feedback from the asp page was
		sResults = sResults.split("&");
		remail = sResults[0];
		if(remail=="-1" || remail=="-2"){
			var tt = remail=="-1"?"Acest email exista in baza de date.":"Acest nume de utilizator exista in baza de date.";
			if(remail=="-1"){
				$("#email").addClass('ui-state-error');
				$("#email").focus();
			}else{
				$("#name").addClass('ui-state-error');
				$("#name").focus();
			}
			updateTips(tt);
		}else{
			var name = $("#name"),
			email = $("#email"),
			tips = $("#validateTips"),
			location = $("#location"),
			password = $("#password"),
			password2 = $("#password2"),
			sex = $("#sex"),
			yob = $("#yob"),
			code = $("#code");
			var url = "./doRegister.php";
			var params = "name="+name.val()+"&email="+email.val()+"&location="+location.val()+"&password="+password.val()+"&sex="+$('[name=sex]:checked').val()+"&yob="+yob.val()+"&security_code="+code.val();
			var http1 = ajaxFunction();//don't worry about this
			http1.open("POST", url, true);
			
			//Send the proper header information along with the request
			http1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http1.setRequestHeader("Content-length", params.length);
			http1.setRequestHeader("Connection", "close");
			
			http1.onreadystatechange = function() {//Call a function when the state changes.
				if(http1.readyState == 4) {
					sResults = http1.responseText; //results is now whatever the feedback from the asp page was
					sResults = sResults.split("&");
					switch(sResults[0]){
						case "-2":
							t="Codul trebuie sa fie identic cu cel din imagine";
							code.addClass('ui-state-error');
							code.focus();
							updateTips(t);
						break;
						case "-1":
							t="Acest email exista in baza de date.";
							email.addClass('ui-state-error');
							email.focus();
							updateTips(t);
						break;
						case "1":
							registerOK();
						break;
					}
				}
			}
			http1.send(params);
		}
	}
}

function registerOK(){
	$('#dialog').dialog('close');
	var dialog_obj = {width:300, height:220,title:'&#206;nregistrare',html:"Inregistrare completa.<br />Veti primi pe email codul de verificare al contului dumneavoastra. Verificati si folderul SPAM.<br />Multumim."};
	addDialog(dialog_obj);
}
function sendPassOK(){
	$('#dialog').dialog('close');
	var dialog_obj = {width:300, height:150,title:'Schimba parola',html:"Modalitatea de a schimba parola a fost trimisa pe adresa ta de email."};
	addDialog(dialog_obj);
}
function addEmailOK(){
	$('#dialog').dialog('close');
	var dialog_obj = {width:300, height:150,title:'Newsletter',html:"Adresa ta de email a fost adaugata in baza de date."};
	addDialog(dialog_obj);
}
function addFotoWin(id,btype){
	var id_user = checkIdUser('Logheaza-te pentru a adauga imagini');
	if(id_user==0) return;
	var FO = { movie:"uploader.swf", width:"200", height:"150", majorversion:"8", build:"0", xi:"true",wmode:"transparent",flashvars:"id="+id+"&amp;type="+btype+"&amp;id_user="+id_user+"&serverURL=http://"+window.location.hostname,id:"uploader",name:"uploader"};
	UFO.create(FO, "dialog");
	
	var dialog_obj = {width:250, height:265,title:'Adauga Imagine',buttons:{"Adauga Imagine": function() {uploader.doAddImage();},"Renunta": function() {$("#dialog").dialog('close')}},html:""};
	addDialog(dialog_obj);
}
function addDialog(obj){
	obj.buttons = obj.buttons==undefined?{"OK": function() {$("#dialog").dialog('close')}}:obj.buttons;
	$("#dialog").dialog({
			bgiframe:true,
			autoOpen:false,
			resizable: false,
			modal:true
	});
	$("#dialog").dialog('option','width',obj.width);
	$("#dialog").dialog('option','height',obj.height);
	$("#dialog").dialog('option','title',obj.title);
	$("#dialog").dialog('option','buttons',obj.buttons);
	$("#dialog").html(obj.html);
	$("#dialog").dialog('open');
	
}

function checkCode(c,c1,t) {
	if ( c.val() != c1) {
		c.addClass('ui-state-error');
		c.focus();
		updateTips(t);
		return false;
	} else {
		return true;
	}
}
function checkEqual(o,o1,t) {
	if ( o.val() != o1.val()) {
		o.addClass('ui-state-error');
		o.focus();
		updateTips(t);
		return false;
	} else {
		return true;
	}
}
function checkLength(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass('ui-state-error');
		o.focus();
		updateTips("Lungimea campului " + n + " trebuie sa fie intre "+min+" si "+max+".");
		return false;
	} else {
		return true;
	}
}
function checkRegexp(o,regexp,n) {
	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass('ui-state-error');
		o.focus();
		updateTips(n);
		return false;
	} else {
		return true;
	}
}
function openPage(page,login,err){
	if(login=='1'){
		var id_user = checkIdUser(err);
		if(id_user==0) return;
	}
	document.location=page;
}
function openUpdateMovie(btype,id,page){
	var id_user = checkIdUser('Logheaza-te pentru a completa pagina');
	if(id_user==0) return;
	document.location=page+'-'+btype+'-'+id+'.html';
}
function addFotoDone(){
	$('#dialog').dialog('close');
	var dialog_obj = {width:250, height:200,title:'Adauga Imagine',html:'Imaginea a fost adaugata.<br />Va aparea pe site dupa ce va fi verificata.<br />Multumim.'};
	addDialog(dialog_obj);
}
function addSubtitleDone(){
	$('#dialog').dialog('close');
	var dialog_obj = {width:250, height:200,title:'Adauga Subtitrare',html:'Subtitrarea a fost adaugata.<br />Va aparea pe site dupa ce va fi verificata.<br />Multumim.'};
	addDialog(dialog_obj);
}
function addAvatarDone(){
	document.location=document.location;
}
function checkChangePassword(){
	var pass = $("#password"),
	passa = $("#passworda"),
	tips = $("#validateTips"),
	allFields = $([]).add(pass).add(passa).add(tips);

	var bValid = true;
	allFields.removeClass('ui-state-error');
	bValid = bValid && checkLength(pass,"parola",5,16);
	bValid = bValid && checkLength(passa,"verificare parola",5,16);
	bValid = bValid && checkRegexp(pass,/^([0-9a-zA-Z])+$/,"Parola trebuie sa contina a-z, 0-9");
	bValid = bValid && checkEqual(passa, pass,"Parola trebuie sa fie identica cu verificare parola");
	return bValid;
}
function getHoroscop(i){
	document.getElementById('horoscop').innerHTML = "<div style='height:100px;text-align:center; padding-top:50px;'><div>Loading...</div><div><img src='../images/loadingAnimation.gif' alt='loading' width='170' /></div></div>";
	var url = "./getH.php";
	var params = "i="+i;
	var http = ajaxFunction();//don't worry about this
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4) {
			sResults = http.responseText; //results is now whatever the feedback from the asp page was
			sResults = sResults.split("!@#$");
			document.getElementById('horoscop').innerHTML = sResults[0];
		}
	}
	http.send(params);
	
}
function openTrailer(id){
	var html = '<div><object width="100%" height="287" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"><param name="movie" value="http://video.cinemagia.net/v/'+id+'" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="wmode" value="transparent"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://video.cinemagia.net/v/'+id+'" width="100%" height="287" menu="false" quality="high" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><div>';
	var dialog_obj = {width:600, height:400,title:'Trailer',html:html};
	addDialog(dialog_obj);
}