// JavaScript Document
var ajaxAddItin = function(imgroot,recid,itype){
	initItin();
	ajaxAddItin(imgroot,recid,itype);
}

//Initialize the additin function to choose between jquery or prototye version
function initItin(){
	if(typeof(window['Ajax']) != 'undefined' && Ajax.Request){
		ajaxAddItin = ajaxAddItin_prototype;
	}
	else{
		ajaxAddItin = ajaxAddItin_jquery;
	}
}

//Handle Failures
function handlerFailure(response){
	alert('We were unable to comply with your requrest.  Please reload the page and try again');
}


/*Begin JQuery Functions*/

//JQuery version - do not call this version directly all calls should be made through ajaxAddITin
function ajaxAddItin_jquery(imgroot,recid,itype)
{
	var thisUrl  = imgroot+'/itinerary/ajaxAddItin.cfm';
	var thisData = 'type=' + itype + '&recid='+recid;
	
	$.ajax({
	   type: "POST",
	   url: thisUrl,
	   data: thisData,
	   success: function (response){
			if(itype == 1){
				$('#itin_' + recid).html('<span title="Added to Itinerary">Added to Itinerary</span>');
			}
		//Calendar
			else{
				$('#itin_' + recid).html('<span title="Added to Itinerary">Added to Itinerary</span>');
			}
			return true;
		},
	   failure: handlerFailure
	 });
}
/*End Jquery Functions*/


/*Begin Prototype Functions*/

//Prototype version - *****do not call this version directly all calls should be made through ajaxAddItin***
function ajaxAddItin_prototype(imgroot,recid,itype)
{
	var thisUrl  = imgroot+'/itinerary/ajaxAddItin.cfm';
	var thisData = 'type=' + itype + '&recid='+recid; 
	
	new Ajax.Request(thisUrl,{
		method: 'post',
		parameters: thisData,
		onSuccess: function (response){
			if(itype == 1){
				$P('itin_' + recid).innerHTML = ('<span title="Added to Itinerary">Added to Itinerary</span>');
			}
		//Calendar
			else{
				$P('itin_' + recid).innerHTML = ('<span title="Added to Itinerary">Added to Itinerary</span>');
			}
			return true;
		},
		onFailure: handlerFailure
 });
}
/*End Prototype Functions*/