/*
var ewd_domain = 'http://www.schweser.com/help/'; //set domain
var ewd_loading_img = ewd_domain + 'images/loading.gif';//set image path
var ewd_loading_msg = '<strong>Processing Data…</strong>';//set loading message
*/
var xmlhttp_obj = false;      

//create the XMLHttpRequest
function ewd_xmlhttp(){
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		xmlhttp_obj = new XMLHttpRequest();
	}else if (window.ActiveXObject){ // if IE
		try{
			xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				
			}
		}    
		
	} else {
		xmlhttp_obj = false;
	}
	
	return xmlhttp_obj;
}    

function ewd_loadpage(xmlhttp_obj, content, containerid){
	if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 ){
		document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
	}
}      


// GET sending methods START ------------------------------------------------------------------------------------
//get content via GET
function ewd_getcontent(url, containerid){
	var xmlhttp_obj = ewd_xmlhttp();
	
//	document.getElementById(containerid).innerHTML = '<img src="' + ewd_loading_img + '" />' + ewd_loading_msg;
	xmlhttp_obj.onreadystatechange=function(){
		ewd_loadpage(xmlhttp_obj, '', containerid);
	}
	
	xmlhttp_obj.open('GET', url, true);
	xmlhttp_obj.send(null);
}      
// GET sending methods END --------------------------------------------------------------------------------------


// POST sending methods START -----------------------------------------------------------------------------------
//functions for posted values from forms vis POST
function ewd_getcontent_post(url, content, containerid){
	var xinput = content;
	var xmlhttp_obj = ewd_xmlhttp();
	
//	document.getElementById(containerid).innerHTML = '<img src="' + ewd_loading_img + '" />' + ewd_loading_msg;
	
	xmlhttp_obj.open('POST', url, true);
	xmlhttp_obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	xmlhttp_obj.onreadystatechange = function() {
		ewd_loadpage(xmlhttp_obj, content, containerid);
	}
	
	xmlhttp_obj.send(content);
}

//convert form data sent to POST CONTENT
function ewd_submit_form(page_to,form_name,containerid) {
	var content = ewd_convertFormDataToPostContent(form_name);
	ewd_getcontent_post(page_to, content, containerid);
}

//convert field data sent to POST CONTENT
function ewd_submit_field(page_to,field_name,containerid) {
	var content = ewd_convertFieldDataToPostContent(field_name);
	
	if (field_name == "validate_required_none_examErr"){
		// displays none onchange
		document.getElementById('key_row').style.display = 'none';
	}
	
	ewd_getcontent_post(page_to, content, containerid);
}

function ewd_convertFieldDataToPostContent(fieldID){
	// Loosly based on function below
	var form_element = document.getElementById(fieldID);
	// Made for DDL
	var content_to_submit = '';
	
	content_to_submit = form_element.name + '=' + escape(form_element.value);
	
	return content_to_submit;
}

function ewd_convertFormDataToPostContent(form_y){
	var f=document.getElementById(form_y);
	var content_to_submit = '';
	var form_element;
	var last_element_name = '';
	
	for (i = 0; i < f.elements.length; i++){
		form_element = f.elements[i];
		
		switch (form_element.type){
			// text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				content_to_submit += form_element.name + '=' + escape(form_element.value) + '&';
				break;
				
			// radio buttons
			case 'radio':
				if (form_element.checked){
					content_to_submit += form_element.name + '=' + escape(form_element.value) + '&';
				}
				break;
				
			// checkboxes
			case 'checkbox':
				if (form_element.checked){
					// Continuing multiple, same-name checkboxes
					if (form_element.name == last_element_name) {
						// Strip of end ampersand if there is one
						if (content_to_submit.lastIndexOf('&') == content_to_submit.length - 1){
							content_to_submit = content_to_submit.substr(0, content_to_submit.length - 1);
						}
						// Append value as comma-delimited string
						content_to_submit += ',' + escape(form_element.value);
					} else {
						content_to_submit += form_element.name + '=' + escape(form_element.value);
					}
					content_to_submit += '&';
					last_element_name = form_element.name;
				}
				break;
		}//end switch
	} //end for
	
	// remove trailing separator
	content_to_submit = content_to_submit.substr(0, content_to_submit.length - 1);
	
	return content_to_submit;
}
// POST sending methods END -------------------------------------------------------------------------------------
