var pkProspectID;
var ProspectFirstName;
var ProspectLastName;
var ProspectEmail;
var ProspectWhereFrom;
var SchoolName;

function openpage(pagename,windowYN){
	if(windowYN=="0"){
	window.location = pagename;
	}
	if(windowYN=="1"){
	window.open(pagename,'mywindow','width=800,height=600');
	}
}
function createPlayer() {
	var flashvars = {
		file:"Images/MM_Demo/MobyMathPresentation.flv", 
		autostart:"false",
		image:"Images/PlayerImage.png"
	}

	var params = {
		allowfullscreen:"true", 
		allowscriptaccess:"always"
	}

	var attributes = {
		id:"player1",  
		name:"player1"
	}

	swfobject.embedSWF("mediaplayer.swf", "placeholder1", "245px", "170px", "9.0.115", false, flashvars, params, attributes);
	
}


function Register(){
	var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;	
	var Email = document.getElementById("Email").value;	
	var Phone = document.getElementById("Phone").value;	
	var School = document.getElementById("School").value;	
	var District = document.getElementById("District").value;	
	
	ProspectFirstName = FirstName;
	ProspectLastName = LastName;	
	ProspectEmail = Email;
	SchoolName = School;
	
		if (FirstName == "") {
			// shwo message
			pinkArrow.showTopRight("FirstName","MMNotComplete");
			return; // exit from function
		} // if
		
		if (LastName == "") {
			// shwo message
			pinkArrow.showTopRight("LastName","MMNotComplete");
			return; // exit from function
		} // if
		
        var title = document.getElementById('Title');
		if (title.value==""){
			pinkArrow.showTopRight("Title","MMNotComplete");
			return; // exit from function
		}

		if (Email == "") {
			// shwo message
			pinkArrow.showTopRight("Email","MMNotComplete");
			return; // exit from function
		} // if
		if (Phone == "") {
			// shwo message
			pinkArrow.showTopRight("Phone","MMNotComplete");
			return; // exit from function
		} // if

        var School = document.getElementById('School');
		if (School.value==""){
			pinkArrow.showTopRight("School","MMNotComplete");
			return; // exit from function
		}
		
        var State = document.getElementById('State');
		if (State.value==""){
			pinkArrow.showTopRight("State","MMNotComplete");
			return; // exit from function
		}


		
        var WhereFrom = document.getElementById('WhereFrom');
		if (WhereFrom.value==""){
			pinkArrow.showTopRight("WhereFrom","MMNotComplete");
			return; // exit from function
		}
		ProspectWhereFrom = WhereFrom.value;
				
		ajax = new AjaxEngine();	// make ajax object
		ajax.addCode('action','create_account');	// add parameter
		ajax.addCode('FirstName',FirstName); // add parameter
		ajax.addCode('LastName',LastName); // add parameter		
		ajax.addCode('email',Email); // add parameter		
		ajax.addCode('phone',Phone); // add parameter				
		ajax.addCode('school',School.value); // add parameter				
		ajax.addCode('district',District); // add parameter						
		ajax.addCode('title',title.value); // add parameter
		ajax.addCode('wherefrom',WhereFrom.value); // add parameter
		ajax.addCode('state',State.value); // add parameter
		ajax.loadXML('Source/HomeXML.php',RegisterContinue_cb); // make ajax call
	
}
function RegisterContinue_cb(data){
	// convert xml to object
	var dataObj = data.formatAsObject();
	
	if (dataObj.Status == "OK"){
		showCreateSchoolDiv();
		clearSchoolDiv();
		pkProspectID = dataObj.pkProspectID;
	}
	
	if (dataObj.Status == "SchoolExists"){
			pkProspectID = dataObj.pkProspectID;
			document.getElementById("Schools").innerHTML = dataObj.ExistingSchools;
			document.getElementById("accountExists").style.display = 'block';
			document.getElementById("subdomain").value = "";
			clearSchoolDiv();
			document.getElementById("school_progress_bar").style.display = 'none';
			return; // exit from function	
	}
		
	if (dataObj.Status == "IPAddressError"){
			document.getElementById("school_progress_bar").style.display = 'none';
				alert("Sorry, appears you have created 10 classes. Please call \n888-793-8331 and we can help you create another school.");
				return; // exit from function	
	}
}

