function getItinerary(date){

	var div = createIEElement('div', new Array('style'), new Array('position:relative; width:64px; left:50%; margin-left:-32px; color:#ffffff;'));	
	var img = createIEElement('img', new Array('src'), new Array('./images/itinerary_loader.gif'));
	div.appendChild(img);
	div.appendChild(createIEElement('br'));
	div.addText(' loading...');
	getEl('itinerary-ajax').innerHTML = '';
	getEl('itinerary-ajax').appendChild(createIEElement('br'));
	getEl('itinerary-ajax').appendChild(createIEElement('br'));
	getEl('itinerary-ajax').appendChild(createIEElement('br'));	
	getEl('itinerary-ajax').appendChild(div);
	getEl('itinerary-ajax').appendChild(createIEElement('br'));
	getEl('itinerary-ajax').appendChild(createIEElement('br'));
	getEl('itinerary-ajax').appendChild(createIEElement('br'));
	

	$.ajax({
	type: "POST",
	  url: "./includes/classes/itineraryCalendar/itinerary-ajax.php"+"?date="+date,
	  data: "?date="+date,
	  cache: false,
	  success: displayItinerary
	});
}

function displayItinerary(html){
	getEl('itinerary-ajax').innerHTML = html;
}

function getTerms(query_string){

	//first we shall create the div to use
	shoppingCartDiv = createIEElement('div', new Array('id', 'class'), new Array('shopping-cart-div', 'shopping-cart-div-class'));	
	document.body.appendChild(shoppingCartDiv);
	//shoppingCartDiv.innerHTML = '<table style="width:100%"><tr><td style="text-align:center"><h1>Loading Cart Interface...</h1><br /><img src="./images/loader.gif" alt="loading"/></td></tr></table>';
		
	//overwrite the properties for the window
	$.jqm.params.overlay = 80;//transparency percentage
	$.jqm.params.overlayClass = 'shopping-cart-lightbox';
	$.jqm.params.ajax = 'extra-info.php'+query_string+'&dialog=true&title=Terms_and_Conditions';
	$.jqm.params.ajaxText = '<table style="width:100%"><tr><td style="text-align:center"><h1>Loading...</h1><br /><img src="./images/loader.gif" alt="loading"/></td></tr></table>';
	$.jqm.params.modal = true; //will cause the overlay to be inactive
	//$.jqm.params.type = 'POST';	
	
	//alert($.jqm.params.ajax);
	
	$('#shopping-cart-div').jqm( );
	$('#shopping-cart-div').jqmShow(); 
	
	scrollToTop( );
}

function sortMe(url, extra, get_count){

	var start = url.indexOf('&products_sort=');
	var param = '&';
	if(start == -1){
		start = url.indexOf('?products_sort=');
		param = '?';
	}
	//var start = url.indexOf('&products_sort=');
	if(start != -1){
		var end = url.indexOf('&', start+1); //start searching for '&' after the product sort
		if(end == -1){
			end = url.length;
		}
		//alert(start);
		//alert(end);
		
		var remove = url.substring(start, end);
		//alert(remove);
		url = url.replace(remove, '');
	}
	
	if(start != -1 && get_count ==1){//has 1 get paramater that is the product_sort
		url += '?products_sort='+extra;
	}else if(start == -1 && get_count == 0){
		url += '?products_sort='+extra;
	}else if(get_count > 1){
		url += '&products_sort='+extra;
	}else{
		url += '&products_sort='+extra;
	}
	window.location=url;
		
}

//will take the scroll of the page to the top of the screen
function scrollToTop( ){
	scroll(0,0);
}

function pageSearch( ){
	window.location = './search.php?_srch='+getEl('page_search_input').value;
}

function openInDialog(url, width, height){
	//first we shall create the div to use
	var margin = Math.floor(width/2);
	shoppingCartDiv = createIEElement('div', new Array('id', 'class', 'style'), new Array('shopping-cart-div', 'shopping-cart-div-class', 'width:'+width+'px; height:'+height+'px; margin-left:-'+margin+'px'));	
	document.body.appendChild(shoppingCartDiv);
	//shoppingCartDiv.innerHTML = '<table style="width:100%"><tr><td style="text-align:center"><h1>Loading Cart Interface...</h1><br /><img src="./images/loader.gif" alt="loading"/></td></tr></table>';
	
	//overwrite the properties for the window
	$.jqm.params.overlay = 80;//transparency percentage
	$.jqm.params.overlayClass = 'shopping-cart-lightbox';
	$.jqm.params.ajax = url;
	$.jqm.params.ajaxText = '<table style="width:100%"><tr><td style="text-align:center"><h1>Loading...</h1><br /><img src="./images/loader.gif" alt="loading"/></td></tr></table>';
	$.jqm.params.modal = true; //will cause the overlay to be inactive
	//$.jqm.params.type = 'POST';
	
	
	scrollToTop( );
	$('#shopping-cart-div').jqm( );
	$('#shopping-cart-div').jqmShow(); 
}

function closeMediaDialog( ){
	$('#shopping-cart-div').jqmHide(); 
	document.body.removeChild(shoppingCartDiv);
	if(dickyBrowser( )){
		var list = document.getElementsByTagName('select');
		for(i=0; i<list.length; i++){
			list[i].style.display = 'block';
		}
	}
}

