/* ----------------------------------
		Registrations JavaScript
   ---------------------------------- */
vSystem = "register";

function fChangeRegSelect(oForm) {
	if ( $("#package_code").val() != "" ) {
		$("#reg_type_submit").click();
	} 
}


function validateDateOfBirth (themessage, yyyy, mm, dd, minDate, maxDate, ifError ) {
	if ( !isDate(mm, dd, yyyy) ) themessage += " - " + ifError + "\n";
	else
	{
		var dTmp = mm + "/" + dd + "/" + yyyy + " 00:00:00";
		var d = new Date(dTmp);
		var maxD = new Date(maxDate + " 00:00:00");
		var minD = new Date(minDate + " 00:00:00");
		var addMessage = "";
		if ( maxDate && ( Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) > Date.UTC(maxD.getFullYear(), maxD.getMonth(), maxD.getDate() ) ) ) addMessage += " max: " + maxD.getDate() + "/" + (parseInt(maxD.getMonth())+1) + "/" + maxD.getFullYear() + ",";
		if ( minDate && ( Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) < Date.UTC(minD.getFullYear(), minD.getMonth(), minD.getDate() ) ) ) addMessage += " min: " + minD.getDate() + "/" + (parseInt(minD.getMonth())+1) + "/" + minD.getFullYear() + ",";
		if ( addMessage != "" ) {
			themessage += " - " + ifError + "\n"
			window["vFieldList"] = window["vFieldList"] + "date_of_birth,";
		}
		//if ( addMessage != "" ) themessage += " - " + ifError + " -" + addMessage + "\n"
	}
	return themessage;
}


function fJobRoleChange(oField) {
	if(oField.value=="100"){
		document.getElementById("div_job_role_other").style.display="block";
	}else{
		document.getElementById("div_job_role_other").style.display="none";
	}
}


function showRegistrationDiv(divname){
	$("#"+divname+"_registrations").slideToggle();
}

function showRegTypeDiv(divid){
	$("#RegTypeHolder_"+divid).slideToggle()
}

/* Checks to see if the registration type selected in the drop down isn't the label. */
function fRegCheckSubmit(oField) {
	if (oField.value != "") {
		oField.form.submit()
	}
}

function fJournoTerms(oBox) {
	$(oBox).attr("checked") ? $("#journoRegSelect").css("display","block") : $("#journoRegSelect").css("display","none")
}

function fChangeRegType() {
	if ($("#package_code").val() == "") { return false; }
	// Changing the registration type
	var bShowDoB = 0;
	var bShowStu = 0;
	var bShowSS = 0;
	var bShowGuest = 0;
	var bShowYLComp = 0;
	var sCurrRegType = $("#package_code").val(); // Format is 1:FD so need to get first digit
	aCurrRegType = sCurrRegType.split(":");
	sCurrRegTypeID = aCurrRegType[0];
	sCurrPackage = aCurrRegType[1];

	//alert(sCurrRegTypeID+" "+sCurrPackage)
	//alert(aPCodesDoB+" "+sCurrPackage)
	$.each(aPCodesDoB, function() {
		if(sCurrPackage == this) {
			bShowDoB = true;
			$.each(aPCodesYLCreatives, function() { if(sCurrPackage == this) {
				// Creative
				$("#formEleDoBCreatives").show();
				$("#formEleDoBMarketers").hide();
				sDoBType = sDoBTextCreative;
				sDoBUSA = sDoBUSACreative;
				sDoBUK = sDoBUKCreative;
			}	});
			$.each(aPCodesYLMarketers, function() { if(sCurrPackage == this) {
				// Marketer
				$("#formEleDoBCreatives").hide();
				$("#formEleDoBMarketers").show();
				sDoBType = sDoBTextMarketer;
				sDoBUSA = sDoBUSAMarketer;
				sDoBUK = sDoBUKMarketer;
			}	});
		}
	});
	$.each(aPCodesStu, function() {
		if(sCurrPackage == this) { bShowStu = true; }
	});
	$.each(aPCodesSS, function() {
		if(sCurrPackage == this) { bShowSS = true; }
	});
	$.each(arrGuestCodes, function() {
		if(sCurrPackage == this) {  bShowGuest = true; }
	});
	$.each(aPCodesYLComp, function() {
		if(sCurrPackage == this) { bShowYLComp = true; }
	});

	//Guest
	if (bShowGuest) {
		$("#guest_section").show();
		fGuestYes();
	} else {
		$("#guest_section").hide();
		fGuestNo();
	}
	// YC DoB
	if (bShowDoB) {
		bValidateDoB = true;
		$(".formEleDoB").show();
	} else {
		bValidateDoB = false;
		$(".formEleDoB").hide();
	}
	// Young Lions Comp
	if (bShowYLComp) {
		$(".formEleYLComp").show();
	} else {
		$(".formEleYLComp").hide();
	}
	// Students
	if (bShowStu) {
		bValidateStudent = true;
		$("#for_company_name").html("College/University");
		$("#company_agency_group").hide();
		$("#form_company_type").hide();
		$("#form_job_role").hide();
		$("#form_degree_faculty").show();
	} else {
		bValidateStudent = false;
		$("#for_company_name").html("Company Name");
		$("#company_agency_group").show();
		$("#form_company_type").show();
		$("#form_job_role").show();
		$("#form_degree_faculty").hide();
	}
	// Seminar Speaker
	if (bShowSS) {
		bValidateSeminar = true;
		$("#form_seminar_date").show();
	} else {
		bValidateSeminar = false;
		$("#form_seminar_date").hide();
	}
	
	// Different reg type
	$(".person_label").html(eval("label_name_"+sCurrRegTypeID));
	if(nRegTypeCurrent != sCurrRegTypeID) {
		nRegTypeCurrent = sCurrRegTypeID; // Set global var
	}
	
	// Set hidden form values
	$("#del_form_registration_type_id").val(sCurrRegTypeID)
	$("#del_form_package_code").val(sCurrPackage)
	
}


