<!--

var loading = new Image();
loading.src = 'img/loading.gif';

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function param()
{
    this.array = new Array(1);

    this.setValue = function(v) { this.array[0] = v; }
    this.getValue = function()  { return this.array[0]; }
}

function getCheckedValue(radioObj) 
{
  if(!radioObj)
    return '';
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return '';
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return '';
} 

function logIn()
{
	//if (username != '' && password  != '') {
		// compute the hash of the hash of the password and the seed
		//hash = hex_md5(password);
	var logmsg = document.getElementById('logmsg');	 
	var loadmsg = document.getElementById('loadmsg');
	loadmsg.appendChild(loading);
  //loadmsg.appendChild()    
	new Ajax.Request('login.php',
  	{
	    method: 'post',
	    postBody: 'userlogin='+document.getElementById("userlogin").value+'&userpass='+document.getElementById("userpass").value,
	    onSuccess: function(transport){
	   	  loadmsg.removeChild(loading);
	      var response = transport.responseText || "0";	      
	      if (response == "1")
	      {
		      logmsg.innerHTML = "Zalogowano pomyślnie!";
		      window.location.href="index.php";
	      }
	      else
	      {
		      logmsg.innerHTML = "Błąd! Spróbuj ponownie.</br>";
	      }
	      
	    },
	    onFailure: function(){ 
        alert("on failure");        
        loadmsg.removeChild(loading);
        logmsg.innerHTML = "Bład systemu logowania!";  
      }
	});
	
		/*/ open the http connection
		http.open('GET', 'login.php?task=checklogin&username='+username+'&hash='+hash, true);
		http.onreadystatechange = function() { 
			if (http.readyState == 4) {	
				document.getElementById('message').innerHTML='';
				var result = http.responseText.trim();
				if (result == 'success') {
					messageElement = document.createElement('strong');
					messageElement.appendChild(document.createTextNode('Login successful!'));
					messageElement.style.color = '#00ff00';
					document.getElementById('message').appendChild(messageElement);
					window.location.href='clubhouse/';
				} else {
					messageElement = document.createElement('strong');
					messageElement.appendChild(document.createTextNode(' ' + result));
					messageElement.style.color = '#ff0000';
					document.getElementById('message').appendChild(messageElement);
				}			
			}
		}
		http.send(null);		
	//}*/
}

function GetLatLong(city,state,country)
{
	var latitude = document.getElementById('latitudetxt');	 
	var longitude = document.getElementById('longitudetxt');	 	
	var loadmsg = document.getElementById('loadmsg');
	var query = "";
	new Ajax.Request('geocode.php',
  	{
	    method: 'post',
	    postBody: 'city='+city+'&state='+state+'&country='+country,
	    requestHeaders: {Accept: 'text/x-json'},
	    onSuccess: function(transport,json){
			loadmsg.removeChild(loading); 
			var jsonx = transport.responseText;
			var data = jsonx.evalJSON();
			longitude.innerHTML = data.Placemark[0]['Point'].coordinates[0];	
			latitude.innerHTML = data.Placemark[0]['Point'].coordinates[1];	
      	      
	    },
	    onLoading: function(){ loadmsg.appendChild(loading); },
	    onFailure: function(){ loadmsg.removeChild(loading); alert("Bład geocode!");  }
	});
}

function ShowFeed(layer,obj,curlayer)
{
if(curlayer.getValue() == layer)
  return false;
Effect.Fade(curlayer.getValue());
Effect.Appear(layer);
obj.style.backgroundColor = "#F6F9ED";
document.getElementById('a'+curlayer.getValue()).style.backgroundColor = "transparent";
curlayer.setValue(layer);
return true;
}

function validateRegForm(form) {
var msg = "";

  msg += validateLogin(form.login);
  msg += validatePassword(form.password,form.password2);
  msg += validateEmail(form.email);
  msg += validateEmpty(form.city);
  msg += validateEmpty(form.country);
      
  if (msg != "") {
    alert("Niektóre pola wymagają korekty:\n" + msg);
    return false;
  }

  return true;
}

function validateUserEditForm(form) {
  var msg = "";
  if(form.cpassword.value != '')
  {
    msg += validatePassword(form.password,form.password2);
  }
  msg += validateEmail(form.email);
  msg += validateEmpty(form.city);
  msg += validateEmpty(form.country);
      
  if (msg != "") {
    alert("Niektóre pola wymagają korekty:\n" + msg);
    return false;
  }

  return true;
}

function validateCompForm(form) {
  var msg = "";
  msg += validateEmpty(form.name);
  if(form.private.value == 1)
    msg += validateEmpty(form.password);
      
  if (msg != "") {
    alert("Niektóre pola wymagają korekty:\n" + msg);
    return false;
  }
  return true;
}

function validateCompSearchForm(form)
{
  var msg = "";
  msg += validateEmpty(form.name);    
  if (msg != "") {
    alert(msg);
    return false;
  }
  return true;
}

function validateContactForm(form){
  var msg = "";
  msg += validateEmpty(form.user);
  msg += validateEmpty(form.subject);
  msg += validateEmpty(form.body);    
  if (msg != "") {
    alert("Niektóre pola wymagają korekty:\n" + msg);
    return false;
  }
  return true;
}

function validateJoinForm(form){
  var msg = "";
  msg += validateEmpty(form.password);
  if (msg != "") {
    alert(msg);
    return false;
  }
  return true;
}

function validateEmpty(field) {
    var error = "";
 
    if (field.value.length == 0) {
        field.style.background = "yellow"; 
        error = "Wymagane pole nie zostało wypełnione.\n"
    } else {
        field.style.background = "white";
    }
    return error;  
}

function validateLogin(field) {
    var error = "";
    var illegalCharacters = /\W/;
 
    if (field.value == "") {
        field.style.background = "yellow"; 
        error = "Nie wpisałeś nazwy użytkownika.\n";
    } else if ((field.value.length < 3) || (field.value.length > 15)) {
        field.style.background = "yellow"; 
        error = "Nazwa użytkownika ma niedozwoloną długość.\n";
    } else if (illegalCharacters.test(field.value)) {
        field.style.background = "yellow"; 
        error = "Nazwa użtkownika zawiera niedozwolone znaki.\n";
    } else {
        field.style.background = 'white';
    }
    return error;
}

function validateEmail(field) {
    var error="";
    var tfield = trim(field.value);
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (field.value == "") {
        field.style.background = "yellow";
        error = "Nie wpisałeś adresu email.\n";
    } else if (!emailFilter.test(tfield)) { 
        field.style.background = "yellow";
        error = "Wpisz poprawny adres email.\n";
    } else if (field.value.match(illegalChars)) {
        field.style.background = "yellow";
        error = "Adres email zawiera niedozwolone znaki.\n";
    } else {
        field.style.background = "white";
    }
    return error;
}

function validatePassword(field,field2) {
    var error = "";
    var illegalChars = /[\W_]/;
 
    if (field.value == "") {
        field.style.background = "yellow";
        error = "Nie wpisałeś hasła.\n";
    } else if ((field.value.length < 4) || (field.value.length > 20)) {
        error = "Hasło ma niedozwoloną długość. \n";
        field.style.background = "yellow";
    } else if (illegalChars.test(field.value)) {
        error = "Hasło zawiera niedozwolone znaki.\n";
        field.style.background = "yellow";
    } else if (!(field.value == field2.value)) {
        error = "Wpisane hasła nie są jednakowe.\n";
        field.style.background = "yellow";
    } else {
        field.style.background = "white";
    }
   return error;
} 

//-->