// Assoc functions
// Author: Erik Smith erik@pdgcreative.com


// Popup Box
function popurl(url,w,h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = 710,top = 425');");
}





// New implementation of saving att with multiple groups, by erik

function remove_assoc(id, entry, type)
	{
				
		document.getElementById("id_"+id).style.display = "none";
		
		loadurlMore('../../../../delete_att.php?id='+id+'&entry='+entry+'&type='+type)
	
	}
	
	
function remove_assoc2(id, entry, type)
	{
				
		document.getElementById("idG_"+id).style.display = "none";
		
		loadurlMore('../../../../delete_att_group.php?id2='+id+'&entry2='+entry+'&type2='+type)
	
	}
	
	
	
	// Itin Functions


		
	
function add_itin(Table, EID, IDN) 
	{
			var type = "Itin";
			document.getElementById('add').href = 'itinerary.php';
			document.getElementById('add').onclick = '';
			loadurlMore('handle.php?Table='+Table+'&EID='+EID+'&type='+type+'&IDN='+IDN+'&add=true');	
	}
	
	function updateItin()
		{
			loadurl_noc('handle.php?type=itin_order&'+Sortable.serialize('itinerary'));
		}
	
function createSortables() {
	Sortable.create("itinerary", {tag:'li',overlap:'verticle',constraint: false, onChange:updateItin})
}

function remove_itin_item(id,table,title)
	{
		var c = confirm("Are you sure you would like to remove "+title+" from your itinerary?");
		
			if(c == true){
				var type = 'removeitin';
				document.getElementById('item_'+id).style.display = "none";
				loadurl("handle.php?type="+type+"&id="+id+'&table='+table);
				window.location = "itinerary.php";
				return true;
			} else
					return false;
	}








 var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } 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('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var poststr = "tmp="+ encodeURI( document.getElementById("tmp").value) + "&id="+ encodeURI( document.getElementById("ID").value) + "&primary=" + encodeURI( document.getElementById("PrimaryCategory").value ) +
                    "&secondary=" + encodeURI( document.getElementById("SecondaryCategory").value );
      makePOSTRequest('../save_att.php', poststr);
      
      p = document.getElementById("PrimaryCategory").value;
      
      if(p == 3) {
			document.getElementById('booknow').style.display = "block";
		} 
		
		if(p == 5) {
			document.getElementById('diningleg').style.display = "block";
		} 
      
   }








 var http_request2 = false;
   function makePOSTRequest2(url2, parameters2) {
      http_request2 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request2 = new XMLHttpRequest();
         if (http_request2.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request2.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request2 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request2 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request2) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request2.onreadystatechange = alertContents2;
      http_request2.open('POST', url2, true);
      http_request2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request2.setRequestHeader("Content-length", parameters2.length);
      http_request2.setRequestHeader("Connection", "close");
      http_request2.send(parameters2);
   }

   function alertContents2() {
   		
      if (http_request2.readyState == 4) {
         if (http_request2.status == 200) {
            //alert(http_request.responseText);
            result2 = http_request2.responseText;
            document.getElementById('myspan2').innerHTML = result2;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get2(obj) {
      var poststr2 = "tmp2="+ encodeURI( document.getElementById("tmp2").value) + "&id2="+ encodeURI( document.getElementById("ID2").value) + "&primary2=" + encodeURI( document.getElementById("PrimaryCategory2").value ) +
                    "&secondary2=" + encodeURI( document.getElementById("SecondaryCategory").value );
      makePOSTRequest2('../save_att_groups.php', poststr2);
   }




// Ajax Request
function loadurl(url){	
	var content = document.getElementById('output');
	var callback = {
		success : function(o) {
			content.innerHTML = o.responseText;
		},
		failure : function(o) {
			content.innerHTML = " ";
		}
	}
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url, callback); 

}


// Ajax Request
function loadurl_noc(url){	
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url); 

}

	
	
	// Ajax Request 3
function loadurl3(url) { 
	var content = document.getElementById('output2');
	var callback = {
		success : function(o) {
			content.innerHTML = o.responseText;
		},
		failure : function(o) {
			content.innerHTML = " ";
		}
	}
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url, callback);  
	} 

	
	

// Secondary Ajax Request	
function loadurlMore(url) { 
	var content = document.getElementById('add');
	var callback = {
		success : function(o) {
			content.innerHTML = o.responseText;
		},
		failure : function(o) {
			content.innerHTML = " ";
		}
	}
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url, callback); 
	}
	


// Get inputs, selected, ect
function get_selected(id)
	{
	
	var get = document.getElementById(id);
	var out = get.options[get.selectedIndex].value;
	return out;
	
	}

function get_input(id)
	{
	
	var get = document.getElementById(id);
	var out = get.value;
	return out;
	
	}
	
function get_html(id)
	{
	
	var get = document.getElementById(id);
	var out = get.innerHTML;
	return out;
	
	}
	

function do_redirect()
	{
		location.href = get_selected('main');
	}
	

	
	
// Front End , Read More | Read Less
function read_more(type, id)
	{
		document.getElementById('blurbs').style.display = "none";
		document.getElementById('readmore').style.display = "block";
		loadurlMore("handle-more.php?type="+type+"&id="+id);
	}
	
