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

function checkSubscribe (mode){
    //alert(mode);
	var checkData = 0;
	var checkMail = 0;
    var colorBase = "#EEEFEF";
    var colorBaseBorder = "1px solid #c4c4c4";
    var colorError = "#FFCCCC";
    var colorErrorBorder = "solid 1px #FF0000";
	
	/*****************************************************
	 ** Distinct Checks (Media vs others types) **********
	 *****************************************************/
	if(mode == "media") {
		/*********************
		 ******* Media *******
		 *********************/
		
		//--- Check Position (and "Other" field if needed).
		if(document.form.Position.value == "" && document.form.CPosition.value == "") {
			document.getElementById("CPosition").style.backgroundColor = colorError;
			document.getElementById("background_position").style.backgroundColor = colorError;
			document.getElementById("background_position").style.border = colorErrorBorder;
            checkData = 1;
		} else {
			document.getElementById("CPosition").style.backgroundColor = colorBase;
			document.getElementById("background_position").style.backgroundColor = "";
			document.getElementById("background_position").style.border = "";
		}

        //--- Check MediaType (and "Other" field if needed).
		if(document.form.MediaType.value == "") {
			document.getElementById("background_type").style.backgroundColor = colorError;
			document.getElementById("background_type").style.border = colorErrorBorder;
            checkData = 1;
		} else {
			document.getElementById("background_type").style.backgroundColor = "";
			document.getElementById("background_type").style.border = "";
		}
		
        //check MediaOrganisation
		if(trim(document.form.MediaName.value)==""){
			document.getElementById("MediaName").style.backgroundColor = colorError;
			document.getElementById("MediaName").style.border = colorErrorBorder;
			checkData = 1;
		} else {
			document.getElementById("MediaName").style.backgroundColor = colorBase;
			document.getElementById("MediaName").style.border = colorBaseBorder;
		}
	 } else {
		 /*********************
		  ** "Speaker", etc ***
		  *********************/
		//--- Check if constants (ex : CONTACT_CATEGORY_SPEAKER = 1) defined in config file have been modified
		if(!document.form.Category1) {
			alert("Error : Category1 doesn't exist. Please notify the webmaster");
			checkData = 1;
		} else if(!document.form.Category2) {
			alert("Error : Category2 doesn't exist. Please notify the webmaster");
			checkData = 1;
		} else if(!document.form.Category4) {
			alert("Error : Category4 doesn't exist. Please notify the webmaster");
			checkData = 1;
		}
		
		//--- Check if at least one category is selected
		if(!document.form.Category1.checked && !document.form.Category2.checked && !document.form.Category4.checked) {
			document.getElementById("background_category").style.backgroundColor = colorError;
			document.getElementById("background_category").style.border = colorErrorBorder;
			checkData = 1;
		} else {
			document.getElementById("background_category").style.backgroundColor = "";
			document.getElementById("background_category").style.border = "";
		}
		
		//check Position
		if(trim(document.form.Position.value)==""){
			document.getElementById("Position").style.backgroundColor = colorError;
			document.getElementById("Position").style.border = colorErrorBorder;
			checkData = 1;
		} else {
			document.getElementById("Position").style.backgroundColor = colorBase;
			document.getElementById("Position").style.border = colorBaseBorder;
		}

        //--- Check Sector (and "Other" field if needed).
        if(document.form.Sector.value == "" && document.form.CSector.value == "") {
            document.getElementById("CSector").style.backgroundColor = colorError;
            document.getElementById("background_sector").style.backgroundColor = colorError;
            document.getElementById("background_sector").style.border = colorErrorBorder;
            checkData = 1;
        } else {
            document.getElementById("CSector").style.backgroundColor = colorBase;
            document.getElementById("background_sector").style.backgroundColor = "";
            document.getElementById("background_sector").style.border = "";
        }

        //check Company
        if(trim(document.form.Company.value)==""){
            document.getElementById("Company").style.backgroundColor = colorError;
            document.getElementById("Company").style.border = colorErrorBorder;
            checkData = 1;
        } else {
            document.getElementById("Company").style.backgroundColor = colorBase;
            document.getElementById("Company").style.border = colorBaseBorder;
        }
	}
	
	
	/*****************************************************
	 ** Commons checks for Media and others types ********
	 *****************************************************/
	
    //check First Name
    if(trim(document.form.FirstName.value)==""){
        document.getElementById("FirstName").style.backgroundColor = colorError;
        document.getElementById("FirstName").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("FirstName").style.backgroundColor = colorBase;
        document.getElementById("FirstName").style.border = colorBaseBorder;
    }
	
    //check Last Name
    if(trim(document.form.LastName.value)==""){
        document.getElementById("LastName").style.backgroundColor = colorError;
        document.getElementById("LastName").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("LastName").style.backgroundColor = colorBase;
        document.getElementById("LastName").style.border = colorBaseBorder;
    }
	
	//--- Check Title (and "Other" field if needed).
	if(document.form.Title.value == "" && document.form.CTitle.value == "") {
		document.getElementById("CTitle").style.backgroundColor = colorError;
		document.getElementById("background_title").style.backgroundColor = colorError;
		document.getElementById("background_title").style.border = colorErrorBorder;
        checkData = 1;
	} else {
		document.getElementById("CTitle").style.backgroundColor = colorBase;
		document.getElementById("background_title").style.backgroundColor = "";
		document.getElementById("background_title").style.border = "";
	}
	
    //check Address
    if(trim(document.form.Address.value)==""){
        document.getElementById("Address").style.backgroundColor = colorError;
        document.getElementById("Address").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("Address").style.backgroundColor = colorBase;
        document.getElementById("Address").style.border = colorBaseBorder;
    }

    //check City
    if(trim(document.form.City.value)==""){
        document.getElementById("City").style.backgroundColor = colorError;
        document.getElementById("City").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("City").style.backgroundColor = colorBase;
        document.getElementById("City").style.border = colorBaseBorder;
    }

    //check Postcode
    if(trim(document.form.Postcode.value)==""){
        document.getElementById("Postcode").style.backgroundColor = colorError;
        document.getElementById("Postcode").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("Postcode").style.backgroundColor = colorBase;
        document.getElementById("Postcode").style.border = colorBaseBorder;
    }

    //check Country
    if(trim(document.form.Country.value)==""){
        document.getElementById("Country").style.backgroundColor = colorError;
        document.getElementById("Country").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("Country").style.backgroundColor = colorBase;
        document.getElementById("Country").style.border = colorBaseBorder;
    }

    //check Phone
    if(trim(document.form.Phone.value)==""){
        document.getElementById("Phone").style.backgroundColor = colorError;
        document.getElementById("Phone").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("Phone").style.backgroundColor = colorBase;
        document.getElementById("Phone").style.border = colorBaseBorder;
    }

    //check Email
    if(trim(document.form.Email.value)==""){
        document.getElementById("Email").style.backgroundColor = colorError;
        document.getElementById("Email").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("Email").style.backgroundColor = colorBase;
        document.getElementById("Email").style.border = colorBaseBorder;
    }

	//--- Check if constants (ex : FLAG1_16MARCH = 1) defined in config file have been modified
	if(!document.form.Flag1_1) {
		alert("Error : Flag1_1 doesn't exist. Please notify the webmaster");
		checkData = 1;
	} else if(!document.form.Flag1_2) {
		alert("Error : Flag1_2 doesn't exist. Please notify the webmaster");
		checkData = 1;
	}
	
	//--- Check if at least one day ("I will attend the..." is selected
	if(!document.form.Flag1_1.checked && !document.form.Flag1_2.checked) {
		document.getElementById("background_days_16").style.backgroundColor = colorError;
		document.getElementById("background_days_16").style.border = colorErrorBorder;
		checkData = 1;
	} else {
		document.getElementById("background_days_16").style.backgroundColor = "";
		document.getElementById("background_days_16").style.border = "";
	}

    if(!document.form.Flag1_1.checked && !document.form.Flag1_2.checked) {
		document.getElementById("background_days_17").style.backgroundColor = colorError;
		document.getElementById("background_days_17").style.border = colorErrorBorder;
		checkData = 1;
	} else {
		document.getElementById("background_days_17").style.backgroundColor = "";
		document.getElementById("background_days_17").style.border = "";
	}

    //--- Check if 16 march is selected (plenary session)
    //--if(document.form.Flag1_1.checked && !document.form.Flag1_4.checked && !document.form.Flag1_8.checked && !document.form.Flag1_16.checked) {
    if(document.form.Flag1_1.checked && !document.form.Flag1_4.checked && !document.form.Flag1_8.checked) {
		document.getElementById("plenary").style.backgroundColor = colorError;
		document.getElementById("plenary").style.border = colorErrorBorder;
		checkData = 1;
	} else {
		document.getElementById("plenary").style.backgroundColor = "";
		document.getElementById("plenary").style.border = "";
	}

    //--- Check if 16 march is selected (parallel interactive sessions)
    //--if(document.form.Flag1_1.checked && !document.form.Flag1_4.checked && !document.form.Flag1_8.checked && !document.form.Flag1_16.checked) {
    if(document.form.Flag1_1.checked && !document.form.Flag1_4.checked && !document.form.Flag1_8.checked) {
		document.getElementById("parallel").style.backgroundColor = colorError;
		document.getElementById("parallel").style.border = colorErrorBorder;
		checkData = 1;
	} else {
		document.getElementById("parallel").style.backgroundColor = "";
		document.getElementById("parallel").style.border = "";
	}

    //--- Check Choice 1.
    if(document.form.Flag1_1.checked && document.form.Flag1_8.checked && document.form.Choice1.value == "") {
        document.getElementById("background_choice1").style.backgroundColor = colorError;
        document.getElementById("background_choice1").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("background_choice1").style.backgroundColor = "";
        document.getElementById("background_choice1").style.border = "";
    }

    //--- Check Choice 2.
    if(document.form.Flag1_1.checked && document.form.Flag1_8.checked && document.form.Choice2.value == "") {
        document.getElementById("background_choice2").style.backgroundColor = colorError;
        document.getElementById("background_choice2").style.border = colorErrorBorder;
        checkData = 1;
    } else {
        document.getElementById("background_choice2").style.backgroundColor = "";
        document.getElementById("background_choice2").style.border = "";
    }

    //--- Check if 16 march is selected (Gala dinner)
    //---if(document.form.Flag1_1.checked && !document.form.Flag1_4.checked && !document.form.Flag1_8.checked && !document.form.Flag1_16.checked) {
	//---	document.getElementById("dinner").style.backgroundColor = colorError;
	//---	document.getElementById("dinner").style.border = colorErrorBorder;
	//---	checkData = 1;
	//---} else {
	//---	document.getElementById("dinner").style.backgroundColor = "";
	//---	document.getElementById("dinner").style.border = "";
	//---}

    if(checkData==1 || checkMail==1){alert("Please fill all the requiered fields"); return false;} else {return true;}
}

