function test() {
  alert('im in ur codez!');
}
function loading() {
	return '<div class="loading"><span>Loading...</span></div>';
}
jQuery.fn.fadeThenSlideToggle = function(speed, easing, callback) {
  if (this.is(":hidden")) {
    return this.slideDown(speed, easing).fadeTo(speed, 1, easing, callback);
  } else {
    return this.fadeTo(speed, 0, easing).slideUp(speed, easing, callback);
  }
};
// set the function to retrieve views w/ params
function callback( page ) {
	// Online Interview view
	if ( page=="online-interview" )
		jQuery.get('/wp-content/plugins/proscout/views/no-results.php', function(html) {
			jQuery("#open-call-container").fadeIn('slow').html(html)
		});	
	// Temp 	
	else if  ( page=="0" )
		test();
	// final error just in case
	else
		alert('oh noz!')
	return;
}	

// Builds the list page
jQuery(document.body).ready(function() {
	jQuery('#open-call').show();	
	jQuery("#getData").click(function(){
	// Display the loading section while the div is empty		
	jQuery("#open-call-container").empty().html(loading());
	var data = "";
	// make the form value a variable
	var address = jQuery('#open-call-addressInput').val();
		// retrieve the xml with the zip variable
		jQuery.get("/wp-content/plugins/proscout/resources/proxy.php?url=getlist.cfm?zip=" + address , function(theXML){
				// check to see if the response is null
				if(jQuery("rec",theXML).text() === "") {
					jQuery('#open-call').fadeThenSlideToggle();
  					callback('online-interview');
				}
				// continue on	
				else
				var head = "<h3 class=\"int-local\">Interview Locations In Your Area</h3>\
						<span class=\"int-local\"><span>You entered zip code "+address+"</span><ul>"
				
				var foot = "<li></li>\
                            </ul>\
				<span id=\"open-call-footnote\">&#42; Select the nearest location to view directions and session times</span>"
				
			
				
				// parse out the xml
				jQuery('rec',theXML).each(function(i){
					var city 		= jQuery(this).find("city").text();
					var eventid 	= jQuery(this).find("eventid").text();
					var eventstart 	= jQuery(this).find("formateddate").text();
					data = data + "<li><a href=\"?eventID=" + eventid + " \"> " + eventstart + ", " + city + " (ProScout)</a></li>";
					// fade out the form since it's not longer needed
					jQuery('#open-call').fadeThenSlideToggle();
				});
				jQuery("#open-call-container").html(head+data+foot);
		});
	});	
});	