function showCreateSchoolDiv(){
	//	if (ProspectWhereFrom != 'Phone call from us') 
			document.getElementById("WebinarCover").style.display = 'none';
	//	else
//			document.getElementById("WebinarCover").style.display = 'block';
			document.getElementById("createSchoolDiv").style.display = 'block';
			document.getElementById("WebinarTimeCover").style.display = 'block';
	}
	
function CreateSchool(){
		var SubDomain = document.getElementById("subdomain").value;
		var Username = document.getElementById("Username").value;
		var Password = document.getElementById("Password").value;		
		var WebinarTime = document.getElementById("WebinarTime").value;		
		var WebinarDate = document.getElementById("WebinarDate").value;		
		var WebinarTimezone = document.getElementById("WebinarTimezone").value;
		
		if (Username==""){
			pinkArrow.showTopRight("Username","EnterUsername");
			return; // exit from function
		}
		
		if (Username.length < 6) {
			// shwo message
			pinkArrow.showLeft("Username","UsernameInvalidLength");
			return; // exit from function
		} // if
		
		if (/\W/.test(Username)) {
			pinkArrow.showLeft("Username","UsernameInvalid");
			return; // exit from function
		}
		
		if (Password==""){
			pinkArrow.showTopRight("Password","EnterPassword");
			return; // exit from function
		}

		
		if (Password.length < 6) {
			// shwo message
			pinkArrow.showLeft("Password","PasswordInvalidLength");
			return; // exit from function
		} // if
		
		if (SubDomain == ""){
				pinkArrow.showLeft("subdomain","EnterSubDomain");
				return; // exit from function
		}

		if (/\W/.test(SubDomain)) {
			pinkArrow.showLeft("subdomain","SubDomainInvalid");
			return; // exit from function
		}

		
		
	//	if (ProspectWhereFrom != 'Phone call from us'){

			if (WebinarDate == ""){
				pinkArrow.showTopLeft("WebinarDate","MMSelectDate");
				return; // exit from function
			}

			if (WebinarTimezone == ""){
				pinkArrow.showTopLeft("WebinarTimezone","MMSelectTimezone");
				return; // exit from function
			}

			if (WebinarTime == ""){
				pinkArrow.showTopRight("WebinarTime","MMSelectTime");
				return; // exit from function
			}

	//	}
		
		/*if (WebinarTime != "" && /^(0[0-9]|1[0-9]|2[0-4]):([0-5][0-9])\s(AM|PM|am|pm)$/.test(WebinarTime) == false) {
			pinkArrow.showLeft("WebinarTime","InvalidTime");
			return; // exit from function
		}
		
		if (WebinarDate != "" && /^([1-9]|0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/\d\d$/.test(WebinarDate) == false) {
			pinkArrow.showLeft("WebinarDate","InvalidDate");
			return; // exit from function
		}*/

		pinkArrow.removeArrow();
		document.getElementById("school_progress_bar").style.display = 'block';
		ajax = new AjaxEngine();	// make ajax object
		ajax.HideProgressBar = true;
		ajax.addCode('action','create_school');	// add parameter
		ajax.addCode('SubDomain',SubDomain); // add parameter
		ajax.addCode('ProspectFirstName',ProspectFirstName); // add parameter		
		ajax.addCode('ProspectLastName',ProspectLastName); // add parameter
		ajax.addCode('ProspectEmail',ProspectEmail); // add parameter										
		ajax.addCode('pkProspectID',pkProspectID); // add parameter			
		ajax.addCode('Username',Username); // add parameter		
		ajax.addCode('Password',Password); // add parameter				
		ajax.addCode('SchoolName',SchoolName); // add parameter	
		ajax.addCode('WebinarTime',WebinarTime); // add parameter		
		ajax.addCode('WebinarDate',WebinarDate); // add parameter		
		ajax.addCode('WebinarTimezone',WebinarTimezone); // add parameter	
		ajax.loadXML('Source/HomeXML.php',CreateSchool_cb); // make ajax call
	}
	
