window.onload = function(){
	
	/* get proxy from ibm */
	sp.getProxy();
	
	/* set service values */
	sp.setServiceParams();
	
	/* if coming from scedule id link */
	var sSchedId = GetQueryString()["schedid"];
	var test = new String(location.href);
    if (sSchedId) {
      sp.$('part_id').value = sSchedId;  
	}
	
	/* set click events for the submit buttons */
	sp.$('join_submit').onclick = sp.validate_part;
	sp.$('host_submit').onclick = sp.validate_mod;
	
	/* kill the autocomplete on passcodes */
	sp.$('part_id').setAttribute("autocomplete","off");
	sp.$('host_id').setAttribute("autocomplete","off");
	sp.$('host_pin').setAttribute("autocomplete","off");
	
	sp.$('part_id').focus();
}
sp = {
	
	params: {
		customer: 'SPE',
		brand: 'SoundpathEMEA',
		mod_form_action: 'https://www.conferenceservers.com/webagent/webagent.asp?',
		part_form_action: 'https://www.conferenceservers.com/meetme/meetme.asp?'
	},

	getProxy: function(){
		sp.$('join_proxy').value = sp.$('host_proxy').value = get_proxy();
	},
	
	setServiceParams: function(){
		sp.$('join_spcode').value = sp.$('host_spcode').value =  sp.params.customer;
		sp.$('join_brand').value = sp.$('host_brand').value = sp.params.brand;
		sp.$('hostform').action = sp.params.mod_form_action;
		sp.$('joinform').action = sp.params.part_form_action;
	},
	
	/* these should be the same name as the respective elements id */
	required: {
		participant: {
			part_id:true,
			part_name:true,
			part_company:false,
			part_email:false	
		},
		moderator: {
			host_id:true,
			host_pin:true,
			host_name:true,
			host_company:false,
			host_email:false			
		}
	},
	
	validate_part: function(event){
		if(!event) var event = window.event;
	
		if (event.preventDefault) {
			event.preventDefault();
		} else {
			event.cancelBubble = true;
			event.returnValue = false;
		}
		
		/* get rid of any spaces in the passcodes - for left and right trim */
		sp.$('part_id').value = sp.$('part_id').value.replace(/^\s+|\s+$/g,"");
		
		
		var pass=true;
		var count=0;
		var error_text = "Please fill out the required information:\r\n";

		var reqs = sp.required.participant;

		for(var k in reqs){
			if((reqs[k])&&(sp.$(k).value.length==0)){
				pass=false;
				error_text += ++count+". "+sp.$(k).title+"\r\n";
			}
		}

		if(pass){
			sp.$('joinform').submit();
		}else{
			alert(error_text);
		}
	},

	validate_mod: function(event){
		if(!event) var event = window.event;

		if(event.preventDefault){
			event.preventDefault();
		}else{
			event.cancelBubble = true;
			event.returnValue = false;
		}

		/* get rid of any spaces in the passcodes */
		sp.$('host_id').value = sp.$('host_id').value.replace(/ /g,''); 
		var pass=true;
		var count=0;
		var error_text = "Please fill out the required information:\r\n";

		var reqs = sp.required.moderator;
		var len = reqs.length;

		for(var k in reqs){
			if((reqs[k])&&(sp.$(k).value.length==0)){
				pass=false;
				error_text += ++count+". "+sp.$(k).title+"\r\n";
			}
		}

		if(pass) sp.$('hostform').submit();
		else alert(error_text);
	},

	$: function(id){
		return document.getElementById(id);
	}
}
