
function validateForm(){
	var value=document.getElementById('firstname').value;
	if(isAnInvalid(value)){
		showError(document.getElementById('firstname'),"You have to insert your name");
		return false;
	}
	value=document.getElementById('lastname').value;
	if(isAnInvalid(value)){
		showError(document.getElementById('lastname'),"You have to insert your family name");
		return false;
	}
	value=document.getElementById('email').value;
	if(isAnInvalid(value)){
		showError(document.getElementById('email'),"You have to insert your email");
		return false;
	}
	value=document.getElementById('company').value;
	if(isAnInvalid(value)){
		document.getElementById('company').value="";
	}
	return true;
}
function isAnInvalid(value){
	return (value==="" || value==='undefined' || value===null )
}
function showSuccess(){
	document.getElementById("invitation-form").setAttribute("class","hidden");
	document.getElementById("success").removeAttribute("class");
}
function showError(domElement,msg){
	document.getElementById("result").innerHTML="<p class='wrong'>"+msg+"</p>";
	document.getElementById("result").removeAttribute("class");
	domElement.setAttribute("class","wrong");
}
function setRigth(domElement){
	domElement.removeAttribute("class");
	domElement.setAttribute("class","rigth");
}

function askForAnInvitation(firstname,lastname,email,company){
	if(validateForm()){	
	firstname = firstname?firstname:document.getElementById("firstname").value;
	lastname = lastname?lastname:document.getElementById("lastname").value;
	email = email?email:document.getElementById("email").value;
	company = company?company:document.getElementById("company").value;	
	var params="firstname="+firstname+"&lastname="+lastname+"&email="+email+"&company="+company;
	var http=new XMLHttpRequest();	
	http.open("post","email.php",true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange=function(){	// all a function when the state
		// changes.
		if (http.readyState == 4 && http.status == 200) {
			var result=document.getElementById("success");
			document.getElementById("invitation-form").setAttribute("class","hidden");
			result.removeAttribute("class");
			result.innerHTML=http.responseText;
		}
	};
	dump("Requesting the deletion of "+params);
	http.send(params);
	}
}

function askForAnInvitationTest(jqParams,firstname,lastname,email,company){
	var firstname = firstname?firstname:jQuery("#firstname").val();
	var lastname = lastname?lastname:jQuery("#lastname").val();
	var email = email?email:jQuery("#email").val();
	var company = company?company:jQuery("#company").val();
	var params="firstname="+firstname+"&lastname="+lastname+"&email="+email+"&company="+company;
	jQuery.ajax({ type: "POST",
	url: "email.php",
	data: params,
	success: function(html){	
		var result=jQuery("#success");
		jQuery("#user-info").hide();
		jQuery("#result").hide();
		result.removeAttr("class");
		result.append(html);
	},beforeSend:validateForm});
}

function acceptEulaNew() {
	jQuery("#eula").hide();	
	jQuery("#install").show();
	setXPIUrl();	
}

function loadDownloadPage(){
	var osx = (navigator.userAgent.indexOf('Mac OS X') != -1);
	
	jQuery.ajax({	type: "GET",
			url: "http://www.smartrm.com/get-started/install/",
			success: function(html){
					jQuery("#install").html(jQuery(html).find("#post-427").html());
					jQuery("#install").addClass("post");
					jQuery("#install").addClass("entry");
					jQuery("#install").hide();		
				}	
			});
var niceToHave = osx? '<tr>'+ 
				'<td> Nice to have </td>'+ 
				' Growl to be notified of any SmartRM interaction <a href="http://growl.info/files/Growl-1.1.5.dmg" class = "down_style" target="_blank"> (download) </a>'+
		       '</tr>' :'';
var requirements ='<table id="requirements"><tbody>'+ 
			'<tr>'+ 
				'<td>  Browser  </td>'+ 
				'<td>Mozilla Firefox 3.5 or higher (<a href = "http://www.mozilla-europe.org/en/firefox/" class = "down_style" target="_blank">download</a>)</td>'+
		       '</tr>'+
			'<tr>'+ 
				'<td>Java VM </td>'+ 
				
				'<td>Sun JRE 1.6.12 or higher (<a href = "http://java.sun.com/javase/downloads/index.jsp" class = "down_style" target="_blank">download</a>)</td>'+
		       '</tr>'+ 
			niceToHave+
		'</tbody></table>';
	jQuery("#header-search").remove();
	jQuery("#search-div").html(requirements);
}

function enableAcceptButton(){
	if(jQuery('#privacy-acceptance').is(":checked")){
		jQuery('#accept').attr('disabled', false); 
	}
	else{
		jQuery('#accept').attr('disabled', true); 
	}
	
}
function backToHomePage(){
	document.location.href="http://www.smartrm.com/"
}
/**
 * Function that returns the smartrm firefox client version. If anything goes wrong return an empty string
 */
function getSmartRMFirefoxVersion() {
	var http=new XMLHttpRequest();	
	http.open("get","http://www.smartrm.com/update/update-osx.rdf",false);
	http.send(null);
	if (http.readyState == 4 && http.status == 200) {
		var version=http.responseXML.getElementsByTagName("em:version")[0].childNodes[0].nodeValue
		return version;
	}
	
}

