var ewd_domain = 'http://www.promolagi.com/'; //set domain URL
var ewd_loading_img = ewd_domain + 'img/loading.gif';//set image path
var ewd_loading_msg = '<b> Loading Data...</b>';//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;
}
//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);
}

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

//functions for posted values from forms via 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);
}

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;
}