function getArrayValue(array){
	var values=new Array();
	for (i=0; i<array.length; i++){
		values.push($(array[i]).attr('value'));
	}
	return values;
}

function verifyPrivacyRequirements(privacy){
	var violated = false;
	
	for (i=0; i<privacy.length; i++){
		var element = privacy[i];
		$("#" + element.id).removeClass('outline_error');
		if ($("#" + element.id).attr('req').toLowerCase() == 'true' && !$("#" + element.id).attr('checked')){
			$("#" + element.id).addClass('outline_error');
			violated = true;
		}
	}
	if (violated){
		$("#error").html("E' necessario accettare la privacy");
		$("#errorPrivacy").html("E' necessario accettare la privacy");
	} else {
		$("#errorPrivacy").html("");
		$("#error").html('');
	}
	return !violated;
}

function verifyPassword(password, confirmPassword){
	if (password != confirmPassword){
		return false;
	}
	return true;
}

function verifyPhoneNumber(s) 
{
     rePhoneNumber = new RegExp(/^\+\d{2}\d{3}\d{5}\d*$/);
     if (!rePhoneNumber.test(s)) {
    	 return false;
     }
     return true;
}

function verifyJIDMail(jid){
	var atIndex = jid.indexOf("@");
	var dotIndex = jid.indexOf(".");
	
	if (atIndex==-1 || atIndex==0 || atIndex==jid.length){
	   return false;
	}

	if (dotIndex==-1 || dotIndex==0 || dotIndex===jid.length){
	    return false;
	}

	var dotIndexDomain = jid.indexOf(".",atIndex);
	if (dotIndexDomain==-1 || dotIndexDomain==0 || dotIndexDomain===jid.length){
	    return false;
	}
	if (jid.indexOf(':')!=-1 || jid.indexOf('\'')!=-1 || 
			jid.indexOf('<')!=-1 || jid.indexOf('>')!=-1 ||
			jid.indexOf('&')!=-1 || jid.indexOf(' ')!=-1 ){
		return false;
	}
		
	if (jid.indexOf("@",(atIndex+1))!=-1){
	    return false;
	}

	return true;					
}

function delete_cookie ( cookie_name )
{
	var date = new Date();		//Get the current time and date
    var expdate = date.getTime();  //Get the milliseconds since Jan 1, 1970
    expdate -= 10 * 60; //expires in 1 hour(milliseconds)
    date.setTime(expdate);
    var newCookie=cookie_name+"=; path=/;";	//Set the new cookie values up
    newCookie += " expires=" + date.toGMTString();
    //alert(newCookie);
    window.document.cookie=newCookie;
}

function getPartialPage(url, params, divFrom, divTo){
	$.post(url, params, function(html){
		var section = $("#"+divFrom,html).html();
		$("#"+divTo).html(section);
	});
}
