function print_it (id, width_i)
{
	if (document.getElementById)
	{
		var content = $('#'+id).html();
		
		/*content = content.substring (0, content.indexOf ('<script')) + content.substring (content.indexOf ('</script>')+9);*/

		var printWin = window.open ('','', 'width='+width_i+',height=800');
		printWin.document.open ();
		printWin.document.write ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.way2web.ro/css/domenii.css\" /></head><body style=\"background-color:#fff;\">');

// 		printWin.document.write ('<div style="width:1000px; margin:0px auto;">');
		printWin.document.write (content);
// 		printWin.document.write ("</div>");
		printWin.document.write ('</body></html>');
		printWin.document.close ();
		printWin.focus ();
	
		printWin.print ();

		/*setTimeout ("", 1000);*/

		printWin.close();
	}
	return false;
}

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}

function validate_required(field,alerttxt)
{
with (field)
{
if (value==NULL||value=='Nume' && value=='')
  {alert(alerttxt);return false}
else {return true}
}
}

function popup(url, img)
{
	$('.smen').hide();
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
		offwidth = document.getElementsByTagName('html')[0].offsetWidth;
		offheight = document.getElementsByTagName('html')[0].offsetHeight;
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth;
	   viewportheight = document.documentElement.scrollHeight/2;
	   offwidth = document.getElementsByTagName('html')[0].offsetWidth;
	   offheight = document.getElementsByTagName('html')[0].scrollHeight;
	}

	// older versions of IE

	else
	{
	   
	   viewportwidth = document.getElementsByTagName('html')[0].clientWidth;
	   viewportheight = document.getElementsByTagName('html')[0].scrollHeight;
	   offwidth = document.getElementsByTagName('html')[0].offsetWidth;
	   offheight = document.getElementsByTagName('html')[0].offsetHeight;
	   
	}
	if(url!=null)
	{
		$('<div id="overall_page" onclick="cancel_mail()" class="overall_page" style="width:'+offwidth+'px; height:'+offheight+'px" ></div>').appendTo("body");
	}
	else
	{
		$('<div id="overall_page" class="overall_page" style="width:'+offwidth+'px; height:'+offheight+'px" ></div>').appendTo("body");
	}
	$('#overall_page').fadeTo("fast", 0.50 ,function()
	{
		if(!document.getElementById('main_panel'))
		$('#overall_page').after('<div class="main_panel" id="main_panel"></div>');

		if(url!=null)
		{
			$('#main_panel').load( url , null, function(){
			p_width = document.getElementById('main_panel').offsetWidth;
			p_height = document.getElementById('main_panel').offsetHeight;

			new_width  = viewportwidth/2-p_width/2;
			new_height = viewportheight/2-p_height/2;
			document.getElementById('main_panel').style.top = new_height+'px';
			document.getElementById('main_panel').style.left = new_width+'px';
			});
		}
		else if(img!=null)
		{
	
			$('#main_panel').html('<div class="loading"> <img src="'+img+'" alt="Loading..."/> </div>');
			p_width = document.getElementById('main_panel').offsetWidth;
			p_height = document.getElementById('main_panel').offsetHeight;

			new_width  = viewportwidth/2-p_width/2;
			new_height = viewportheight/2-p_height/2;
			document.getElementById('main_panel').style.top = new_height+'px';
			document.getElementById('main_panel').style.left = new_width+'px';
			
		}
	});
}

			function cancel_mail()
			{
				$('#overall_page').remove();
				$('select').css({visibility: 'visible'});
				$('#main_panel').empty();
				$('#main_panel').remove();
				$('#overall_page').remove();
				$('select').css({visibility: 'visible'});
				$('#main_panel').empty();
				$('#main_panel').remove();
				$('.smen').show();
			}

			function submit_mail()
			{
				$('#em_form').ajaxSubmit({ target:        '#main_panel'});
				
			}
			
			
			function hoverOn(message)
			{
				$('.help').empty();
				$('.help').html($('#'+message).html());
			//
			}

			function hoverOff()
			{
				$('.help').empty();
			}


function show_pic(top_0)
{
		if(document.getElementById(top_0).style.display == 'block')
		{
			document.getElementById(top_0).style.display = 'none';
		}
		else if(document.getElementById(top_0).style.display == 'none')
		{
			document.getElementById(top_0).style.display = 'block';
		}
}
function check_existing_user()
{
	//alert(document.getElementById('username').value+"***"+document.getElementById('password').value);
	if(echeck(document.getElementById('username').value))
	{
		if(document.getElementById('username').value == '')
		{
			alert("Trebuie sa introduceti un username");
			document.getElementById('username').focus();
			return false;
		}
		else		
		{
			$('#user_ses').load("/resset_pass/sesiune/",{email:document.getElementById('username').value},function(){var a='1';});
			$('#user_result').load("/logpage/check_existing_user/",{username:document.getElementById('username').value,password:document.getElementById('password').value},function(){setTimeout('verifica_raspuns()','1000')});	
		}
	}
	
	
}

function verifica_raspuns()
{
		var valoare = $('#user_result').html();
		
		if(valoare == '0')
			popup('http://domeniiweb.way2web.ro/resset_pass/resetare_parola/'+document.getElementById('username').value);
		else if(valoare == '1')
		{
			$('#user_ses').load("/logpage/sesiune/",{username:document.getElementById('username').value,password:document.getElementById('password').value},function(){});
			setTimeout('window.location= "/logpage"',1000);		
		}
		else
		{
			$('#user_result').html('<div align="center" style="margin:5px;font-size:12px;color:red">Username-ul este disponibil .</div>');
			$('#user_result').show();
		}
}
	
	
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){
		   alert("Va rugam introduceti un email valid.")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Va rugam introduceti un email valid.")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Va rugam introduceti un email valid.")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Va rugam introduceti un email valid.")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Va rugam introduceti un email valid.")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Va rugam introduceti un email valid.")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Va rugam introduceti un email valid.")
		    return false;
		 }

 		 return true					
	}


	
		