var raspuns;

function ShowLogin(){

$('td#contentbg').html('<img style="z-index: 300; position: relative" src="http://www.nethd.ro/images/contact/loading.gif">');

$('div#contentmodal').fadeIn('slow');

	$.ajax({

			type: "POST",

			url: "login.php",

			cache: false,

			data: ({open: true}),

			success: function(mesaj) {

			raspuns = mesaj;

				setTimeout("$('td#contentbg').html(raspuns)", 1000);

			}

		});

}



function doAuth(){

		var nume = $('input#nume').val();

		var parola = $('input#parola').val();



	if(nume.length < 2){

				setTimeout("$('span#RezLogin').html('<font size=2 color=red>Invalid Username !</font>')", 10);

				return false;

	}

	if(parola.length < 6){

				setTimeout("$('span#RezLogin').html('<font size=2 color=red>Password requires 6 characters minimum !</font>')", 10);

				return false;

	}

	$('span#RezLogin').html('<img style="z-index: 300; position: relative; width: 24px; left: 50px" src="http://www.nethd.ro/images/contact/loading.gif">');

	$.ajax({

			type: "POST",

			url: "login.php",

			cache: false,

			data: ({nume: nume, parola: parola}),

			success: function(mesaj) {

			raspuns = mesaj;

			if(raspuns == 0){

				setTimeout("$('span#RezLogin').html('<font size=2 color=red>Username or password incorrect !</font>')", 700);

				return false;

			}

			if(raspuns == 1){

				setTimeout("$('span#RezLogin').html('<font size=2 color=red>Login Failed! Your browser does not accept cookies !</font>')", 700);

				return false;

			}

			if( (raspuns != 0) || (raspuns != 1) ){

                $('div#identify').html("Welcome " + raspuns + " <a href='javascript:LogOut()'>Log Out</a>");

				setTimeout("$('span#RezLogin').html('<font size=2 color=green>Login successful !</font>')", 100);

				setTimeout("$('div#contentmodal').fadeOut('slow');", 1700);

			}



			}

		});



}



function LogOut(){

	$('div#identify').html('Loging Out');

	$.ajax({

			type: "POST",

			url: "login.php",

			cache: false,

			data: ({delcookie: 'true', test: 'true'}),

			success: function(mesaj) {

				nume = undefined;

				$('div#identify').html('<a href="javascript:ShowLogin()">Login</a><a href="javascript:SignUp()">Sign Up</a>');

			}

		});







}



function PassRecover(){

$('td#contentbg').html('<img style="z-index: 300; position: relative" src="http://www.nethd.ro/images/contact/loading.gif">');

	$.ajax({

			type: "POST",

			url: "login.php",

			cache: false,

			data: ({openrecover: true}),

			success: function(mesaj) {

			raspuns = mesaj;

			setTimeout("$('td#contentbg').html(raspuns)", 1000);

			}

		});

}



function doRecover(){



		var nume = $('input#nume').val();

		var email = $('input#email').val();

		var parola1 = $('input#pass1').val();

		var parola2 = $('input#pass2').val();



	if(nume.length < 2){

				setTimeout("$('span#RezLogin').html('<font size=1 color=red>Invalid Username !</font>')", 10);

				return false;

	}

		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (!filter.test( email )){

				setTimeout("$('span#RezLogin').html('<font size=1 color=red>Invalid E-mail !</font>')", 10);

				return false;

	}

	if(parola1 !== parola2){

				setTimeout("$('span#RezLogin').html('<font size=1 color=red>Password does not match 2 times !</font>')", 10);

				return false;

	}

	if(parola1.length < 6){

				setTimeout("$('span#RezLogin').html('<font size=1 color=red>Password requires 6 characters minimum !</font>')", 10);

				return false;

	}

	$('span#RezLogin').html('<img style="z-index: 300; position: relative; width: 22px; left: 50px" src="http://www.nethd.ro/images/contact/loading.gif">');



	$.ajax({

			type: "POST",

			url: "login.php",

			cache: false,

			data: ({ruser: nume, remail: email, rpass: parola1}),

			success: function(mesaj) {

			raspuns = mesaj;

				if(raspuns == 0){

					setTimeout("$('span#RezLogin').html('<font size=1 color=red>User not found in MySQL!</font>')", 1000);

					return false;

				}

				if(raspuns == 1){

					setTimeout("$('span#RezLogin').html('<font size=1 color=red>E-mail not found in MySQL !</font>')", 1000);

					return false;

				}

				if(raspuns == 2){

					setTimeout("$('span#RezLogin').html('<font size=1 color=red>Password can not contain spaces !</font>')", 1000);

					return false;

				}

				if(raspuns == 3){

					setTimeout("$('span#RezLogin').html('<font size=1 color=red>Not found in MySQL database !</font>')", 1000);

					return false;

				}

				if(raspuns == 4){

					setTimeout("$('td#contentbg').html('<font size=2 color=green>Password set successful !</font>')", 400);

					setTimeout("ShowLogin()", 2000);

				}

			}

		});



}



