webucator_partner_init();

function webucator_partner_init() {
	var queryString = "";
	try {
	 	queryString = document.location.search;
	} catch (err) {
		alert("Your browser appears to be running in High security mode. This page may not function correctly.");
	}
	if (pageName.indexOf('-') != -1) {
		var d = pageName.indexOf('-schedule');
		if (d > 0) {
			pageName = pageName.substring(0, d);
		}
		d = pageName.indexOf('-category');
		if (d > 0) {
			pageName = pageName.substring(0, d);
		}
	}
	if (queryString.length == 0) { 
		queryString = '?';
		if (pageType != 'default') { 
			queryString += 'action='+pageType+'&page='+pageName + '&'; 
		}
	} else { queryString+= '&';}
	if (typeof(window['disableBreadCrumb'])!='undefined') {
		if (disableBreadCrumb) { queryString+= "DisableBreadCrumb=1&";}
	}
	if (typeof(window['partnerType'])=='undefined') {
		queryString += "partnerType=ilo&";
		partnerType = "ilo";
	} else {
		queryString += "partnerType=" + partnerType + "&";
	}
	queryString += "PartnerID=" + partnerID;
	queryString += "&ts=" + new Date().getTime(); //to prevent caching
	//TODO change back to www.webucator.com
	if (typeof(window['webucatorDevelopment']) != "undefined") {
		document.write('<script language="javascript" src="/Partners/script.cfm' + queryString + '"><\/script>');
	} else {
		document.write('<script language="javascript" src="http://www.webucator.com/partners/script.cfm' + queryString + '"><\/script>');
	}
	if (typeof window.onload == 'function'){
		var windowLoadFunction = window.onload;
		window.onload = function(){
			for(var i=0;i<document.forms.length;i++){
				document.forms[i].style.height='auto';
			}
			if (document.getElementById('w8_registerFrame')){
				if (parseInt(document.getElementById('w8_registerFrame').style.width) != 1){
					document.getElementById('w8_registerFrame').style.width = '1px';
				}
			}
			windowLoadFunction();
		};
	}else{
		window.onload = function(){
			for(var i=0;i<document.forms.length;i++){
				document.forms[i].style.height='auto';
			}
			if (document.getElementById('w8_registerFrame')){
				if (parseInt(document.getElementById('w8_registerFrame').style.width) != 1){
					document.getElementById('w8_registerFrame').style.width = '1px';
				}
			}
		};
	}
}


function navigateToSchedule(pageName) {
	if (pageLinks[pageName + '-schedule'] != null) {
		if(partnerID==33) { //Deitel
			window.top.document.location = pageLinks[pageName + '-schedule'];
		} else {
			document.location = pageLinks[pageName + '-schedule'];
		}
	}
	else {
		document.location = "?action=schedule&page=" + escape(pageName);
	}
}

function navigateToCategoryGroup(pageName) {
	if (pageLinks[pageName] != null) {
		if (partnerID == 33) { //Deitel
			window.top.document.location = pageLinks[pageName];
		} else {
			document.location = pageLinks[pageName];
		}
	}
	else {
		document.location = location.pathname + "?action=categorygroup&page=" + escape(pageName);
	}
}

function navigateToCategory(pageName) {
	if (pageLinks[pageName + '-category'] != null) {
		if (partnerID == 33) { //Deitel
			window.top.document.location = pageLinks[pageName + '-category'];
		} else {
			document.location = pageLinks[pageName + '-category'];
		}
	}
	else {
		document.location = location.pathname + "?action=category&page=" + escape(pageName);
	}
}


function navigateToCourse(pageName) {
	if (pageLinks[pageName] != null) {
		if (partnerID == 33) { //Deitel
			window.top.document.location = pageLinks[pageName];
		} else {
			document.location = pageLinks[pageName];
		}
	}
	else {
		document.location = location.pathname + "?action=course&page=" + escape(pageName);
	}
}

function navigateToSeries(pageName) {
	if (pageLinks[pageName] != null) {
		if (partnerID == 33) { //Deitel
			window.top.document.location = pageLinks[pageName];
		} else {
			document.location = pageLinks[pageName];
		}
	}
	else {
		document.location = location.pathname + "?action=series&page=" + escape(pageName);
	}
}


function navigateToPage(pageName) {
	if (pageLinks[pageName] != null) {
		if (partnerID == 33) { //Deitel
			window.top.document.location = pageLinks[pageName];
		} else {
			document.location = pageLinks[pageName];
		}
	}
	else {
		document.location = location.pathname + "?action=view&page=" + escape(pageName);
	}
}

function navigateHome() {
	document.location = location.pathname + "?action=home&page=home";
}





