// Global JavaScript Functions/Commands
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() {

	//document.getElementById(cont_div_is).innerHTML = "Loading...";	// Loading graphic..
	//numb = 0;
	//loading_action();
	
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			// What to do on successful return of data
			results = req.responseText
            xml_response_do(results)
        
		 } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.responseText);
         }
    }
}
function xml_response_do(results){
	
	// Membership Log from homepage
	if(xmlaction == "publicmemberlog"){
		if(results == "Thank you for logging in!"){
			alert(results);
		}else{
			alert(results);
			window.location.href = "http://www.jpking.com/index.asp?p=Members";
		}
	}
	
}









// Search Block/Submit Functions
function set_search(val,id){

	var sis = document.getElementById(id).value;
	var dis = "Search J.P.King...";
	if(val==1){	//focus
		document.getElementById(id).value = "";
	}
	if(val==0){ //blur
		if(sis==""){
			document.getElementById(id).value = dis;
		}
	}

}

function submit_search(){
	
	var sis = document.getElementById("sterm").value;
	if(sis == "Search J.P.King..." || sis == ""){
		alert("Please enter something to search for.");
	} else {
		window.location.href = "index.asp?p=Search&st="+sis;
	}

}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		submit_search();
	}
}


// Email Join/Submit functions
function set_member(val,id){

	var sis = document.getElementById(id).value;
	var dis = "Log In/Join (Email Address)...";
	if(val==1){	//focus
		document.getElementById(id).value = "";
	}
	if(val==0){ //blur
		if(sis==""){
			document.getElementById(id).value = dis;
		}
	}

}

function submit_member(){
	
	var sis = document.getElementById("mlog").value;
	if(sis == "Log In/Join (Email Address)..." || sis == ""){
		// Send to the membership page
		window.location.href = "http://www.jpking.com/index.asp?p=Members";
	} else {
		//Pop Alert to Log In
		var passwd = prompt('Please enter your password:','');
     	if (passwd){
			//alert('You are logging in as: \n'+sis+'\n'+passwd);
			// Log the user in
			xmlaction = "publicmemberlog";
			var urlis = "http://www.jpking.com/inc/member_login.asp?logmail="+sis+"&logpass="+passwd;
			loadXMLDoc(''+urlis+'');
			
		} else {
			//alert('You pressed Cancel or no value was entered!');
			window.location.href = "http://www.jpking.com/index.asp?p=Members";
		}
	}

}

function handleMEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		submit_member();
	}
}