// ---------------------------------------------
// 		ERROR DISPLAYS : REGISTRATIONS
// ---------------------------------------------
//  These are section spcific error display functions for the registrtion system
//  Requires:  ErrorDisplay.js, jquery.js

function fPressSubmitForm(vFormID) { AllowSubmit = 1; document.getElementById(vFormID).submit(); }
function fPressYes() { AllowSubmit = 1; document.getElementById('button_yes').click(); }

function fErrorLowAccomPref(vNumber) {
	if (typeof vFunction == 'undefined' ) vFunction = "fPressSubmit()";
	var vS = "";
	if (parseInt(vNumber) > 1) vS = "s";
	vMsg = "<h3>! Accommodation Preferences</h3>";
	vMsg += "You have only chosen "+vNumber+" accommodation preference"+vS+". Click 'Confirm' to continue or 'Cancel' to choose  more accommodation preferences."
	vMsg += '<div id="TBAlertButtons" class="center clearfix"><a href="javascript:tb_alert_close()" class="button_style icon_cross'+IEstyles+'" style="margin-right:50px;">Cancel</a><a href="javascript:fPressSubmit()" class="button_style icon_tick'+IEstyles+'">Confirm</a></div>';
	tb_alertbox(vMsg);
	return false;
}

function fYCStudentAccomNote() {
		if (AllowSubmit == 1) { return true; }
		vMsg = "<h3>Accommodation for Young Spikes &amp; Students</h3>";
		vMsg += "<p>Discounted hotel rates are limited and subject to availability.</p><p>Accommodation will be reserved in 2 and 3 star hotels in Cannes on the basis of two participants sharing a twin room.</p><p>The Festival office will randomly allocate two people of the same gender to share a room unless sharers are clearly specified at the time of registration.</p><p>If you would like to share your hotel room with another young creative/young marketer or student, please specify this at the time of registering otherwise we will assume you require a sharer.</p><p>Special room rates cannot be guaranteed if no sharer can be found.</p>"
		vMsg += '<div id="TBAlertButtons" class="center clearfix"><a href="javascript:fPressYes()" style="margin-right:50px;" class="button_style icon_tick'+IEstyles+'">Confirm</a></div>';
		tb_alertbox(vMsg);
		return false;
}

function fAccomYes() {
	$("#accom_all").show();
	$(".accom_button").addClass("lesser_button");
	$(".accom_hdr").hide();
	$("#accom_hdr_yes").show();
	$("#accom_button_yes").removeClass("lesser_button");
	$("#accom_dates").show();
	$("#accom_yes").show();
	$("#accom_no").hide();
	$("#accom_sharing").hide();
	$("#hotel_needed").val("1");
}

function fAccomNo() {
	$("#accom_all").show();
	$(".accom_button").addClass("lesser_button");
	$(".accom_hdr").hide();
	$("#accom_hdr_no").show();
	$("#accom_button_no").removeClass("lesser_button");
	$("#accom_dates").show();
	$("#accom_yes").hide();
	$("#accom_sharing").hide();
	$("#accom_no").show();
	$("#hotel_needed").val("0");
}

function fAccomShare() {
	$("#accom_all").show();
	$(".accom_button").addClass("lesser_button");
	$(".accom_hdr").hide();
	$("#accom_hdr_share").show();
	$("#accom_button_share").removeClass("lesser_button");
	$("#accom_dates").hide();
	$("#accom_sharing").show();
	$("#accom_yes").hide();
	$("#accom_no").hide();
	$("#hotel_needed").val("2");
}

// GUEST

function fGuestYes() {
	$("#guest_yes").show();
	$("#guest_added").val("1");
	$("#guest_button_yes").removeClass("lesser_button");
	$("#guest_button_no").addClass("lesser_button");
}
function fGuestNo() {
	$("#guest_yes").hide();
	$("#guest_added").val("0");
	$("#guest_button_no").removeClass("lesser_button");
	$("#guest_button_yes").addClass("lesser_button");
}

// AMEND FUNCTIONS
var bFormSubmitted = false;

function fSubmitForm() {
	if (bFormSubmitted == false) {
		bFormSubmitted = true
		return true
	} else {
		return false;
	}
}

function fShowEdit(sID) {
	$("#div_"+sID).show();
	$("#divEdit_"+sID).hide();
	$("#divEditValue_"+sID).hide();
	$("#divClose_"+sID).show();
	$(sID).focus()
}
function fCloseEdit(sID) {
	$(sID).value="";
	$("#div_"+sID).hide();
	$("#divEdit_"+sID).show();
	$("#divEditValue_"+sID).show();
	$("#divClose_"+sID).hide();
}
function fCheckEmpty(sID) {
	//if( document.getElementById(sID).value == "" ) {
		//$("div_"+sID).style.display = "none"
		//$("divEdit_"+sID).style.display = "block"
	//}
}

function fCConnectText() {
	fErrorAlert("<h3>Cannes Connect</h3><p>Cannes Connect is an online networking tool for Cannes Lions delegates. It allows you to look up fellow attendees and send them a message or meeting request through our website. A delegate's email address will NEVER be disclosed to other delegates.</p><p>By opting out of Cannes Connect, you will not be able to look up other attendees or receive any messages. Your name will also not appear on the Schematic Touchwall, an interactive touchwall situated in the Palais des Festivals that allows delegates to send messages to other delegates and send themselves Cannes event, bar and restaurant information.</p>");
}

