var xmlhttp;
var currentid;
function fvoid() {}

function check(form) {
	switch (form.name) {
		case 'contact':
			if (!document.getElementById('rname').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="Name field must be filled!";
			}
			else if (!document.getElementById('remail').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="E-mail field must be filled";
			}
			else if (!document.getElementById('rsubj').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="Subject field must be filled";
			}
			else if (!document.getElementById('rtext').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="Text field must be filled";
			}
			else {
				form.submit();
			}
			break;
		case 'add_job':
			if (!document.getElementById('rtitle').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="Title field must be filled!";
			}
			else if (!document.getElementById('rtext').value) {
				document.getElementById("rf_alert").style.display="block";
				document.getElementById("rf_alert").innerHTML="Text field must be filled";
			}
			else {
				form.submit();
			}
			break;
	}
}

function getxmlhttp()
	{
	var xmlhttp=null;
	xmlhttp=new XMLHttpRequest();
	if(!xmlhttp)
	{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		if(!xmlhttp)
		{
			alert("Your browser does not support Ajax! Please update!");
		}
	}
	return xmlhttp;
}

function display_login () {
	document.getElementById('options').innerHTML='<form name="login" method="post" class="left_form" action=""><h3>Login</h3><ul><li id="lf_alert"></li><li>Second Life user:</li><li><input type="text" name="luser" id="luser" class="lf_field" /></li><li>Password:</li><li><input type="password" name="lpass" id="lpass" class="lf_field" /></li><li class="lf_sli"><a href="javascript:fvoid();" onclick="display_recover();">Recover password &raquo;</a></li><li class="lf_sli"><a href="javascript:fvoid();" onclick="display_signup();">Sign up &raquo;</a></li><li style="overflow: hidden;"><input type="button" value="Login" class="lf_login" onfocus="this.blur();" onclick="elogin(document.getElementById(\'luser\').value,document.getElementById(\'lpass\').value);" /></li></ul></form>';
}

function display_signup () {
	document.getElementById('options').innerHTML='<form name="signup" method="post" class="left_form" action=""><h3>Sign up</h3><ul><li id="lf_alert"></li><li>Second Life user:</li><li><input type="text" name="suser" id="suser" class="lf_field" /></li><li>Password:</li><li><input type="password" name="spass" id="spass" class="lf_field" /></li><li>Verify Password:</li><li><input type="password" name="svpass" id="svpass" class="lf_field" /></li><li>E-mail:</li><li><input type="text" name="semail" id="semail" class="lf_field" /></li><li class="lf_sli"><a href="javascript:fvoid();" onclick="display_login();">Already registered? &raquo;</a></li><li style="overflow: hidden;"><input type="button" value="Sign up" class="lf_signup" onfocus="this.blur();" onclick="esignup(document.getElementById(\'suser\').value,document.getElementById(\'spass\').value,document.getElementById(\'svpass\').value,document.getElementById(\'semail\').value);" /></li><li class="lf_alert">We recommend you do not use your Second Life password!</li></ul></form>';
}

function elogin(user,passw) {
	if (!user) {
		document.getElementById('lf_alert').style.display="block";
		document.getElementById('lf_alert').innerHTML='Username and/or password incorect!';
	}
	else if (!passw) {
		document.getElementById('lf_alert').style.display="block";
		document.getElementById('lf_alert').innerHTML='Username and/or password incorect!';
	}
	else {
		xmlhttp=getxmlhttp();
		if (xmlhttp==null) {
			alert ("Your browser does not support AJAX! Please update!");
			return;
		}
		xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					if (xmlhttp.responseText=='auth') {
						var today = new Date();
						var expire = new Date();
						expire.setTime(today.getTime() + 3600000*24*10);
						document.cookie="aut=1;expires="+expire.toGMTString();
						document.cookie="aus="+escape(user)+ "; expires="+expire.toGMTString();
						document.location="index.php";
					}
					else document.getElementById('lf_alert').innerHTML=xmlhttp.responseText;
				}
			}
		xmlhttp.open("POST","lib/cookie.php",true);
		params="user="+user+"&passw="+passw;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
	}
}