function CreateSchool_cb(data){
		var dataObj = data.formatAsObject();
		if (dataObj.Status == "OK"){
			document.getElementById("createSchoolDiv").style.display = "none";			
			document.getElementById("accountCreatedDiv").style.display = "block";
			document.getElementById("varSubDomain").innerHTML = "<a href='http://www."+document.getElementById("subdomain").value+".mobymath.com' target='_blank'>www."+document.getElementById("subdomain").value+".MobyMath.com</a>";
			document.getElementById("varUsername").innerHTML = dataObj.Username;
			document.getElementById("varPassword").innerHTML = dataObj.Password;		
		}
		if (dataObj.Status == "SubDomainError"){
			document.getElementById("school_progress_bar").style.display = 'none';
			pinkArrow.showLeft("subdomain","SubDomainExist");
				return; // exit from function	
		}

	}	
	

function fillTeacher(){
			if (document.getElementById("chkTeacher").checked == true){
				document.getElementById("FirstNameTeacher").value = document.getElementById("FirstName").value;
				document.getElementById("LastNameTeacher").value = document.getElementById("LastName").value;	
				document.getElementById("EmailTeacher").value = document.getElementById("Email").value;	
				document.getElementById("PhoneTeacher").value = document.getElementById("Phone").value;				
			}
	}
function clearSchoolDiv(){
			document.getElementById("Username").value = "";
			document.getElementById("Password").value = "";	
			document.getElementById("subdomain").value = "";				
			document.getElementById("WebinarTime").value = "";
			document.getElementById("WebinarDate").value = "";	
			document.getElementById("WebinarTimezone").value = "";	
	}	
	

function setWebinar(id)	{
		var WebinarTime = document.getElementById("WebinarTime").value;	
		var WebinarTimezone = document.getElementById("WebinarTimezone").value;
		var WebinarDate = document.getElementById("WebinarDate").value;	


		

			if (WebinarDate == ""){
				pinkArrow.showTopLeft("WebinarDate","MMSelectDate");
				return; // exit from function
			}

			if (WebinarTimezone == ""){
				pinkArrow.showTopLeft("WebinarTimezone","MMSelectTimezone");
				return; // exit from function
			}

			if (WebinarTime == ""){
				pinkArrow.showTopRight("WebinarTime","MMSelectTime");
				return; // exit from function
			}

		

		
		/*if (WebinarTime != "" && /^(0[0-9]|1[0-9]|2[0-4]):([0-5][0-9])\s(AM|PM|am|pm)$/.test(WebinarTime) == false) {
			pinkArrow.showLeft("WebinarTime","InvalidTime");
			return; // exit from function
		}
		
		if (WebinarDate != "" && /^([1-9]|0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/\d\d$/.test(WebinarDate) == false) {
			pinkArrow.showLeft("WebinarDate","InvalidDate");
			return; // exit from function
		}*/
		
		ajax = new AjaxEngine();	// make ajax object
		ajax.HideProgressBar = true;
		ajax.addCode('action','set_webinar');	// add parameter
		ajax.addCode('pkProspectID',id); // add parameter	
		ajax.addCode('WebinarTime',WebinarTime); // add parameter			
		ajax.addCode('WebinarTimezone',WebinarTimezone); // add parameter		
		ajax.addCode('WebinarDate',WebinarDate); // add parameter				
		ajax.loadXML('/MobyMath/Source/HomeXML.php',setWebinar_cb); // make ajax call
}