function SubmitFreeDemo(FORM)
{
	if (FORM.ClassEventID.options.length) {
  	var ClassEventID = FORM.ClassEventID.options[FORM.ClassEventID.options.selectedIndex].value;
  }else{
		var ClassEventID = 0;
	}
	var State = FORM.State.options[FORM.State.options.selectedIndex].value;
	var FirstName = FORM.FirstName.value;
	var LastName = FORM.LastName.value;
	var Company = FORM.Company.value;
	var Telephone = FORM.Telephone.value;
	var Email = FORM.Email.value;
	var Email2 = FORM.Email2.value;
	var Street1 = FORM.Street1.value;
	var Street2 = FORM.Street2.value;
	var City = FORM.City.value;
	var Zip = FORM.Zip.value;
	
	var Errors = false;	
	if (FirstName.length==0)
	{
		document.getElementById("FirstName").style.border="2px solid red";
		Errors=true;
	}
	if (LastName.length==0)
	{
		document.getElementById("LastName").style.border="2px solid red";
		Errors=true;
	}
	if (Telephone.length==0)
	{
		document.getElementById("Telephone").style.border="2px solid red";
		Errors=true;
	}
	if (Email.length < 6 || Email.indexOf("@") == -1 || Email.indexOf(".") == -1 || (Email.lastIndexOf(".") < Email.lastIndexOf("@")))
	{
		document.getElementById("Email").style.border="2px solid red";
		Errors=true;
	}
	else if (Email != Email2)
	{
		document.getElementById("Email2").style.border="2px solid red";
		Errors=true;
	}
	
	if (Street1.length==0)
	{
		document.getElementById("Street1").style.border="2px solid red";
		Errors=true;
	}
	
	if (Errors)
	{
		alert("Please fix the highlighted errors.");
		return false;
	}
	else
	{
		document.getElementById('w8_freeDemoFrame').style.width = "100%";
		document.getElementById('w8_freeDemoFrame').style.height = "800px";
		document.getElementById('FreeDemoArea').style.display = "none";
		return true;
	}
}

var somechecked = false;
function SubmitContactForm(FORM)
{
	var State = FORM.State.options[FORM.State.options.selectedIndex].value;
	var FirstName = FORM.FirstName.value;
	var LastName = FORM.LastName.value;
	var Company = FORM.Company.value;
	var Telephone = FORM.Telephone.value;
	var Email = FORM.Email.value;
	var Email2 = FORM.Email2.value;
	var Street1 = FORM.Street1.value;
	var Street2 = FORM.Street2.value;
	var City = FORM.City.value;
	var Zip = FORM.Zip.value;
	var Country = FORM.Country.value;
	var TimeFrame = FORM.TimeFrame;
	
	var Errors = false;		
	if (FirstName.length==0)
	{
		document.getElementById("FirstNameLabel").className="Emphasize";
		Errors=true;
	}
	if (LastName.length==0)
	{
		document.getElementById("LastNameLabel").className="Emphasize";
		Errors=true;
	}
	if (Telephone.length==0)
	{
		document.getElementById("TelephoneLabel").className="Emphasize";
		Errors=true;
	}
	if (Email.length < 6 || Email.indexOf("@") == -1 || Email.indexOf(".") == -1 || (Email.lastIndexOf(".") < Email.lastIndexOf("@")))
	{
		document.getElementById("EmailLabel").className="Emphasize";
		document.getElementById("Email").className="Emphasize";
		Errors=true;
	}
	else if (Email != Email2)
	{
		document.getElementById("Email2Label").className="Emphasize";
		document.getElementById("Email2").className="Emphasize";
		Errors=true;
	}
	
	if (Street1.length==0)
	{
		document.getElementById("Street1Label").className="Emphasize";
		Errors=true;
	}
	if (City.length==0)
	{
		document.getElementById("CityLabel").className="Emphasize";
		Errors=true;
	}
	if (Zip.length < 5)
	{
		document.getElementById("ZipLabel").className="Emphasize";
		Errors=true;
	}
	if (Country.length==0)
	{
		document.getElementById("CountryLabel").className="Emphasize";
		Errors=true;
	}
	if (TimeFrame.selectedIndex==0)
	{
		document.getElementById("TimeFrameLabel").className="Emphasize";
		Errors=true;
	}
	
	if (Errors || !somechecked)
	{
		if (!somechecked)
		{
			alert("You must select at least one class of interest.");
		}
		else
		{
			alert("Please fix the highlighted errors.");
		}
		return false;
	}
	else
	{
		return true;
	}
}

function ShowOutline(COURSEID,PARTNERID)
{
	var OutlineWin = window.open("http://www.webucator.com/Partners/Outline.cfm?course=" + COURSEID + "&PartnerID=" + PARTNERID,OutlineWin,"height=500,width=500,scrollbars=1,resizable=1,top=10,left=10");	
	OutlineWin.focus();
}

