// JavaScript Document

// map popup
function map_popup(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 400,top = 192');");
	return false;
}


var defValues = {"firstname":"First Name","lastname":"Last Name",
	"email":"Email Address","email_confirm":"Confirm Email",
	"password":"Password","password_confirm":"Confirm",
	"username":"User Name", "name":"Your Name","message":"Your question",
	"captcha":"Enter the code"};

function setText(obj) {
	if (obj.value.length == 0) {
		obj.value = defValues[obj.id];
	}
	else if (obj.value == defValues[obj.id])
		obj.value = "";
}

function chkForm(obj) {
	obj.getElements("input").each(function(el) {
		if (defValues[el.id]!=undefined) {
			if (el.value == defValues[el.id])
				el.value = "";
		}
	});
}

window.addEvent("domready",function() {
	Cufon.now();
});

// START ITINERARY
function i_add(id,type) {
	// perform ajax request and update i_status
	new Request({
			 url: "/index.php", 
			 data: {"ajax":"i_add","id":id,"type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {
			 	if ($chk($('i_status_'+id)))
				 	$('i_status_'+id).innerHTML = responseText;
			 }
	}).send();
	return false;
}

function i_list_remove(id,type) {
	// perform ajax request and update i_status
	var url = '?ajax=i_list_remove&id='+id+'&type='+type;
	new Request({
			 url: "/index.php", 
			 data: {"ajax":"i_list_remove","id":id,"type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {
			 	$('i_listing').innerHTML = responseText;
			 }
	}).send();
	return false;
}

function i_shortlist_remove(id,type) {
	// perform ajax request and update i_status
	new Request({
			 url:"/index.php",
			 data: {"ajax":"i_shortlist_remove","id":id,"type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {$('i_listing').innerHTML = responseText;}
	}).send();
	
	// update the map now
	new Request({
			url:"/index.php",
			data: {"ajax":"i_map_refresh"},
			method: 'get',
			onSuccess: function(responseText, responseXML) {$('i_map').innerHTML = responseText;}
	}).send();
	
	return false;
}

function i_remove(id,type) {
	// perform ajax request and update i_status
	new Request({
			 url:"/index.php",
			 data: {"ajax":"i_remove","id":id,"type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {$('i_status_'+id).innerHTML = responseText;}
	}).send();
	return false;
}

function i_view() {
	// redirect the user to the view page
	document.location = '/page/itinerary';
	return false;
	
	// display a listing of stores to the user
	var url = '?ajax=i_view';
	new Request({
			 url:url,
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {$('i_status').innerHTML = responseText;}
	}).send();
	return false;
}

function i_list_clear() {
	// perform ajax request and update i_status
	new Request({
			 url:"/index.php",
			 data: {"ajax":"i_list_clear"},
			 method: 'get',
 			 onSuccess: function(responseText, responseXML) {$('i_listing').innerHTML = responseText;}
	}).send();
	return false;
}

function i_print() {
	if ( confirm('Press OK to print this page') )
		window.print();
	return false;
}
// END ITINERARY

