function makeRequest(w, url) {

	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Sorry, Your browser is not supported');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(w, http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);

}

function NewElement(SrcTxt, AddtoObject){
	var newele;
	var txt;	
	arr2=SrcTxt.split("|");
	 newele=document.createElement("option") ;
	 txt=document.createTextNode(arr2[1]);
	 newele.setAttribute("value",arr2[0]);	 
	 newele.appendChild(txt);
	AddtoObject.appendChild (newele);
}

function alertContents(w, http_request) {

	if (http_request.readyState == 4) {

		if (http_request.status == 200){

			var str=http_request.responseText;

			arr= str.split ("<br>");			
			if (w==1) { //  Set Schools, State was changed
				// Clear the Schools List
				for (i=document.Frm.SchoolId.options.length; i>=0; i --)  
					document.Frm.SchoolId.options[i]=null;		
				//Populate the list now
				NewElement("0|Please select...",document.Frm.SchoolId);					
				for (i=0; i<arr.length-1; i++){					
					NewElement(arr[i],document.Frm.SchoolId);
				}			
				NewElement("-99|Other school...",document.Frm.SchoolId);					
			}
			else if (w==2) {//  Set States, Country was changed, Clear schools
				// Clear the Schools List
				for (i=document.Frm.SchoolId.options.length; i>=0; i --)  
					document.Frm.SchoolId.options[i]=null;		
				// Clear states
				for (i=document.Frm.StateId.options.length; i>=0; i --)
					document.Frm.StateId.options[i]=null;								
				// Only one school item		
				NewElement("0|Please select state/province...",document.Frm.SchoolId);					
				// Populate States
				NewElement("0|Please select...",document.Frm.StateId);					
				for (i=0; i<arr.length-1; i++){
					NewElement(arr[i],document.Frm.StateId);
				}
			}				
			else if (w==3) { // Set Billing States, billing country was changes 
				
				for (i=document.Frm.BillingStateId.options.length; i>=0; i --)
					document.Frm.BillingStateId.options[i]=null;		
				NewElement("0|Please select...",document.Frm.BillingStateId);					
				for (i=0; i<arr.length-1; i++){
					NewElement(arr[i],document.Frm.BillingStateId);
				}
			}
			else if (w==4) {	

				if (http_request.responseText=="NV"){
					alert("You entered an invalid discount code or your code has been already used, please try again");
					document.Frm.BtnChkCoupon.disabled=false;				
					document.Frm.txtDiscCode.focus();
				}
				else{
					alert("Code valid, the price will reflect your discount");
					SetPrice(true);
					document.Frm.txtDiscCode.disabled=true; 
					document.Frm.BtnChkCoupon.disabled=true; 
					discount=10
					SetPrice();
				}
				document.Frm.BtnSubmit.disabled=false;
			}
			else if (w==5) {
				if (http_request.responseText=="NV"){
					alert("You entered an invalid discount code or your code has been already used, please try again");
					document.Frm.BtnChkCoupon.disabled=false;				
					document.Frm.txtDiscCode.focus();
				}
				else{
					alert("Code valid, the price will reflect your discount");
					SetDiscPrice();
					document.Frm.txtDiscCode.disabled=true; 
					document.Frm.BtnChkCoupon.disabled=true; 
				}
			}		

			else if (w==6) { 			// Lookup username 
				if (str=="UserHasAccess") {
					HideElement('LblUserHasAccess',0)			
					
				}
				else if (str=="UserFound") {
					HideElement('LblUserFound',0)		
					HideElement('LblPwd',0)
					HideElement('CurrPwd',0)
					HideElement('BtnContinuePwd',0)		
					document.Frm.CurrPwd.focus();
					HideElement('BtnContinue',1);
					document.Frm.UserName.value=document.Frm.Email.value
					document.Frm.Email.disabled=true;				
				

				}
				else {											
					HideElement('LblUserNotFound',0)		
					HideElement('LblConfEmail',0)		
					HideElement('ConfEmail',0)
					HideElement('LblNewPwd',0)		
					HideElement('NewPwd',0)		
					HideElement('LblConfPwd',0)		
					HideElement('ConfPwd',0)	
					HideElement('BtnContinueNewUser',0)																			
					HideElement('BtnContinuePwd',1)											
					document.Frm.ConfEmail.focus();
					HideElement('BtnContinue',1);
					document.Frm.UserName.value=document.Frm.Email.value					
					document.Frm.Email.disabled=true;				

				}
	
			}
			else if(w==7) {	// Lookup password

				if (str.substring(0,5)=="PwdOk"){			
					HideElement('LblName',0)	
					HideElement('Name',0)					
					HideElement('LblSchoolTitle',0)	
					HideElement('LblSchoolId',0)
					HideElement('SchoolId',0)
					HideElement('LblCountryId',0)
					HideElement('CountryId',0)
					HideElement('LblStateId',0)
					HideElement('StateId',0)

					if (document.Frm.IsByChapter.value=='True') {		
						arr=str.substring(str.indexOf('chapters')+9).split(",")						
						for (i=0;i<arr.length;i++){
							for (j=0; j<document.Frm.Chp.length; j++){
								if (document.Frm.Chp[j].value==arr[i]){
									document.Frm.Chp[j].disabled=true
								}	
							}
						}
						SetPrice();
					}
					HideElement('BtnCancel',0)			
					HideElement('BtnSubmit',0)						
					HideElement('BtnContinuePwd',1)		
					document.Frm.Pwd.value=document.Frm.CurrPwd.value;
					document.Frm.CurrPwd.disabled=true;					

				}
				else {
					HideElement('LblPwdError',0)
				}		
			}
			
			
		}
		
	}
}
function $() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];

        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}

function HideElement( element, mode ) {
    var e = $(element);

    if (e) {
        e.style.display = ((mode==0) ? 'inline' : 'none');
        
    }
}


function IsElementHidden( element) {
    var e = $(element);

    if (e) {
		if (e.style.display =='none')
			return true
		else
			return false
        
    }
}