function Register(FORM)
{
	var Errors=true;
	for (i=0; i<FORM.elements.length; i++)
	{
		if (FORM.elements[i].checked)
		{
			if (parseInt(document.getElementById('w8_registerFrame').style.width) == 1){
				document.getElementById('w8_registerFrame').style.width = "100%";
			}
			document.getElementById('w8_registerFrame').style.height = "800px";
			document.getElementById('course_listings').style.display = "none";
			return true;
		}
	}
	alert("Please select at least one course.");
	return false;
}

function RegisterAyop(FORM)
{
	var isValid = false;
	if (typeof(FORM.SeriesList.length) != "undefined") {
		//if checkbox
		for (i=0;i<FORM.SeriesList.length;i++) {
			if (FORM.SeriesList[i].checked) {
				isValid = true;
				break;
			}
		}
	} else if (typeof(FORM.SeriesList) != "undefined") {
		//input box
		isValid = true;
	}
	if (isValid) {
		if (parseInt(document.getElementById('w8_registerFrame').style.width) == 1){
			document.getElementById('w8_registerFrame').style.width = "100%";
		}
		document.getElementById('w8_registerFrame').style.height = "800px";
		document.getElementById('series_listings').style.display = "none";
		return true;
	} else {
		alert('Please Select at least one Course Series');
		return false;
	}
}

function setupAyopRegistrationForm(formObj) {
	formObj.target = "registerFrame";
	formObj.action = document.getElementById("webucator_register_form_action").value;
	formObj.onsubmit = function() { RegisterAyop(formObj); }; 
	return true;
}



function setPrice(FORM)
{
	var NumStudents = FORM.NumStudents.options[FORM.NumStudents.selectedIndex].value;
	var tp = NumStudents * FORM.PricePerStudent.value;
	
	document.getElementById("Discount1").className="UnselectedDiscount";
	document.getElementById("Discount2").className="UnselectedDiscount";
	document.getElementById("Discount3").className="UnselectedDiscount";
	document.getElementById("Discount4").className="UnselectedDiscount";
	
	if (NumStudents == 2)
	{
		tp *= 0.95;
		document.getElementById("Discount2").className="SelectedDiscount";
		FORM.Discount.value=".05";
	}
	else if (NumStudents == 3 || NumStudents == 4)
	{
		tp *= 0.9;
		document.getElementById("Discount3").className="SelectedDiscount";
		FORM.Discount.value=".1";
	}
	else if (NumStudents >= 5)
	{
		tp *= 0.85;
		document.getElementById("Discount4").className="SelectedDiscount";
		FORM.Discount.value=".15";
	}
	else
	{
		document.getElementById("Discount1").className="SelectedDiscount";
		FORM.Discount.value="0";
	}
	FORM.TotalPrice.value=tp;
	document.getElementById("TotalPriceSpan").innerHTML=DollarFormat(tp);
}

function FillILOForm()
{
	document.ILOForm.FirstName.value = document.ILOForm.BillingFirstName.value;
	document.ILOForm.LastName.value = document.ILOForm.BillingLastName.value;
	document.ILOForm.Telephone.value = document.ILOForm.BillingTelephone.value;
	document.ILOForm.Email.value = document.ILOForm.BillingEmail.value;
	document.ILOForm.Email2.value = document.ILOForm.BillingEmail.value;
	document.ILOForm.Street1.value = document.ILOForm.BillingStreet1.value;
	document.ILOForm.Street2.value = document.ILOForm.BillingStreet2.value;
	document.ILOForm.City.value = document.ILOForm.BillingCity.value;
	document.ILOForm.Zip.value = document.ILOForm.BillingZip.value;
	
	
	for (i=0; i < document.ILOForm.State.options.length; i++)
	{
		if (document.ILOForm.State.options[i].value == document.ILOForm.BillingState.value)
		{
			document.ILOForm.State.options[i].selected=true;
			break;
		}
	}
}

function SetLabelClass(frmObj) {
	//var lblElement = document.getElementById(frmObj.name + "Label");
	//lblElement.style.color = "green";
}
function highlightChecked() { somechecked=true; }

function openContactForm(courseID,partnerID)
{
	var url = "";
	if (typeof(window['webucatorDevelopment']) == "undefined") {
		url = "http://www.webucator.com";
	}
	url+="/contact/index.cfm?PartnerView=1&CompanyPartnerID=" + partnerID + "&courseID=" + courseID + "&productTypeID=1" ;
	window.open(url,'contactWin','toolbar=no,width=520,height=600,scrollbars=1');
}

function ayopSupportFormCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name", "email","phone", "company", "subject", "description", "RespondBackVia", "UserBrowser", "UserOS", "ProblemURL", "LoginID");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name", "Email", "Phone", "Company", "Subject", "Description", "RespondBackVia", "UserBrowser", "UserOS", "ProblemURL", "LoginID");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

