//--------------------------------------------------------------------
// CUSTOMER functions
//--------------------------------------------------------------------
function Init() {
	if (GetValueFromURL('spId') != null)
	{
		var spId = GetValueFromURL('spId');
		SpeakerDescription(spId);
		moveTo('#form');
	}
	ShowState();
}

function showLayer(layer) {
    if (document.all && document.all[layer])
        document.all[layer].style.display = 'block';
    else if (document.getElementById(layer))
        document.getElementById(layer).style.display = 'block';
}

function hideLayer(layer) {
    if (document.all && document.all[layer])
        document.all[layer].style.display = 'none';
    else if (document.getElementById(layer))
        document.getElementById(layer).style.display = 'none';
}

function ShowState() {
    var country = getObjFormField("WsSignUp", "WS_Country");
    var state = getObjFormField("WsSignUp", "WS_State");
    if (country.options[country.selectedIndex].value == "1" || country.options[country.selectedIndex].value == "2" || country.options[country.selectedIndex].value == "158") {
        showLayer("state");
    }
    else {
        hideLayer("state");
        state.selectedIndex = 0;
    }
}

function ConfirmEmail() {
	var height	= "280";								// define the popup's height;
	var width	= "280";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	var t = window.open("/common/shared/webseminar/emailconf.aspx","confemail","width="+width+",height="+height+",toolbar=no,scrollbars=no,status=no,resizable=no,top="+top+",left="+left);
	t.focus();
}

function WsFAQ() {
	var height	= "350";								// define the popup's height;
	var width	= "550";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("/common/shared/webseminar/faq.aspx","wsfaq","width="+width+",height="+height+",toolbar=no,scrollbars=yes,status=no,resizable=no,top="+top+",left="+left);
}

function WsDisclaimer() {
	var height	= "330";								// define the popup's height;
	var width	= "550";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("/common/shared/webseminar/disclaimer.aspx","disclaimer","width="+width+",height="+height+",toolbar=no,scrollbars=no,status=no,resizable=no,top="+top+",left="+left);
}

function SpeakerDescription(id) {
	var height	= "300";								// define the popup's height;
	var width	= "400";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("/common/shared/webseminar/speaker.aspx?id="+id,"speaker","width="+width+",height="+height+",toolbar=no,scrollbars=yes,status=no,resizable=no,top="+top+",left="+left);
}

function ToSummary() {
	location.href = 'index.aspx';
}

function isPhoneNumber(aStr) {	
	var index;
	var reg = "0123456789()+/\\-_. "
		for (index=0; index < aStr.length; index++)
		if (reg.indexOf(aStr.charAt(index))==-1)
			return false;
		return true;
}

function checkphone(champ,message) {
	if (!isPhoneNumber(champ.value))
	{
		alert(message);
		champ.select();	
	}
}

function ShowWSFAQItem(c) {
    var img = document.getElementById("img" + c);
    var div = document.getElementById("faqwsitem" + c);

    if (img.src.indexOf("plus.gif") != -1) {
        div.style.display = "block";
        img.src = "/img/ws/ws_minus.gif";
    }
    else {
        div.style.display = "none";
        img.src = "/img/ws/ws_plus.gif";
    }
}

