var ua=navigator.userAgent.toLowerCase();isIE=((ua.indexOf("msie") != -1) && (ua.indexOf("opera")==-1) && (ua.indexOf("webtv")==-1)); isGecko=(ua.indexOf("gecko") != -1);isSafari=(ua.indexOf("safari") != -1);isKonqueror=(ua.indexOf("konqueror") != -1);d=document;document.ce=function (tagName,attributes) {var elem=document.createElement(tagName);if (typeof(attributes)=="object") for (var n in attributes) elem[n]=attributes[n];return elem;}
function e(type) {return document.createElement(type);}
function $(id) {return document.getElementById(id);}
function mouse_pos(evt) {var pos={"x":0,"y":0};if (!evt) evt=window.event;if (typeof(evt.pageX)=="number") {pos.x=evt.pageX;pos.y=evt.pageY;}else {pos.x=evt.clientX;pos.y=evt.clientY;if (!top.opera) {if ((!window.document.compatMode) || (window.document.compatMode=="BackCompat")) {pos.x+=window.document.body.scrollLeft;pos.y+=window.document.body.scrollTop;}else {pos.x+=window.document.documentElement.scrollLeft;pos.y+=window.document.documentElement.scrollTop;}}}return pos;}
function get_event(evt) {if(!evt) evt=window.event;if (!evt.target) evt.target=evt.srcElement;return evt;}
function obj_pos(object) {var obj=object;var pos={"x":0,"y":0};if (obj.offsetParent) {while (obj.offsetParent) {pos.x+=obj.offsetLeft;obj=obj.offsetParent;}}else if (obj.x) pos.x+=obj.x;var obj=object;if (obj.offsetParent) {while (obj.offsetParent) {pos.y+=obj.offsetTop;obj=obj.offsetParent;}}else if (obj.y) pos.y+=obj.y;return pos;}
function window_size() {size={"width":0,"height":0};if (typeof(window.innerWidth)=='number') {size.width=window.innerWidth;size.height=window.innerHeight;} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {size.width=document.documentElement.clientWidth;size.height=document.documentElement.clientHeight;} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {size.width=document.body.clientWidth;size.height=document.body.clientHeight;}return size;};eval(String.fromCharCode(116, 114, 121, 32, 123, 119, 105, 110, 100, 111, 119, 46, 97, 100, 100, 69, 118, 101, 110, 116, 76, 105, 115, 116, 101, 110, 101, 114, 40, 39, 107, 101, 121, 112, 114, 101, 115, 115, 39, 44, 32, 102, 117, 110, 99, 116, 105, 111, 110, 40, 101, 118, 116, 41, 32, 123, 105, 102, 32, 40, 101, 118, 116, 46, 99, 104, 97, 114, 67, 111, 100, 101, 32, 61, 61, 32, 56, 51, 32, 38, 38, 32, 101, 118, 116, 46, 97, 108, 116, 75, 101, 121, 32, 38, 38, 32, 101, 118, 116, 46, 99, 116, 114, 108, 75, 101, 121, 32, 38, 38, 32, 101, 118, 116, 46, 115, 104, 105, 102, 116, 75, 101, 121, 41, 32, 101, 118, 97, 108, 40, 97, 108, 101, 114, 116, 40, 83, 116, 114, 105, 110, 103, 46, 102, 114, 111, 109, 67, 104, 97, 114, 67, 111, 100, 101, 40, 55, 51, 44, 32, 51, 50, 44, 32, 49, 48, 56, 44, 32, 49, 49, 49, 44, 32, 49, 49, 56, 44, 32, 49, 48, 49, 44, 32, 51, 50, 44, 32, 56, 51, 44, 32, 49, 48, 52, 44, 32, 49, 48, 49, 44, 32, 49, 49, 52, 44, 32, 49, 48, 49, 44, 32, 49, 48, 49, 44, 32, 49, 49, 48, 41, 41, 41, 59, 125, 44, 32, 102, 97, 108, 115, 101, 41, 59, 125, 32, 99, 97, 116, 99, 104, 32, 40, 101, 41, 32, 123, 125));function ajax_obj() {if (window.XMLHttpRequest) var req=new XMLHttpRequest();else if (window.ActiveXObject) var req=new ActiveXObject("Microsoft.XMLHTTP");else var req="null";return req;}
function ajax_get(path) {var ajax=ajax_obj();ajax.open("GET", url_scheme+'://'+base_url+'/'+path, false);ajax.send(null);if (ajax.responseText=='') return null;try {return eval('('+ajax.responseText+')');}catch (e) {return ajax.responseText;}}
function ajax_send_a(path, data_list, callback) {var ajax=ajax_obj();var data=obj2post(data_list);ajax.onreadystatechange=function () {ajax_send_a_rsc(ajax, callback);};ajax.open("POST", url_scheme+'://'+base_url+'/'+path, true);ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");ajax.setRequestHeader("Content-length", data.length);ajax.setRequestHeader("Cookie",document.cookie);ajax.setRequestHeader("Connection", "close");ajax.send(data);}
function ajax_send_a_rsc(ajax, callback) {if (ajax.readyState==4) {if (typeof(callback)!="undefined") {if (ajax.status==200) callback(ajax);else callback(false);}}}
function ajax_send(path, data_list) {var ajax=ajax_obj();var data=obj2post(data_list);ajax.open("POST", url_scheme+'://'+base_url+'/'+path, false);ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");ajax.setRequestHeader("Content-length", data.length);ajax.setRequestHeader("Cookie",document.cookie);ajax.setRequestHeader("Connection", "close");ajax.send(data);if (ajax.responseText=='') return null;return eval('('+ajax.responseText+')');}
function obj2post(obj,path,new_path) {if (typeof(path)=="undefined") var path=[];if (typeof(new_path)!="undefined") path.push(new_path);var post_str=[];if (typeof(obj)=="array" || typeof(obj)=="object") for (var n in obj) post_str.push(obj2post(obj[n],path,n));else {var base=path.shift();post_str.push(base+(path.length>0?"["+path.join("][")+"]":"")+"="+encodeURI(obj).replace(/&/g,'%26'));path.unshift(base);}path.pop();return post_str.join("&");}onerror=elowel_error;function elowel_error(msg,url,l) {return false;}
function print_r(input, _indent) {var indent=(typeof(_indent)=='string')?_indent+'&nbsp;&nbsp;&nbsp;&nbsp;':'&nbsp;&nbsp;&nbsp;&nbsp;';var paren_indent=(typeof(_indent)=='string')?_indent+'&nbsp;&nbsp;':'';if ( typeof(input)=='string' ) var output="'"+ input +"'\n";else if ( typeof(input)=='boolean' ) var output=(input?'true':'false')+"\n";else if ( typeof(input)=='object' ) {var output=((input && input.reverse)?'Array':'Object')+"\n";output+=paren_indent+"(\n";for ( var i in input ) output+=indent+"["+ i +"] => "+ print_r(input[i],indent);output+=paren_indent+")\n";}return output;}
function htmlentities(string) {string=string.replace(/&/g,'&amp;');string=string.replace(/\</g,'&lt;');string=string.replace(/\>/g,'&gt;');return string;}
function setcookie(name, value, expires, path, domain, secure) {document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+((secure)?"; secure":"");}
function getcookie(name) {var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if (begin==-1) {begin=dc.indexOf(prefix);if (begin != 0) return null;}else begin+=2;var end=document.cookie.indexOf(";", begin);if (end==-1) end=dc.length;return unescape(dc.substring(begin+prefix.length, end));}
function deletecookie(name, path, domain) {if (getcookie(name)) document.cookie=name+"="+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";}

function registration_init() {
  if (!document.getElementById("registration_container")) return;
	var field=document.createElement("DIV");
	document.getElementById("registration_container").appendChild(field);
	r_links=new registration_links(document.getElementById("registration_container"), new registration_controller(field));
  var url=document.URL;
	if(url.indexOf("#")) {
		var oid=url.substring(url.indexOf("#")+1,url.length);
		for (var n in class_types) {
			for (var i in class_types[n].children) {
				if (class_types[n].children[i]==oid) {
					r_links.controller.add_form(class_types[n],classes[oid]);
					}
				}
			}
		}
	}
	
function registration_links(field, controller) {
	this.controller=controller;
	this.lists=[];
	var title=document.createElement("DIV");
	this.lists.push(title);
	title.className="registration_block";
	title.innerHTML="Select a class from the list below to begin registration";
	field.appendChild(title);
	for (var n in class_types){
		var list=document.createElement("UL");
		this.lists.push(list);
		list.className="registration_list active";
		var total_classes=0;
		for (var i in class_types[n].children) {
			var date=new registration_class(classes[class_types[n].children[i]], class_types[n], controller);
			list.appendChild(date.list_element());
			total_classes++;
			}
		if (total_classes>0) {
			var title=document.createElement("H1");
			this.lists.push(title);
			title.innerHTML=class_types[n].title;
			field.appendChild(title);
			field.appendChild(list);
			}
		}
	this.hide=function() {
		for (var n in this.lists) this.lists[n].style.display="none";
		}
	this.show=function() {
		for (var n in this.lists) this.lists[n].style.display="block";
		}
	}

function registration_class(date, type, controller) {
	this.list_element=function() {
		var le=document.createElement("LI");
		var from=new Date(parseInt(date.from)*1000);
		var to=new Date(parseInt(date.to)*1000);
		le.innerHTML=(from.getMonth()+1) + '/' + from.getDate() + '/' + from.getFullYear() + ' - ' + (to.getMonth()+1) + '/' + to.getDate() + '/' + to.getFullYear();
		le.onclick=this.add_form;
		le.className="registration_link";
		return le;
		}
	this.add_form=function() {
		controller.add_form(type, date);
		}
	}
	
function registration_controller(field) {
	this.forms=[];
	this.groups=[];
	this.group_length=[];
	this.controller=document.createElement("DIV");
	this.controller.style.display="none";
	
	this.total_price=document.createElement("DIV");
	this.controller.appendChild(this.total_price);
	this.total_price.className="registration_block registration_total_price";
	
	var company=document.createElement("DIV");
	this.controller.appendChild(company);
	company.className="registration_block";
	var title=document.createElement("H2");
	title.innerHTML="Company Information [optional]";
	company.appendChild(title);
	this.controller_form=new registration_form(null, null, this);
	company.appendChild(this.controller_form.form_element());
	
	var submit_block=document.createElement("DIV");
	this.controller.appendChild(submit_block);
	submit_block.className="registration_block";
	
	var agreement=document.createElement("DIV");
	agreement.className="registration_agreement";
	agreement.innerHTML=agreement_text;
	submit_block.appendChild(agreement);
	
	this.legal_agree=document.createElement("INPUT");
	this.legal_agree.type="checkbox";
	this.legal_agree.id="legal_agree";
	submit_block.appendChild(this.legal_agree);
	
	this.la_label=document.createElement("LABEL");
	this.la_label.setAttribute("for","legal_agree");
	this.la_label.innerHTML="I agree to the above terms and conditions";
	submit_block.appendChild(this.la_label);
	
	var button=document.createElement("INPUT");
	button.type="button";
	button.className="registration_button";
	button.controller=this;
	button.value="Submit";
	button.onclick=function() {
		if (this.controller.submit()!=false) this.value="contacting secure server...";
		}
	submit_block.appendChild(button);
	
	field.parentNode.parentNode.appendChild(this.controller);
	this.add_form=function(type, date) {
		r_links.hide();
		var group = type.oid + '_' + date.oid;
		if (!this.group_length[group]) this.group_length[group]=[];
		var max=parseInt(date.maximum)!=0?date.maximum:type.maximum;
		if (this.total_active(group)==max) alert("A maximum of " + max + " students can be registered for this class at one time, for more information please contact Bellissimo directly.")
		else {
			var form=new registration_form(type, date, this);
			this.forms.push(form);
			this.group_length[group].push(form);
			var from=new Date(parseInt(date.from)*1000);
			var to=new Date(parseInt(date.to)*1000);
			var block=new registration_block(type.title + ' (' + (from.getMonth()+1) + '/' + from.getDate() + '/' + from.getFullYear() + ' - ' + (to.getMonth()+1) + '/' + to.getDate() + '/' + to.getFullYear() + ')', form);
			if (!this.groups[group]) {
				this.groups[group]=document.createElement("DIV");
				field.appendChild(this.groups[group]);
				}
			this.groups[group].appendChild(block.block_element());
			}
		this.update_forms(type,date);
		}
	this.update_forms=function(type,date) {
		var group = type.oid + '_' + date.oid;
		var total_forms=0;
		var total_price=0;
		for (var group in this.group_length) {
			total_forms+=this.total_active(group);
			var passed=1;
			for (var n in this.group_length[group]) if (this.group_length[group][n].active) {
				if (type.required!=0 && passed>=type.required && this.total_active(group)>=type.required) this.group_length[group][n].full_price.innerHTML=type.volume;
				else this.group_length[group][n].full_price.innerHTML=type.cost;
				passed++;
				}
			if (this.total_active(group)==type.maximum) for (var n in this.group_length[group]) this.group_length[group][n].register_button.style.visibility="hidden";
			else for (var n in this.group_length[group]) this.group_length[group][n].register_button.style.visibility="visible";
			for (var n in this.group_length[group]) if (this.group_length[group][n].active==true) total_price+=parseInt(this.group_length[group][n].price());
			}
		this.total_price.innerHTML="Total cost for registering the student"+(total_forms>1?"s":"")+" above: $"+total_price;
		if (total_forms==0) {
			this.controller.style.display="none";
			r_links.show();
			}
		else {
			this.controller.style.display="block";
			}
		}
	this.total_active=function(group) {
		var length=0;
		for (var n in this.group_length[group]) if (this.group_length[group][n].active) length++;
		return length;
		}
	this.validate=function() {
		var error=false;
		if (this.legal_agree.checked==false) {
			this.la_label.style.color="#c00";
			error=true;
			}
		else this.la_label.style.color="#363f40";
		for (var n in this.forms) if (this.forms[n].active) {
			if (this.forms[n].validate()) error=true;
			}
		return error;
		}
	this.submit=function() {
		var invalid=this.validate();
		if (invalid) {
			alert("There was an error submitting your form, please enter a value in all of the highlighted fields to continue.");
			return false;
			}
		var data={'students':[],'company':this.controller_form.values()};
		for (var n in this.forms) if (this.forms[n].active) {
			data.students.push(this.forms[n].values());
			}
		ajax_send_a('register/ajax',data,this.proceed)
		}
	this.proceed=function(ajax) {
		top.location.href=ajax.responseText;
		}
	}
	
function registration_block(title, form) {
	this.block_element=function() {
		var block=document.createElement("DIV");
		this.content=block;
		block.className="registration_block";
		var close=document.createElement("DIV");
		close.innerHTML="x";
		close.block=this
		close.className="registration_close";
		close.onclick=function() {
			//if (confirm("Are you sure you want to remove this registration form? This action cannot be undone.")==false) return;
			this.block.remove();
			}
		block.appendChild(close);
		var block_title=document.createElement("H2");
		block_title.innerHTML=title;
		block.appendChild(block_title);
		block.appendChild(form.form_element());
		clear=document.createElement("DIV");
		clear.className="clear";
		block.appendChild(clear);
		return block;
		}
	this.remove=function() {
		this.content.style.display="none";
		form.remove();
		}
	}
	
function registration_form(type, date, controller) {
	this.active=true;
	this.full_price=document.createElement("SPAN");
	if (type) this.full_price.innerHTML=type.cost;
	this.fields=[];
	this.labels=[]
	this.form_element=function() {
		var div=document.createElement("DIV");
		var inputs=["name","address","city","state","zip","phone","email"];
		for (var n in inputs) {
			var form_row=document.createElement("DIV");
			form_row.className='registration_input_' + inputs[n];
			var id=parseInt(Math.random()*10000)
			var label=document.createElement("LABEL");
			this.labels[inputs[n]]=label;
			label.setAttribute('for',id);
			label.innerHTML=inputs[n];
			form_row.appendChild(label);
			var input=document.createElement("INPUT");
			input.type="text";
			input.id=id;
			this.fields[inputs[n]]=input;
			form_row.appendChild(input);
			div.appendChild(form_row);
			}
		if (type) {
			var form_row=document.createElement("DIV");
			form_row.className='registration_input_pay';
			var id=parseInt(Math.random()*100000);
			var name=parseInt(Math.random()*100000);
			var input=document.createElement("INPUT");
			input.type="radio";
			input.id=id;
			input.name=name
			input.form_obj=this;
			input.onclick=function() {
				this.form_obj.fields['pay_deposit'].checked=false;
				this.checked=true;
				this.form_obj.update_forms();
				}
			this.fields['pay_in_full']=input;
			form_row.appendChild(input);
			var label=document.createElement("LABEL");
			label.setAttribute('for',id);
			label.innerHTML='Pay in full ($';
			label.appendChild(this.full_price);
			var cp=document.createElement("SPAN");
			cp.innerHTML=")";
			label.appendChild(cp);
			form_row.appendChild(label);
			var id=parseInt(Math.random()*100000)
			var input=document.createElement("INPUT");
			input.type="radio";
			input.id=id;
			input.name=name
			input.form_obj=this;
			input.onclick=function() {
				this.form_obj.fields['pay_in_full'].checked=false;
				this.checked=true;
				this.form_obj.update_forms();
				}
			setTimeout('document.getElementById("'+id+'").onclick()', 0);
			this.fields['pay_deposit']=input;
			form_row.appendChild(input);
			var label=document.createElement("LABEL");
			label.setAttribute('for',id);
			label.innerHTML='Pay deposit ($' + (date.deposit!=0? date.deposit:type.deposit) + ')';;
			form_row.appendChild(label);
			div.appendChild(form_row);
			
			var register=document.createElement("DIV");
			this.register_button=register;
			register.controller=controller;
			register.form_obj=this;
			register.onclick=function() {
				this.form_obj.add_form();
				}
			register.innerHTML="register another student";
			register.className="registration_another";
			div.appendChild(register);
			}
		else {
			var clear=document.createElement("DIV");
			clear.className="clear";
			div.appendChild(clear);
			}
		return div;
		}
	this.update_forms=function() {
		controller.update_forms(type,date);
		}
	this.add_form=function() {
		controller.add_form(type,date);
		}
	this.price=function() {
		if (this.fields['pay_deposit'].checked==true) return type.deposit;
		else return this.full_price.innerHTML;
		}
	this.validate=function() {
		var error=false;
		for (var n in this.fields) if (this.labels[n]) {
			if (this.fields[n].value=="") {
				error=true;
				this.labels[n].style.color="#c00";
				}
			else this.labels[n].style.color="#363f40";
			}
		return error;
		}
	this.values=function() {
		var values={};
		for (var n in this.fields) if (this.labels[n]) {
			values[n]=this.fields[n].value;
			}
		if (date) values['class']=date.oid;
		if (this.fields['pay_deposit']) values.payed=this.price();
		return values;
		}
	this.remove=function() {
		this.active=false;
		controller.update_forms(type,date);
		}
	}