function SignUp(){

	$('td#contentbgs').html('<img style="z-index: 300; position: relative" src="http://www.nethd.ro/images/contact/loading.gif">');

	$('div#contentmodals').fadeIn('slow');

	$.ajax({

			type: "POST",

			url: "signup.php",

			cache: false,

			data: ({open: true}),

			success: function(mesaj) {

			raspuns = mesaj;

				setTimeout("$('td#contentbgs').html(raspuns)", 1000);

			}

		});

}



function doSignUp(){

$('span#RezLogins').html('<img style="z-index: 300; position: relative; width: 24px; left: 50px" src="http://www.nethd.ro/images/contact/loading.gif">');

	var nume = $('input#nume').val();

	var user = $('input#user').val();

	var pass1 = $('input#parola1').val();

	var pass2 = $('input#parola2').val();

	var email = $('input#email').val();

	var adresa = $('input#adresa').val();

	var tel1 = $('input#tel1').val();

	var tel2 = $('input#tel2').val();

	var fax1 = $('input#fax1').val();

	var fax2 = $('input#fax2').val();

	var website = $('input#website').val();

	var yahoo = $('input#yahoo').val();

	var msn = $('input#msn').val();

	var skype = $('input#skype').val();

	var scode = $('input#secutirycode').val();

		if(scode.length != 5){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Incorrect security code !</font>')", 1000);

			return false;

		}

		if(nume.length < 3){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Incorrect name, too short !</font>')", 1000);

			return false;

		}

		if(user.length < 3){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Incorrect user, too short !</font>')", 1000);

			return false;

		}

		if(pass1 !== pass2){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Password does not match 2 times !</font>')", 1000);

			return false;

		}

		if(pass1.length < 6){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Password too short, must be at least 6 characters !</font>')", 1000);

			return false;

		}

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		if (!filter.test( email )){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Incorrect E-mail !</font>')", 10);

			return false;

		}

		if(adresa.length < 15){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Address too short, must be at least 15 characters !</font>')", 1000);

			return false;

		}

		if(tel1.length < 9){

			setTimeout("$('span#RezLogins').html('<font size=2 color=red>Phone too short, I think is not correct !</font>')", 1000);

			return false;

		}



	$.ajax({

			type: "POST",

			url: "signup.php",

			cache: false,

			data: ({nume: nume, user: user, pass: pass1, email: email, adresa: adresa, tel1: tel1, tel2: tel2, fax1: fax1, fax2: fax2, website: website, yahoo: yahoo, msn: msn, skype: skype, scode: scode}),

			success: function(mesaj) {

			raspuns = mesaj;

			if(raspuns != 0){

				setTimeout("$('span#RezLogins').html('<font color=red size=2>' + raspuns + '</font>')", 1000);

				return false;

			}else{

				setTimeout("$('td#contentbgs').html('<font size=2 color=green>User created successfully, thanks !</font>')", 400);

			}

			}

		});



}
var videodemo;
var preloadImg = "<img style='position: relative' src='http://www.nethd.ro/images/contact/loading.gif'>";
function openvideo(){
$("div#contentmodalov").fadeIn();
	videodemo = '<object align="left" id="player3" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="740" height="570"><param name="movie" value="http://www.nethd.ro/flash_player/player.swf" />	<param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" /><param name="flashvars" value="wmode=transparent&volume=0&autostart=true&skin=http://www.nethd.ro/flash_player/bluemetal.swf&file=http://webhtb.nethd.ro/WebHTB_Pro.ogv.flv" /><embed align="left" type="application/x-shockwave-flash" id="player4" src="http://www.nethd.ro/flash_player/player.swf" width="740" height="570" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="wmode=transparent&volume=0&autostart=true&skin=http://www.nethd.ro/flash_player/bluemetal.swf&file=http://webhtb.nethd.ro/WebHTB_Pro.ogv.flv"/></object>';
	setTimeout("$('td#contentbgov').html(videodemo)", 1500);

}

window.onload = function(){

	if(nume == undefined){

		$('div#identify').html('<a href="javascript:ShowLogin()">Login</a><a href="javascript:SignUp()">Sign Up</a>');

	}else{

		$('div#identify').html("Welcome " + nume + " <a href='javascript:LogOut()'>Log Out</a>");

	}

}
