/******** Main Sub Links **********/
var xmlLead='<?xml version="1.0" encoding="iso-8859-1" ?>'
var outbound;

$(document).ready(function(){
 $('#mainNav li.subNav').hover(
 function() { $('ul', this).css('display', 'block'); },
 function() { $('ul', this).css('display', 'none'); });
});


$(document).ready(function(){
	$('a#allsubjects').click(function() {
		$('.searchBrowse').show();
		return false;
	});
	
	$('#submitLink').hover(function(){
		$('#btnSubmit').attr('src','images/btn_SubmitReq_f2.png');
	},function(){
		$('#btnSubmit').attr('src','images/btn_SubmitReq.png');
	});

	$('#submitLink').click(function(){
		if($("#reqForm").validate().form()){
			//build the XML to send
			var tdy=new Date();
			outbound='<Request type="conferenceUpdateRequest" reqDate="' + tdy.toString() + '">';
			outbound+='<fullName><![CDATA[' + $('#fName').val() + ']]></fullName>';
			outbound+='<orgName><![CDATA[' + $('#org').val() + ']]></orgName>';
			outbound+='<email><![CDATA[' + $('#email').val() + ']]></email>';
			outbound+='</Request>';
			jaxSend();
		}
	});
																	  
	$('#btnclose').click(function() {
		$('.searchBrowse').hide();
		return false;
	});
}); 

function responseError(reqObj, ajaxOptions, thrownError){
	if(reqObj.status == 200 && reqObj.statusText == "OK"){
		reqObj = (new DOMParser()).parseFromString(reqObj.responseText, "text/xml");
		handleResponse(reqObj);
	}else{
		alert(reqObj.status);
		alert(thrownError);
	}
}
			
function jaxSend(){
	var xmlDocument=xmlLead + outbound;
	$.ajax({
		url: "../gsLib/passData.aspx",
		processData: false,
		contentType: "text/xml",
		data: xmlDocument,
		type: "POST",
		dataType: "xml",
		success: handleResponse,
		error: responseError
	});
}

function handleResponse(reqObj){
	var root_node;
//	var	xmlObject=reqObj.responseXML;
//	if(xmlObject==null) xmlObject = (new DOMParser()).parseFromString(reqObj.responseText, "text/xml");
	root_node = $(reqObj).find("Response");
	var aType=root_node.attr("type");
	switch (aType){
		case "requestReceived":
			if(root_node.attr("status")=="success"){
				$('#requestForm').hide();
				$('#thankYou').show();
			}
			break;
		default:
			alert("unrecognized request: " + aType + "\n" + reqObj.responseText);
	}
}