function Validation() {
    var FirstName   = getObjFormField("WsSignUp", "WS_FirstName");
    var LastName    = getObjFormField("WsSignUp", "WS_LastName");
    var Company     = getObjFormField("WsSignUp", "WS_Company");
    var Country     = getObjFormField("WsSignUp", "WS_Country");
    var Email       = getObjFormField("WsSignUp", "WS_Email");
    var InterPhone  = getObjFormField("WsSignUp", "WS_InterPhone");
    var Phone       = getObjFormField("WsSignUp", "WS_Phone");
    var Address     = getObjFormField("WsSignUp", "WS_Address");
//  var Job         = getObjFormField("WsSignUp", "Job");
    var Zip         = getObjFormField("WsSignUp", "WS_ZipCode");
    var City        = getObjFormField("WsSignUp", "WS_City");
    var State       = getObjFormField("WsSignUp", "WS_State");
//  var Activity    = getObjFormField("WsSignUp", "Activity");
    var form        = getObjForm("WsSignUp");

    // First Name
    if (isNull(FirstName.value)) {
        alert(alertfirstname);
        FirstName.focus();
        return;
    }
    // Last Name
    if (isNull(LastName.value)) {
        alert(alertlastname);
        LastName.focus();
        return;
    }
    // Email
    if (isNull(Email.value)) {
        alert(alertemail);
        Email.focus();
        return;
    }
    if (!checkmail(Email.value)) {
        alert(alertemailvalid);
        Email.focus();
        return;
    }
    // Company Name
    if (isNull(Company.value)) {
        alert(alertcompany);
        Company.focus();
        return;
    }
    // Address
    if (isNull(Address.value)) {
        alert("Address is required.");
        Address.focus();
        return;
    }
    // Job
//    if (Job.selectedIndex == 0) {
//        alert(alertjob);
//        Job.focus();
//        return;
//    }
    // Area/Zip Code
    if (Zip && isNull(Zip.value)) {
        alert("Area / Zip Code is required.");
        Zip.focus();
        return;
    }
    // City
    if (isNull(City.value)) {
        alert("City is required.");
        City.focus();
        return;
    }
    // Country
    if (Country.selectedIndex == 0) {
        alert(alertcountry);
        Country.focus();
        return;
    }
    if (Country.options[Country.selectedIndex].value == "1" || Country.options[Country.selectedIndex].value == "2" || Country.options[Country.selectedIndex].value == "158") {
        if (State.options[State.selectedIndex].value == "0" || State.options[State.selectedIndex].value == "") {
            alert("State/Province is required for US, Canada and Australia users.");
            State.focus();
            return;
        }
    }
    // Phone number
    if (isNull(Phone.value)) {
        alert(alertphone);
        Phone.focus();
        return;
    }
    else if (isNull(InterPhone.value)) {
        alert(alertcodephone);
        InterPhone.focus();
        return;
    }
    // Activity
//    if (Activity.selectedIndex == 0) {
//        alert(alertactivity);
//        Activity.focus();
//        return;
//    }


	// CkeckBoxes
	check = false;
	ctr = 0;
	for (i=0 ; i<form.length ; i++)
	{
		if ((form[i].type == "checkbox") && (form[i].name.indexOf("SessionDate") > -1))
		{
			ctr++;
			if (form[i].checked)
			{
				check = true;
			}
		}
	}
	if (ctr > 0)
	{
		if (!check)
		{
			alert("Please choose a session date.");
			return;
		}
	}
	// .............suite de la verif
	ValidFormHtmlPage();
	//form.submit();
}

function ShowTab(index) {
    var list = document.getElementById("etctablist").childNodes;
    for (var i=1 ; i<=5 ; i++)
    {
        document.getElementById("etctab"+i).style.display = "none";
        document.getElementById("tab"+i).className = "";
    }

    document.getElementById("etctab"+index).style.display = "block";
    document.getElementById("tab"+index).className = "current";
    
    if (index == 5)
    {
        document.getElementById("etctabgreenborder").style.display = "block";
        document.getElementById("etctabblueborder").style.display = "none";
        moveTo('#form');
   }    
    else
    {
        document.getElementById("etctabblueborder").style.display = "block";
        document.getElementById("etctabgreenborder").style.display = "none";
    }
}

function InitEtrainingTabs() {
    if (GetValueFromURL("tab") != null) {
        var tab = GetValueFromURL("tab");
        switch (tab) {
            case "1":
                ShowTab('1');
                break;
            case "2":
                ShowTab('2');
                break;
            case "3":
                ShowTab('3');
                break;
            case "4":
                ShowTab('4');
                break;
            case "5":
                ShowTab('5');
                break;
        }
    }
}

//--------------------------------------------------------------------
// PARTNERS functions
//--------------------------------------------------------------------
function Session(idsession) {
	var form = document.forms.formchosensession;
	form.idsession.value = idsession;
	form.action = "session.aspx";
	form.submit();
}

function Cancel() {
	window.location.href = "index.aspx";
}

function ViewUserAnswer(idmember) {
	var height	= "400";								// define the popup's height;
	var width	= "450";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("viewquestionnaire.aspx?id="+idmember,"view","width="+width+",height="+height+",toolbar=no,scrollbars=yes,status=no,resizable=no,top="+top+",left="+left);
}

function ViewInformation(idquestion) {
	var height	= "400";								// define the popup's height;
	var width	= "450";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("viewinformation.aspx?id="+idquestion,"view","width="+width+",height="+height+",toolbar=no,scrollbars=yes,status=no,resizable=no,top="+top+",left="+left);
}

function ViewChatQuestions(idmember) {
	var height	= "400";								// define the popup's height;
	var width	= "450";								// define the popup's width;
	var top		= (screen.availHeight-height)/2;		// define the popup's vertical position on screen;
	var left	= (screen.availWidth-width)/2;			// define the popup's horizontal position on screen;
	window.open("viewchatquestions.aspx?id="+idmember,"view","width="+width+",height="+height+",toolbar=no,scrollbars=yes,status=no,resizable=no,top="+top+",left="+left);
}

function NavigateLink(section) {
	var form = document.forms.NavigateForm;
	form.Link.value = section;
	form.idsession.value = getObjFormField("InfoSession", "wssessionid").value; 
	form.action = "session.aspx";
	form.submit();
}