// Builds the Event Page
jQuery("#getData").ready(function(){
	// Set the url param as a var
    var param = jQuery(document).getUrlParam('eventID');	
	// Continue only if this is an eventID page
	if (param==null)
	return;
	else
	// hide everything that a event page doesn't need
	jQuery('#open-call,#open-call-container').hide();
	// Display the loading section while the div is empty
	jQuery("#open-call-event-container").empty().html(loading());

	var eventdata = "";
		
		// retrieve the xml with the zip variable
		jQuery.get("/wp-content/plugins/proscout/resources/proxy.php?url=getEvent.cfm?eventID=" + param , function(theXML){
		//jQuery.get("/wp-content/plugins/proscout/resources/test.xml" , function(theXML){		
				// check to see if the response is null
				if(jQuery("rec",theXML).text() == "") { alert('Oh noz!!!') } else;
				
				var ehead = "<h3>Your Interview Location</h3>\
							<p>Below is your requested interview location. Get tips for how to prepare for your interview by selecting the button at the bottom.</p>"
				var efoot = "	<div class=\"oc-box\">\
								<div id=\"start-online-int\"><a href=\"?email=" + param + "\" title=\"Choose this location\">Prepare for this interview</a></div>\
							</div>"
				// parse out the xml
				jQuery('rec',theXML).each(function(){
				
					//var title 	= $(this).find("address").attr("title");
					var eventdate			= 	jQuery(this).find("formateddate").text();
					var address 			= 	jQuery(this).find("address").text();
					var city 				= 	jQuery(this).find("city").text();
					var state 				= 	jQuery(this).find("state").text();
					var zip 				= 	jQuery(this).find("zip").text();
					var eventid 			= 	jQuery(this).find("eventid").text();
					var eventname 			= 	jQuery(this).find("eventname").text();
					var locationname 		= 	jQuery(this).find("locationname").text();
					var roomname 			= 	jQuery(this).find("roomname").text();
					var scoutoneimage 		= 	jQuery(this).find("scoutoneimage").text();
					var scoutonelink 		= 	jQuery(this).find("scoutonelink").text();
					var scoutonename 		= 	jQuery(this).find("scoutonename").text();
					var scouttwoimage 		= 	jQuery(this).find("scouttwoimage").text();
					var scouttwolink 		= 	jQuery(this).find("scouttwolink").text();
					var scouttwoname 		= 	jQuery(this).find("scouttwoname").text();
					var sessiononetime		= 	jQuery(this).find("sessiononetime").text();
					var sessiononename 		= 	jQuery(this).find("sessiononename").text();
					var sessiontwotime		= 	jQuery(this).find("sessiontwotime").text();
					var sessiontwoname 		= 	jQuery(this).find("sessiontwoname").text();
					var sessionthreetime	= 	jQuery(this).find("sessionthreetime").text();
					var sessionthreename 	= 	jQuery(this).find("sessionthreename").text();
					
					eventdata = "<div class=\"event-data\"\
					\
					<strong>Interview Date</strong>\
					<p>"+ eventdate +"</p>\
					<strong>Event Name</strong>\
					<p>ProScout - "+ eventname +"</p>\
					<strong>Interview Location</strong>\
					<p>"+ locationname +"<br/>\
					"+ address +"<br/>\
					"+ city +", "+ state +" "+ zip +"</p>\
					<strong>Meeting Room</strong>\
					<p>"+ roomname +"</p>\
					<strong>Sessions</strong>\
					<p>"+ sessiononename +" "+ sessiononetime +"</p>\
					<p>"+ sessiontwoname +" "+ sessiontwotime +"</p>\
					<p>"+ sessionthreename +" "+ sessionthreetime +"</p>\
					<strong>Interview Fee</strong>\
					<p>Free. No appointment necessary.</p>\
					<strong>Contact ProScout</strong>\
					<p>Email: <a href=\"mailto:info@proscout.com\">info@proscout.com</a></p>\
					<p>Toll Free: 866-337-3281 </p>\
					<p>Website: <a href=\"http://www.proscout.com\">proscout.com</a></p>\
					</div>\
					<div id=\"maps-wrap\"><iframe width=\"100%\" height=\"400\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q="+ address +" "+ city +" "+ state +" "+ zip+"&amp;iwloc=A&amp;output=embed\"></iframe></div>\
					";
					
				});
				
				jQuery("#open-call-event-container").html(ehead+eventdata+efoot);
	
	});	
});	
// Builds the Event Page
jQuery("#getData").ready(function(){
	
	// Set the url param as a var
    var param = jQuery(document).getUrlParam('email');	
	// Continue only if this is an eventID page
	if (param==null)
	return;
	else
	
	// Display the loading section while the div is empty
	jQuery("#open-call-email-container").empty().html(loading());
	
	// hide everything that a event page doesn't need
	jQuery('#open-call,#open-call-event-container,#open-call-container,#email-confirmation').hide();
		
	jQuery.get('/wp-content/plugins/proscout/views/email.php', function(html) {
		jQuery("#open-call-email-container").html(html)
		
		jQuery("#open-call-submit").click(function(){
			jQuery('#open-call-email-wrap').fadeThenSlideToggle();
			jQuery('#open-call-email-confirmation').fadeIn('slow')
		});	
	});	
});	
jQuery.fn.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* 
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if (jQuery(this).attr("nodeName")=="#document") {
		//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if ($(this).attr("src")!="undefined") {
		
		var strHref = $(this).attr("src")
		if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
			qString = strQueryString.split("&");
		}
	  } else if ($(this).attr("href")!="undefined") {
		
		var strHref = $(this).attr("href")
		if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
			qString = strQueryString.split("&");
		}
	  } else {
		return null;
	  }
		
	  
	  if (qString==null) return null;
	  
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}
			
	  }
	  
	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});