function read_less(type, id)
	{
		document.getElementById('blurbs').style.display = "block";
		document.getElementById('readmore').style.display = "none";
	}
	

	
// Sort By...
function bycat()
	{
		var cat = get_selected('category');
		var type = get_input('type');
		var p = get_input('primary');
		document.getElementById('q').value = '';
		
		
		loadurl("handle.php?type="+type+"&c="+cat+"&p="+p+"&all=false");
	}
	
	
		
// Sort By...
function bypara(para)
	{
	
		var cat = get_selected('category');
		var type = get_input('type');
		var p = get_input('primary');
		document.getElementById('q').value = '';
				
		loadurl("handle.php?type="+type+"&c="+cat+"&p="+p+"&all=false&para="+para);
	}
	
	
function loadall()
	{
		var cat = get_selected('category');
		var type = get_input('type');
		var p = get_input('primary');

		loadurl("handle.php?type="+type+"&c="+cat+"&p="+p+"&all=true");
	}
	
function bycat_skip(start)
	{
	
		var cat = get_selected('category');
		var type = get_input('type');
		var q = get_input('q');
		var p = get_input('primary');

		loadurl("handle.php?type="+type+"&c="+cat+"&p="+p+"&start="+start+"&q="+q);
	}
	
	function byevent_skip(start)
	{
	
		var type = "events";
		var month = get_selected('month');
		var year = get_selected('year');

		loadurl("handle.php?type="+type+"&month="+month+"&year="+year+"&start="+start);
	}
	
	
function search_skip(a)
	{
		var type = 'search';
		var start = a;
		loadurl("handle-search.php?type="+type+"&start="+start);
	
	}
	
function bydate()
	{
		var month = get_selected('month');
		var year = get_selected('year');
		var type = get_input('type');
		document.getElementById('q').value = '';
		
		loadurl("handle.php?type="+type+"&month="+month+"&year="+year);
	}	

function bykeyword()
	{
		var q = get_input('q');
		var p = get_input('p');
		var type = get_input('type');
				
		loadurl("handle.php?type="+type+"&q="+q+"&p="+p);
	}
	
	
function bygallery()
	{
		var id = get_selected('category');
		var type = get_input('type');

		loadurl("handle.php?type="+type+"&gallery="+id);
}
	
	function bygallery_keyword()
	{
		var id = get_selected('category');
		var q = get_input('q');
		var type = get_input('type');
		
		loadurl("handle.php?type="+type+"&q="+q+"&gallery="+id);
		
	}
	
	
	function bygallery_getBig(pass)
		{
			document.getElementById('gallery_main_pic').src = pass;
		}
		
		

// Clear an input content		
function input_clear(id)
{
	document.getElementById(id).value = ""
	document.getElementById(id).style.color = "#000";
	document.getElementById(id).onclick = "";
}



// Backend, secondary Show
function secondary_att()
	{
		var type = 'forAtt';
		var p = get_selected('PrimaryCategory');
		var s = get_input('Secondary');
		
				
		loadurl("../../../../handle.php?type="+type+"&p="+p+"&s="+s);	
	}
	
function secondary_group_att()
	{
		
		var type = 'forAtt';
		var forthis = 'forPlan';
		var p = get_selected('PrimaryCategory2');
		var s = get_input('Secondary2');	
								
		loadurl3("../../../../handle.php?type="+type+"&p="+p+"&forthis="+forthis+"&s="+s);	
	}
	



function search()
	{
		var search = get_input('q');
		var type = 'search';

		loadurl("handle-search.php?type="+type+"&q="+search);
	
	}
	
	




// Maps


function save_address()
	{
		var save = get_input('address');
		var type = 'saveaddress';
		
		GUnload()
		onLoad();
		document.getElementById('addaddress').style.display = "none";
		
		loadurl("handle.php?type="+type+"&address="+save);
	
	}

function pop_map(a)
{
	var address = get_input(a);
	var en = escape(address);
	popurl('/maps.php?address='+en, '500px', '330px');

}

function pop_address(a)
{
	var en = escape(a);
	popurl('maps.php?address='+en, '500px', '330px');
}

function pop_dir(b,a)
{
	var address = escape(a);
	var dest = escape(b);
	popurl('maps-get-directions.php?address='+address+'&dest='+dest, '500px', '330px');
}

function pop_map_front(a)
{
	var address = get_html(a);
	var en = escape(address);
	popurl('/maps.php?address='+en, '500px', '330px');

}


// show secondary list of categories

function show_secondary(pre, top)
	{
		
		var type = '2';		
		var p = get_selected('PrimaryCategory');
				
		if(top != "top")
			var show_att = "true";
		else
			var show_att = "false";
	
		if(pre == "true"){
			var s = get_input('Secondary');	
		} 
			else {
				var s = get_selected('SecondaryCategory');	
			}
			
			var a = get_input("Att");
		
		loadurl("../../../../handle.php?type="+type+"&p="+p+"&s="+s+"&show_att="+show_att+"&a="+a);
		
	}

	









// print this page

function print_page(Table)
	{
		location.href = "print.php?Table="+Table;
	}