function esignup (user,passw,vpassw,email) {
	if (!user || !passw || !vpassw || !email) {
		document.getElementById('lf_alert').innerHTML="All fields are mandatory";
	}
	else if (passw!=vpassw) {
		document.getElementById('lf_alert').innerHTML="Passwords do not coincide";
	}
	else {
		xmlhttp=getxmlhttp();
		if (xmlhttp==null) {
			alert ("Your browser does not support AJAX! Please update!");
			return;
		}
		xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					document.getElementById('lf_alert').innerHTML=xmlhttp.responseText;
				}
			}
		xmlhttp.open("POST","lib/cookie.php",true);
		params="user="+user+"&passw="+passw+"&email="+email;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
	}
}

function elogout() {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() - 3600000);
	document.cookie="aut=0";
	document.cookie="aus=''; expires="+expire.toGMTString();
	document.location="/";
}

function del(id,action) {
	xmlhttp=getxmlhttp();
	if (xmlhttp==null) {
		alert ("Your browser does not support AJAX! Please update!");
		return;
	}
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if (xmlhttp.responseText=='OK') document.getElementById('link_'+id).style.display='none';
				else document.getElementById('l_answ_'+id).innerHTML=xmlhttp.responseText;
			}
		}
	xmlhttp.open("POST","lib/cookie.php",true);
	params="id="+id+"&action="+action;
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}

function job_toogle(id,action) {
	xmlhttp=getxmlhttp();
	if (xmlhttp==null) {
		alert ("Your browser does not support AJAX! Please update!");
		return;
	}
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if (currentid==id) {
					//document.getElementById('job_text_'+currentid).innerHTML=xmlhttp.responseText;
					document.getElementById('job_link_'+currentid).style.display='none';
					document.getElementById('job_button_'+currentid).innerHTML='<a href="javascript:fvoid();" onfocus="this.blur();" onclick="job_toogle('+currentid+',\'show\');">Details &raquo;</a>';
					currentid=0;
				}
				else {
					if (currentid) {
						//document.getElementById('job_text_'+currentid).innerHTML=xmlhttp.responseText;
						document.getElementById('job_link_'+currentid).style.display='none';
						document.getElementById('job_button_'+currentid).innerHTML='<a href="javascript:fvoid();" onfocus="this.blur();" onclick="job_toogle('+currentid+',\'show\');">Details &raquo;</a>';
					}
					document.getElementById('job_text_'+id).innerHTML=xmlhttp.responseText;
					document.getElementById('job_link_'+id).style.display='block';
					document.getElementById('job_button_'+id).innerHTML='<a href="javascript:fvoid();" onfocus="this.blur();" onclick="job_toogle('+id+',\'hide\');">&laquo; Details</a>';
					currentid=id;
				}
			}
		}
	xmlhttp.open("POST","lib/jobs.php",true);
	params="id="+id+"&action="+action;
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}

function del_job(id) {
	xmlhttp=getxmlhttp();
	if (xmlhttp==null) {
		alert ("Your browser does not support AJAX! Please update!");
		return;
	}
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if (xmlhttp.responseText=="ok") {
					document.getElementById('job_'+id).style.display="none";
					window.location.reload(true);
				}
			}
		}
	xmlhttp.open("POST","lib/jobs.php",true);
	params="id="+id+"&action=delete";
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}

function change_pass() {
	if (document.getElementById('cpass').value || document.getElementById('npass').value || document.getElementById('vpass').value)
		document.changepass.submit();
	else {
		document.getElementById('rf_alert').style.display='block';
		document.getElementById('rf_alert').innerHTML='All fields must be filled!';
	}
}

function cms_preload(ido)
{
if (ido)
  {
  if(typeof(ido)==typeof(" ")) {obiect=document.getElementById(ido);}
  else
    obiect=ido;
  
  obiect.innerHTML="";
  if (!document.getElementById("cms_preloader"))
    {
    document.getElementById("cms_preloader_shadow").innerHTML="<embed class='cms_preloader' id='cms_preloader' src='flash/preloader.swf' wmode='transparent'></embed>";
    document.getElementById("cms_preloader").style.display="none";
    }

  new_preloader=obiect.appendChild(document.getElementById("cms_preloader"));
  document.getElementById("cms_preloader").style.display="block";
  
  return new_preloader;
  }
return false;
}

function cms_preload_finish()
{
if (document.getElementById("cms_preloader"))
  {
  document.getElementById("cms_preloader").style.display="none";
  document.getElementById("cms_preloader_shadow").appendChild(document.getElementById("cms_preloader"));
  }
}