function getBandwidthDialog(self){
	var div = createIEElement('div', new Array( ), new Array( ));
		//	div.innerHTML = \'bla bla bla I like to watch naked females\';
		//	div.innerHTML += \'<table><tr><td style="text-align:center"><strong>Low Bandwidth Site</strong><br />Get a faster connection<br /><Br /><input type="button" value="Low Bandwidth"/></td>\';
		//	div.innerHTML += \'<td style="text-align:center"><strong>Hight Bandwidth Site</strong><br />Get a slower connection<br /><Br /><input type="button" value="High Bandwidth"/></td></tr></table>\'; 
			var ss = createIEElement('strong', new Array( ), new Array( ));
			ss.addText('Kia Ora! ');
			div.appendChild(ss);
			div.addText('Welcome to our new website featuring Kirra Holidays\' wide range of New Zealand holidays.');
			div.appendChild(createIEElement('br', new Array( ), new Array( )));
			div.addText('Our new website has many new features such as an interactive itinerary builder and membership system to retrieve previous Itineraries.');
			div.appendChild(createIEElement('br', new Array( ), new Array( )));
			div.appendChild(createIEElement('br', new Array( ), new Array( )));  
			div.addText('To assist you in browsing our website please choose which version you would like to use: Low Bandwidth or High Bandwidth.');
			div.appendChild(createIEElement('br', new Array( ), new Array( )));  
			div.appendChild(createIEElement('br', new Array( ), new Array( )));  
			
			var wrap_div = createIEElement('div', new Array('style'), new Array('width:600px'));
			
			var left_div = createIEElement('div', new Array('style'), new Array('float:left; display:inline-block; padding-left:40px'));
			var strong = createIEElement('strong', new Array( ), new Array( ));
			strong.addText('Low Bandwidth Site');
			left_div.appendChild(strong);
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			left_div.addText('- no images, faster loading time');
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			left_div.addText('- no google maps');
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			left_div.addText('- optimised for slower connections and mobile devices');
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			left_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			var ref = createIEElement('a', new Array('href', 'style'), new Array(self+'low-bandwidth-toggle=true', 'text-decoration:underline'));
			ref.addText('Low Bandwidth Site');
			left_div.appendChild(ref);
			
			//var button = createIEElement('input', new Array('type', 'class', 'value', 'onclick', 'id'), new Array('button','green-button', 'Low Bandwidth Site', 'bandwidthRelocate("'+self+'low-bandwidth-toggle=true")', 'low_band_button'));
			//left_div.appendChild(button);
			
			var right_div = createIEElement('div', new Array('style'), new Array('float:right; display:inline-block; padding-left:40px'));
			strong = createIEElement('strong', new Array( ), new Array( ));
			strong.addText('High Bandwidth Site');
			right_div.appendChild(strong);		
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			right_div.addText('- high quality images ');
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			right_div.addText('- product image galleries ');
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			right_div.addText('- google maps');	
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			right_div.addText('- optimised for high-speed connections');
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			right_div.appendChild(createIEElement('br', new Array( ), new Array( ))); 
			ref = createIEElement('a', new Array('href', 'style'), new Array(self+'low-bandwidth-toggle=false', 'text-decoration:underline'));
			ref.addText('High Bandwidth Site');
			right_div.appendChild(ref);
			//button = createIEElement('input', new Array('type', 'class', 'value', 'onclick', 'id'), new Array('button','green-button', 'Low Bandwidth Site', 'bandwidthRelocate("'+self+'low-bandwidth-toggle=false")', 'low_band_button'));
			//right_div.appendChild(button);
						
			wrap_div.appendChild(left_div);
			wrap_div.appendChild(right_div);
			
			div.appendChild(wrap_div);
			
			div.appendChild(createIEElement('br', new Array('style'), new Array('clear:both;')));
			div.appendChild(createIEElement('br', new Array( ), new Array( )));
			div.addText('At any time, you may switch between low/high bandwith versions by clicking the link at the bottom of the website');
			div.appendChild(createIEElement('br', new Array( ), new Array( )));
			div.appendChild(createIEElement('br', new Array( ), new Array( )));
			var img = createIEElement('img', new Array('src'), new Array('./images/bandwidth_toggle_img.jpg'));
			div.appendChild(img);
			
			
			
			showDialog(div);	
}

function bandwidthRelocate(url){
	window.location=url;
}

function simulateClick(elm) {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var canceled = !elm.dispatchEvent(evt);
  if(canceled) {
    // A handler called preventDefault
    // uh-oh, did some XSS hack your site?
  } else {
    // None of the handlers called preventDefault
    // do stuff
  }
}

function populateSuburbList() {
	var country = getEl('agent-finder-country').value;
	if(country != null && country != '') {
		$.ajax({
			type: "GET",
			  url: "./includes/classes/product/product-ajax.php?action=populateSuburbList&country="+country,
			  success: fillSuburbList,
			  error: function(a,b,c){alert(a); alert(b); alert(c)}
			});
	}
}
function fillSuburbList(html) {
	getEl('agent-finder-suburb').innerHTML = html;
}

