function addressLookup()
{

	var housenum = document.getElementById("pi_search_house");
	var postcode = document.getElementById("pi_search_postcode");

	//if(housenum.value == "" || postcode.value == "")
	//	return false;

	xajax_ajaxsearch_postcode(housenum.value, postcode.value);

}

function addAddress(txt,val)
{
	var id = document.getElementById(txt);
	id.value = val;
}

function selectRadioOption(intID) 
{
	document.getElementById(intID).checked = true;
}


/*
 * Show and hide element function
*/

function showElement(id)
{

	var e = document.getElementById(id);

	if (e.style.display == 'none')
	{
		e.style.display = 'block';
	}
	else
	{
		e.style.display = 'none';
	}

}

/*
 *Limit the characters in the text area field
 */
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
}
}


/*
 *Returns the version of Internet Explorer or a -1
 *(indicating the use of another browser).
 */
function getInternetExplorerVersion()
{
	var rv = -1; // Return value assumes failure.

	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}

	return rv;
}

/*
 * Enable/Disable hover style over the tab items
 * oItem (the li object ref)
 * bOther (is it an OTHER style tab - i.e. News or Contact Us)
 * bOn (is it being hovered over?)
 */
function tabItemHover(oItem, bOther, bOn)
{
	var oChild;
	var iIEVersion;

	iIEVersion = getInternetExplorerVersion();
	
	if((iIEVersion >= 6.0) && (iIEVersion < 7.0))
	{
		if(bOn)
		{
			oItem.style.backgroundPosition 		= "right top";
			
			oChild 								= oItem.getElementsByTagName("a");
			oChild[0].style.backgroundPosition 	= "left top";
			oChild[0].style.color 				= "#27a42e";
			oChild[0].style.padding 			= "5px 0 0 15px";
			oChild[0].style.height 				= "41px";
			oChild[0].style.lineHeight			= "41px";					
		}
		else
		{
			oItem.style.backgroundPosition 		= "right " + (bOther ? "-100px" : "-50px");
			
			oChild 								= oItem.getElementsByTagName("a");
			oChild[0].style.backgroundPosition 	= "left " + (bOther ? "-100px" : "-50px");
			oChild[0].style.color 				= "#ffffff";
			oChild[0].style.padding 			= "10px 0 0 15px";
			oChild[0].style.height 				= "36px";
			oChild[0].style.lineHeight			= "36px";		
		}
	}
}



