var _preldr_1 = new Image();
_preldr_1.src = "css/layout/preloaders/preloader1.gif";

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
//comment

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function HTTPGetRequest(onsuccess , url ) {

	wait = onsuccess == false ? false : true;

	xmlhttp.open("GET", url,wait);

	if (!wait){
		xmlhttp.send(null)
		return xmlhttp.responseText;
	} else {
		xmlhttp.onreadystatechange = function() {
			//temporaty fix, i font know why it isnw working when i pass directlu the xmlhttp.readyState to the function
			switch (xmlhttp.readyState)	{
				case 4:
					onsuccess(xmlhttp.responseText , xmlhttp.readyState)
				break;

				default:
					onsuccess("" , xmlhttp.readyState)
				break;			
			}
		}
		xmlhttp.send(null)
	}	
}


function HTTPPostRequest(onsuccess , url , vars)  {

	var wait = onsuccess == false ? false : true;
	var request = "";

	for ( i in vars ){
		request += i + "=" + escape(vars[i]) + "&";
	}

	xmlhttp.open("POST", url, wait);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

	if (!wait){
		xmlhttp.send(request)
		return xmlhttp.responseText;
	} else {
		xmlhttp.onreadystatechange = function() {

			switch (xmlhttp.readyState)	{
				case 4:
					onsuccess(xmlhttp.responseText , xmlhttp.readyState)
				break;

				default:
					onsuccess("" , xmlhttp.readyState)
				break;			
			}
						
			//alert(xmlhttp.readyState);
		}
		xmlhttp.send(request)
	}
}

function is_Ajax() {
	if (xmlhttp ==false)
		return false;
	else 
		return true;
}


function PostGuestbook(lang) {
	var fields = Array("name" , "email" , "message" , "code");

	var error = false;
	var current = "";
	for (i = 0 ; i< fields.length ; i++ ) {
		if (eval('document.forms["guestbook"].' + fields[i] + '.value.length') < 2) {
			error = true;

			if (current == "") {
				current = fields[i];
			}
		}
	}

	if (error) {
		alert(lang == "en" ? "Please fill in all the fields!" : "Va rugam sa completati toate campurile pentru a putea posta");
		//focus the first element with problems
		eval('document.forms["guestbook"].' + current + '.focus()');
	} else {

		var response = HTTPPostRequest(
				false,
				"private/guestbook" , 
				{
					"lang" : lang,
					"name" : document.forms["guestbook"].name.value,
					"email" : document.forms["guestbook"].email.value,
					"message" : document.forms["guestbook"].message.value,
					"code" : document.forms["guestbook"].code.value
				}
			);


		switch (response) {
			case "ok":
				window.location.reload();
			break;

			case "code":
				alert(lang == "en" ? "The verification image and the code you typed id doesnt match!" : "Imaginea de verificare si codul introdus de dumneavoastra nu sunt la fel.");
			break;
		}

		alert(response);

	}

}


function UserLogin() {
	var fields = Array("login" , "password" /*, "code"*/);
	var error = false;
	var current = "";
	for (i = 0 ; i< fields.length ; i++ ) {
		if (eval('document.forms["LoginForm"].' + fields[i] + '.value.length') < 2) {
			error = true;

			if (current == "") {
				current = fields[i];
			}
		}
	}

	if (error) {
		UserBox("loginFields");
		//focus the first element with problems
		eval('document.forms["LoginForm"].' + current + '.focus()');
	} else {
		url = _URL + "private/account/submit";

		var response = HTTPPostRequest(
				false,
				url , 
				{
					"login" : document.forms["LoginForm"].login.value,
					"password" : document.forms["LoginForm"].password.value,
					//"code" : document.forms["LoginForm"].code.value,
					"remember" : document.forms["LoginForm"].remember.checked ? 1 : 0
				}
			);

		if (response.indexOf("okay;") != "-1") {

				//store the cookie
				if (document.forms["LoginForm"].remember.checked) {
					data = response.split(";");

					setCookie("fc_user" , document.forms["LoginForm"].login.value);
					setCookie("fc_pass" , data[1]);
				}

				//redirect the user to its account
				if (document.forms["LoginForm"].redirect.value != "")
					window.location = document.forms["LoginForm"].redirect.value;
				else
					window.location = _URL + "account/index.html";
		}

		switch (response) {
			case "okay":
			break;

			case "error":
				UserBox("loginInvalid");
				//alert("Invalid username or password!");
			break;

			case "code":
				UserBox("loginCode");
				//alert("Security code and image doesnt match!");
				//document.forms["LoginForm"].code.focus();
			break;
		}

	}


}