function setWebinar_cb(data){
		var dataObj = data.formatAsObject();
		if (dataObj.Status == "OK"){
			alert("Thank you for registering for your Moby Math Training \nWebinar. We look forward to helping you get started.")
			document.getElementById("WebinarTime").value = "";	
			document.getElementById("WebinarTimezone").value = "";	
			document.getElementById("WebinarDate").value = "";	
			document.getElementById("WebinarTimeCover").style.display = 'block';
			document.getElementById("WebinarTime").options.length = 0;
		}
	}

function FillTime(obj){
		timezone = obj.value;
		time = document.getElementById("WebinarTime");
		ET = new Array("9:00 am","9:15 am","9:30 am","9:45 am","10:00 am","10:15 am","10:30 am","10:45 am","11:00 am","11:15 am","11:30 am","11:45 am","12:00 pm","12:15 pm","12:30 pm","12:45 pm","1:00 pm","1:15 pm","1:30 pm","1:45 pm","2:00 pm","2:15 pm","2:30 pm","2:45 pm","3:00 pm","3:15 pm","3:30 pm","3:45 pm","4:00 pm","4:15 pm","4:30 pm","4:45 pm");
		CT = new Array("8:00 am","8:15 am","8:30 am","8:45 am","9:00 am","9:15 am","9:30 am","9:45 am","10:00 am","10:15 am","10:30 am","10:45 am","11:00 am","11:15 am","11:30 am","11:45 am","12:00 pm","12:15 pm","12:30 pm","12:45 pm","1:00 pm","1:15 pm","1:30 pm","1:45 pm","2:00 pm","2:15 pm","2:30 pm","2:45 pm","3:00 pm","3:15 pm","3:30 pm","3:45 pm");
		MT = new Array("7:00 am","7:15 am","7:30 am","7:45 am","8:00 am","8:15 am","8:30 am","8:45 am","9:00 am","9:15 am","9:30 am","9:45 am","10:00 am","10:15 am","10:30 am","10:45 am","11:00 am","11:15 am","11:30 am","11:45 am","12:00 pm","12:15 pm","12:30 pm","12:45 pm","1:00 pm","1:15 pm","1:30 pm","1:45 pm","2:00 pm","2:15 pm","2:30 pm","2:45 pm");
		PT = new Array("6:00 am","6:15 am","6:30 am","6:45 am","7:00 am","7:15 am","7:30 am","7:45 am","8:00 am","8:15 am","8:30 am","8:45 am","9:00 am","9:15 am","9:30 am","9:45 am","10:00 am","10:15 am","10:30 am","10:45 am","11:00 am","11:15 am","11:30 am","11:45 am","12:00 pm","12:15 pm","12:30 pm","12:45 pm","1:00 pm","1:15 pm","1:30 pm","1:45 pm");
		
		time.options.length = 0;		
		if (timezone == ''){
			document.getElementById("WebinarTimeCover").style.display = 'block';	
			return;
		}
		
		document.getElementById("WebinarTimeCover").style.display = 'none';	
		
		time.options[time.options.length] = new Option("Select","");
		
		if (timezone == 'ET')
			for (i=0;i<ET.length;i++)
				time.options[time.options.length] = new Option(ET[i],ET[i]);
		if (timezone == 'CT')
			for (i=0;i<CT.length;i++)
				time.options[time.options.length] = new Option(CT[i],CT[i]);
		if (timezone == 'MT')
			for (i=0;i<MT.length;i++)
				time.options[time.options.length] = new Option(MT[i],MT[i]);
		if (timezone == 'PT')
			for (i=0;i<PT.length;i++)
				time.options[time.options.length] = new Option(PT[i],PT[i]);

	}

function clearProspect(){
		document.getElementById("FirstName").value = "";
		document.getElementById("LastName").value = "";	
		document.getElementById("Email").value = "";	
		document.getElementById("Phone").value = "";	
		document.getElementById("School").value = "";	
		document.getElementById("District").value = "";
		document.getElementById("Title").selectedIndex = 0;
		document.getElementById("State").selectedIndex = 0;
		document.getElementById("WhereFrom").selectedIndex = 0;		
	}