/*
 * Keypress function (F9) for Webdev stats/info.  This only for Mozilla browsers (e.g. Firefox).
*/
$(document).ready( function()
{
	
	$("#webdev_info").css({ "display" : "block" }).hide();

	$(document).keypress( function(event)
	{
		
		if( event.keyCode == 120 )
		{
			$("#webdev_info").toggle("slow");
		}
		
	});
	
	//*********************************************************//
	//Prevent double form submit
	/*$('form').submit(
			function()
			{
				$(':submit', this).click(function() 
				{
					return false;
				}
			);
	});*/
	//*********************************************************//
	//Survey popup handling	
	$('#surveyPopup').dialog({ show: 'slow',position: ['auto',100] }); //Open our survey popup
	
	
	//close survey popup when link clicked on
	$("#surveyPopupClose").click
	( 
		function()
		{
			$('#surveyPopup').dialog('close');
		}
	);
	
	//Survey popup to open new window
	$("#surveyPopupOpen").click
	( 
		function()
		{
			popup = window.open('http://www.helpucover.co.uk/views/templates/general/survey_popup_question.html','_blank','width=800,height=600,alwaysLowered=yes, scrollbars=yes');
			popup.blur();
			window.focus();
			self.focus();
			
			$('#surveyPopup').dialog('close');
		}
	);
	//Optout form on privacy page
	
	if ($('#opt_out_preferences_post').attr('checked'))
     {
     	$('#opt_out_preferences_post_fields').show('slow');
     }
     else
     {
     	$('#opt_out_preferences_post_fields').hide();
     }
     
     if ($('#opt_out_preferences_email').attr('checked'))
     {
     	$("#opt_out_preferences_email_fields").show('slow');
     }
     else
     {
     	$("#opt_out_preferences_email_fields").hide();
     }
     
     if ( ( $('#opt_out_preferences_telephone').attr('checked') && $('#opt_out_preferences_sms').attr('checked')==false )  || ( $('#opt_out_preferences_sms').attr('checked') && $('#opt_out_preferences_telephone').attr('checked')==false ) )
     {
     	$("#opt_out_preferences_phone_fields").show('slow');
     }
     else if ($('#opt_out_preferences_sms').attr('checked')==false && $('#opt_out_preferences_telephone').attr('checked')==false)
     {
     	$("#opt_out_preferences_phone_fields").hide();
     }
     
		
		
	$("#opt_out_preferences_post,#opt_out_preferences_email,#opt_out_preferences_telephone,#opt_out_preferences_sms").click
	(
		function () 
		{
			var id 		= this.id;
			var fields 	= id + '_fields';

			
	         if ($(this).attr('checked'))
	         {
	         	$("#" + fields).show('slow');
	         }
	         else
	         {
	         	$("#" + fields).hide();
	         }
			
	         if ( ( $('#opt_out_preferences_telephone').attr('checked') && $('#opt_out_preferences_sms').attr('checked')==false )  || ( $('#opt_out_preferences_sms').attr('checked') && $('#opt_out_preferences_telephone').attr('checked')==false ) )
	         {
	         	$("#opt_out_preferences_phone_fields").show('slow');
	         	
	         }
	         else if ($('#opt_out_preferences_sms').attr('checked')==false && $('#opt_out_preferences_telephone').attr('checked')==false)
	         {
	         	$("#opt_out_preferences_phone_fields").hide();
	         }



	         var newWindowHeight = $('#optOutForm').height() + 100;
	         
	         
	         window.resizeTo(700, newWindowHeight);
	         

		}
	);
	
	
	//*********************************************************//
	//Optout handling	
	

	/*Removing this check for now
	if ($('#customer_opt_out').attr('checked')) 
	{
     	$("#customer_opt_out_preferences").fadeIn("slow");
 		$('#customer_opt_out_preferences').dialog({ autoOpen: false,title: 'Opt Out Preferences',position: [100,230],buttons: { "Ok": function() { $(this).dialog("close"); },"Close": function() { $(this).dialog("close"); } } }); 
 		$("#customer_opt_out_preferences").parent().appendTo($("form:first"));

 		$('#customer_opt_out_preferences').dialog('open'); //Open our survey popup
	}
	else
	{
		$("#customer_opt_out_preferences").hide();
		//$('#customer_opt_out_preferences').dialog('close');
	}*/
	
	
		$("#customer_opt_out_preferences").hide();
	
	
	$("#customer_opt_out").click
	(
		function () 
		{
	         if ($('#customer_opt_out').attr('checked'))
	         {
	         	//$("#customer_opt_out_preferences").fadeIn("slow");
	         	$('#customer_opt_out_preferences').dialog({ autoOpen: false,title: 'Opt Out Preferences' ,position: [70,200],buttons: { "Ok": function() { $(this).dialog("close"); } } }); 
	         	$("#customer_opt_out_preferences").parent().appendTo($("form:first"));
	         	$('#customer_opt_out_preferences').dialog('open'); //Open our survey popup
	         }
	         else
	         {
	         	//$("#customer_opt_out_preferences").hide();
	         	$('#customer_opt_out_preferences').dialog('close');
	         }
		}
	);
	//*********************************************************//
	
	$("#switch_and_save").click
    (
            function () 
            {

            $('#switch_and_save_popup_text').dialog({ autoOpen: false,title: 'Switch and Save' ,position: 'center',width: 270,buttons: { "Ok": function() { $(this).dialog("close"); } } }); 
            $('#switch_and_save_popup_text').dialog('open'); //Open our survey popup

            }
    );
    
    $('#switch_and_save_popup_text').hide();

	

});
