function ViewCrossReference (selSelectObject)
{
   if (selSelectObject.options[selSelectObject.selectedIndex].value != "")
   {
     location.href=selSelectObject.options[selSelectObject.selectedIndex].value
   }
}


function show(obj) 
{	
	var moving_to = document.getElementById('moving_to_int');
	var value = moving_to.value;
	
	document.getElementById('qquote_small_print_local').style.display = 'none';
	document.getElementById('london').style.display = 'none';
	document.getElementById('auckland_christchurch_wellington').style.display = 'none';
	document.getElementById('singapore_hongkong').style.display = 'none';
	document.getElementById('LA_SF').style.display = 'none';
	
	if(value != '')
	{
		document.getElementById(value).style.display = 'block';		
	}
	
	/*no = obj.options[obj.selectedIndex].value;
	count = obj.options.length;
	for(i=1;i<count;i++)
	document.getElementById('SkiDiv'+i).style.display = 'none';
	document.getElementById('SkiDiv'+i).style.display = 'none';
	document.getElementById('SkiDiv'+i).style.display = 'none';
	document.getElementById('SkiDiv'+i).style.display = 'none';
	if(no>0)
	document.getElementById('SkiDiv'+no).style.display = 'block';*/
}



	function qquote_update_sprite(item){
		//var small_print = document.getElementById('moving_to_int').value;
		switch(item){
			case 'quote_local':
					{
						$('.quote_local').css({backgroundPosition:'0px 0px'}); //select to local
						$('.quote_interstate').css({backgroundPosition:'0px -81px'});	//deselect interstate
						$('.quote_global').css({backgroundPosition:'2px -40px'});	//deselect international
						//$('#qquote_form').css('display','block');
						$('#qquote_form').fadeIn('slow');
						$('#international').hide();					
						document.getElementById('quote_type').value = "local";						
						//document.getElementById('qquote_small_print_local').style.display = 'block';
						//if(small_print)						
						//	document.getElementById(small_print).style.display = 'none';
						//else
						//	document.getElementById('london').style.display = 'none';
					}			
					break;
			case 'quote_interstate':
					{
						$('.quote_interstate').css({backgroundPosition:'0px -60px'});	//select interstate
						$('.quote_global').css({backgroundPosition:'2px -40px'});	//deselect international
						$('.quote_local').css({backgroundPosition:'-80px 0px'}); //deselect to local
						//$('#qquote_form').css('display','block');
						$('#qquote_form').fadeIn('slow');
						$('#international').hide();
						document.getElementById('quote_type').value = "local";
						//document.getElementById('qquote_small_print_local').style.display = 'block';						
						//document.getElementById(small_print).style.display = 'none';
						//if(small_print)						
						//	document.getElementById(small_print).style.display = 'none';
						//else
						//	document.getElementById('london').style.display = 'none';
					}
					break;
			case 'quote_global':
					{
						$('.quote_global').css({backgroundPosition:'2px -20px'});	//select international
						$('.quote_interstate').css({backgroundPosition:'0px -81px'});	//deselect interstate
						$('.quote_local').css({backgroundPosition:'-80px 0px'}); //deselect to local
						//$('#qquote_form').css('display','none');
						//$('#qquote_form').hide();
						//$('#international').fadeIn('slow');
						$('#qquote_form').fadeIn('slow');
						$('#international').hide();
						document.getElementById('quote_type').value = "international";
						//document.getElementById('qquote_small_print_local').style.display = 'block';
						//document.getElementById('quick_quote_details').style.display = 'none';						
						//document.getElementById('qquote_small_print_local').style.display = 'block';						
						//show($('#moving_to_int'));
						//if(small_print==''){
						//	document.getElementById('london').style.display = 'block';
						//}
					}
					break;
		}
	}
	
	function qquote_update_sprite2(item){
		var sel_quote_moving = document.getElementById('sel_quote_moving').value;
		var sel_quote_type = document.getElementById('sel_quote_type').value;
		if(item == '')
		  item = sel_quote_type;
		switch(item){
			case '':
			{
				$('#qquote_form_local').hide();
				$('#qquote_form_int').hide();
			}
			break;
			case 'local':
			{
			  if(sel_quote_moving == '')
			  {
			    $('#qquote_form_local').hide();
				$('#qquote_form_int').hide();
			  }
			  else
			  {
				$('#qquote_form_int').hide();
				$('#qquote_form_local').fadeIn('slow');
			  }
			}
			break;
			case 'international':
			{
			  if(sel_quote_moving == '')
			  {
			    $('#qquote_form_local').hide();
				$('#qquote_form_int').hide();
			  }
			  else
			  {
				$('#qquote_form_local').hide();
				$('#qquote_form_int').fadeIn('slow');
			  }
			}
			break;
		}
		if(sel_quote_moving == 'whole_house')
		{
		  if(document.getElementById('require1'))
		    document.getElementById('require1').value = "quote_type,quote_moving,name,customer_email,phone,residence_type,moving_from,moving_to,move_date";
		  if(document.getElementById('require2'))
		    document.getElementById('require2').value = "quote_type,quote_moving,name,customer_email,phone,residence_type,moving_from,moving_to,move_date";
		}
		else if(sel_quote_moving == 'small_move')
		{
		  if(document.getElementById('require1'))
		    document.getElementById('require1').value = "quote_type,quote_moving,name,customer_email,phone,moving_from,moving_to,move_date";
		  if(document.getElementById('require2'))
		    document.getElementById('require2').value = "quote_type,quote_moving,name,customer_email,phone,moving_from,moving_to,move_date";
		}
		if(document.getElementById('quote_moving'))
		  document.getElementById('quote_moving').value = sel_quote_moving;
		if(document.getElementById('quote_moving2'))
		  document.getElementById('quote_moving2').value = sel_quote_moving;
		if(document.getElementById('moving_to2'))
		  if(document.getElementById('moving_to2').value != '')
		    getScriptPageCountry('box22','moving_to2','to_country','','','autosuggest_int1');
	}
	
	function change_text(text) {
		var var1 = text;
		if(var1 == 'quote_global' || var1 == 'international')
		{
			document.getElementById('moving_to').value = 'Country To';
		}
		else
		{
			document.getElementById('moving_to').value = 'Suburb or Postcode';
		}
	}
	
	function popup() {
		if(document.getElementById('popup').style.display == 'block')
			document.getElementById('popup').style.display = 'none';
		else
			document.getElementById('popup').style.display = 'block';
	}
	
	function toggle_check(div_id, chk_id) {
	  if(document.getElementById(chk_id) && document.getElementById(div_id))
	  {
		var adiv = document.getElementById(div_id);
		var achk = document.getElementById(chk_id);
		if(document.getElementById(chk_id).checked)
		{
		  adiv.style.display = "block";
		}
		else
		{
		  adiv.style.display = "none";
		}
	  }
	}
	
	function check_require(require_id)
	{
	  var required = document.getElementById(require_id).value;
	  var req_array = required.split(','); 
	  var check = true;
	  var fname;
	  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	  if(required != '')
	  {
		var i;
		for(i=0; i<req_array.length; i++)
		{
		  if(require_id == 'require3')
		    fname = req_array[i]+'3';
		  else if(require_id == 'require2')
		    fname = req_array[i]+'2';
		  else
		    fname = req_array[i];
		  if(document.getElementById(fname).value == '' || document.getElementById(fname).value == 'Suburb or Postcode')
		  {
		    alert('Please fill all mandatory fields');
			check = false;
			break;
		  }
		  else
		  {
			  if(fname == 'customer_email' || fname == 'customer_email2' || fname == 'customer_email3')
			  {
			    if(reg.test(document.getElementById(fname).value) == false)
				{
				  alert('Invalid Email Address');
				  check = false;
				  break;
				}
			  }
		  }
		}
	    return check;
	  }
	  return check;
	}

	

