/**
 * Popups
 */	
 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function get_customer_detail(){
	$.post (
		'http://ongas.co.nz/customerdata',
		{ customer_number: $("#customer_number").val() },
		function(resp) {
			var json = eval("(" + resp + ")");
			if(json.has_record > 0){
				if($("#customer_title")){
					$("#customer_title").val(json.title);
				}
				if($("#customer_name")){
					$("#customer_name").val(json.name);
				}
				if($("#customer_address")){
					$("#customer_address").val(json.address);
				}
				if($("#customer_phone")){
					$("#customer_phone").val(json.phone);
				}
				if($("#customer_email")){
					$("#customer_email").val(json.email);
				}
				if($("#Remember")){
					$("#Remember").attr('checked','checked');
				}
			}		   
		}
	);
}
function remove_reorder_residential(){
	if($(".fillRadio")){
		$(".fillRadio").removeAttr('checked');
	}
}
function clear_reorder_residential_txtarea(){
	if($("#reorder_refill_txt")){
		$("#reorder_refill_txt").val("");
	}
}

function remove_reorder_residential2(){
	if($(".fillRadio2")){
		$(".fillRadio2").removeAttr('checked');
	}
}
function clear_reorder_residential_txtarea2(){
	if($("#reorder_refill_txt2")){
		$("#reorder_refill_txt2").val("");
	}
}

function remove_reorder_residential3(){
	if($(".fillRadio3")){
		$(".fillRadio3").removeAttr('checked');
	}
}
function clear_reorder_residential_txtarea3(){
	if($("#reorder_refill_txt3")){
		$("#reorder_refill_txt3").val("");
	}
}

function remove_reorder_residential4(){
	if($(".fillRadio4")){
		$(".fillRadio4").removeAttr('checked');
	}
}
function clear_reorder_residential_txtarea4(){
	if($("#reorder_refill_txt4")){
		$("#reorder_refill_txt4").val("");
	}
}

function remove_title_radio(){
	$(".titleRadio").removeAttr('checked');
}
function clear_titleTxt(){
	if($("#titleTxt")){
		$("#titleTxt").val("");
	}
}

$(document).ready(function()
{
	//Popup windows, just add popup class to any link (replaces the old target=_blank)
	$('a.popup').bind('click',function(){
		window.open(this.href);
		return false;
	});
	//my price input
	if($("#customer_number")){
	    $("#customer_number").bind('blur',get_customer_detail); 
	}
	
	if($("#reorder_refill_txt")){
	    $("#reorder_refill_txt").keypress(remove_reorder_residential); 
	}
	if($(".fillRadio")){
	    $(".fillRadio").click(clear_reorder_residential_txtarea);
	}
	
	if($("#reorder_refill_txt2")){
	    $("#reorder_refill_txt2").keypress(remove_reorder_residential2); 
	}
	if($(".fillRadio2")){
	    $(".fillRadio2").click(clear_reorder_residential_txtarea2);
	}
	
	if($("#reorder_refill_txt3")){
	    $("#reorder_refill_txt3").keypress(remove_reorder_residential3); 
	}
	if($(".fillRadio3")){
	    $(".fillRadio3").click(clear_reorder_residential_txtarea3);
	}
	
	if($("#reorder_refill_txt4")){
	    $("#reorder_refill_txt4").keypress(remove_reorder_residential4); 
	}
	if($(".fillRadio4")){
	    $(".fillRadio4").click(clear_reorder_residential_txtarea4);
	}
	
	if($("#titleTxt")){
	    $("#titleTxt").keypress(remove_title_radio); 
	}
	if($(".titleRadio")){
	    $(".titleRadio").click(clear_titleTxt);
	}
});