/******************* AUTO COMPLETE FUNCTIONALITY ***********************************/
	(function( $ ) {
		$.widget( "ui.combobox", {
			_create: function() {
				var self = this,
					select = this.element.hide(),
					selected = select.children( ":selected" ),
					value = selected.val() ? selected.text() : "Type location...";
				var input = this.input = $( "<input>" )
					.insertAfter( select )
					.val( value )
					.autocomplete({
						delay: 0,
						minLength: 0,
						source: function( request, response ) {
							var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
							response( select.children( "option" ).map(function() {
								var text = $( this ).text();
								if ( this.value && ( !request.term || matcher.test(text) ) )
									return {
										label: text.replace(
											new RegExp(
												"(?![^&;]+;)(?!<[^<>]*)(" +
												$.ui.autocomplete.escapeRegex(request.term) +
												")(?![^<>]*>)(?![^&;]+;)", "gi"
											), "<strong>$1</strong>" ),
										value: text,
										option: this
									};
							}) );
						},
						select: function( event, ui ) {
							
							ui.item.option.selected = true;
							self._trigger( "selected", event, {
								item: ui.item.option
							});
							$(this).parent('form').submit();
						},
						
						change: function( event, ui ) {
							
							if ( !ui.item ) {
								var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
									valid = false;
								select.children( "option" ).each(function() {
									if ( $( this ).text().match( matcher ) ) {
										this.selected = valid = true;
										return false;
										
									}
									
								});
								if ( !valid ) {
									// remove invalid value, as it didn't match anything
									$( this ).val( "" );
									select.val( "" );
									input.data( "autocomplete" ).term = "";
									return false;
								}
							}
						}
					})
					.addClass( "ui-widget ui-widget-content ui-corner-left" );

				input.data( "autocomplete" )._renderItem = function( ul, item ) {
					return $( "<li></li>" )
						.data( "item.autocomplete", item )
						.append( "<a>" + item.label + "</a>" )
						.appendTo( ul );
				};

				this.button = $( "<button type='button'>&nbsp;</button>" )
					.attr( "tabIndex", -1 )
					.attr( "title", "Show All Items" )
					.insertAfter( input )
					.button({
						icons: {
							primary: "ui-icon-triangle-1-s"
						},
						text: false
					})
					.removeClass( "ui-corner-all" )
					.addClass( "ui-corner-right ui-button-icon" )
					.click(function() {
						// close if already visible
						if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
							input.autocomplete( "close" );
							return;
						}

						// work around a bug (likely same cause as #5265)
						$( this ).blur();

						// pass empty string as value to search for, displaying all results
						input.autocomplete( "search", "" );
						input.focus();
					});
			},

			destroy: function() {
				this.input.remove();
				this.button.remove();
				this.element.show();
				$.Widget.prototype.destroy.call( this );
			}
		});
	})( jQuery );

	
	var loadAutoloader=function() {
		if ( $("#autoComplete").length>0 && $("#autoComplete .ui-button").length===0 ) { 
		//console.debug("found and deploying");
			$("#autoComplete select").combobox();

			var newInput = $('#autoComplete').find('input.ui-autocomplete-input');
			var inputVal = $(newInput).val();
			$(newInput).click(function(){			   
				if(inputVal == inputVal){
					$(newInput).val('');
				}
			});
			$(newInput).live('blur', function(){
					var inputValNew = $(newInput).val();
					if(inputValNew == ''){
						$(newInput).val(inputVal);
					}
				});

		} else {
			//console.debug("trying again");
		}
	};

window.setInterval("loadAutoloader()",500);
	
	
