/* IE6 Drop down menu fix */
var sfHover = function() {
	if(document.getElementById("main-navigation")){
		var sfEls = document.getElementById("main-navigation").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" hover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* Input click clear */
var clickClear = function(i, value){
	var currentValue = value || input.val();
	i.click(function(){
		if(i.val() == currentValue){
			i.val('');
		}
	});
	i.blur(function(){
		if(i.val() == ''){
			i.val(currentValue);
		}
	});
}

/* Password field changer */
var changePassType = function(){
	var rpass = $('#login-password'), //real password field
		fpass = $('#login-password-hint'); //fake password field
		
		rpass.css('display', 'none');
		fpass.css('display', 'block').attr('value', 'Password')
		
		fpass.focus(function(){			
			fpass.css('display', 'none');
			rpass.css('display', 'block').attr('value', '').focus();			
		});
		
		rpass.blur(function(){			
			if(rpass.val() == ''){
				rpass.css('display', 'none');
				fpass.css('display', 'block').attr('value', 'Password');
			}			
		});	
				
}

/*-----------------------------------
	Doc ready
---------------------------------- */
$(document).ready(function() {

	if ($('#search .input input')) {
		new clickClear($('#search .input input'), 'Type product or business name');
	}

	if ($('#login-email')) {
		new clickClear($('#login-email'), 'Email');
	}

	if ($('.ts-text')) {
		new clickClear($('.ts-text'), '$10,000');
	}

	if ($('#login-password')) {
		changePassType();
	}

	$("#tbl-products").find("input").click(function () {
        	EnableDisableDescriptor();
	});


	austMade.ready();

});

var austMade = {

	/**
	* Function is called on document.ready
	*/
	ready: function () {

		$("#ctl00__phBody_ctl00__rdoSAddressNew, #ctl00__phBody_ctl00__rdoSAddressUsePostal").click(function () {

			austMade.showHideAddress(this, 'street-address');

		});

		$("#ctl00__phBody_ctl00__rdoBAddressNew, #ctl00__phBody_ctl00__rdoBAddressUsePostal").click(function () {

			austMade.showHideAddress(this, 'billing-address');

		});

		/*$("#ctl00__phBody_ctl00__txtCompanyDescription").blur(function () {
			if ($(this).val() == '') {
				$(this).val("X company has been manufacturing its great range of y products in Australia since 1968. It employs more than 400 Australians at its plant in Melbourne.");
			}
		});

		$("#ctl00__phBody_ctl00__txtCompanyDescription").focus(function () {
			if ($(this).val() == 'X company has been manufacturing its great range of y products in Australia since 1968. It employs more than 400 Australians at its plant in Melbourne.') {
				$(this).val("");
			}
		});*/

	},

	/**
	* Shows and hides the address fields
	*/
	showHideAddress: function (sender, addressContainer) {

		if ($(sender).val().indexOf('AddressNew') != -1) {
			$('#' + addressContainer).show();
		} else {

			$('#' + addressContainer + " .form-item input").each(function (i) {
				$(this).val('');
			});

			$('#' + addressContainer + " .form-item select").val('AU');

			$('#' + addressContainer).hide();
		}

	}

}

function EnableDisableDescriptor(e) {

	id = "";

	if (e != null) {

		id = e.id;

	} // end if
	else {
		try{
		if (document.getElementById("ctl00__phBody_ctl00__rdoPA").checked)
			id = "ctl00__phBody_ctl00__rdoPA";

		if (document.getElementById("ctl00__phBody_ctl00__rdoAM").checked)
			id = "ctl00__phBody_ctl00__rdoAM";

		if (document.getElementById("ctl00__phBody_ctl00__rdoAS").checked)
			id = "ctl00__phBody_ctl00__rdoAS";

		if (document.getElementById("ctl00__phBody_ctl00__rdoAG").checked)
			id = "ctl00__phBody_ctl00__rdoAG";

		if (document.getElementById("ctl00__phBody_ctl00__rdoAGPlus").checked)
			id = "ctl00__phBody_ctl00__rdoAGPlus";
		}	
		catch(err){}	

		try{
		if (document.getElementById("ctl00__phBody_ctl01__rdoPA").checked)
			id = "ctl00__phBody_ctl01__rdoPA";

		if (document.getElementById("ctl00__phBody_ctl01__rdoAM").checked)
			id = "ctl00__phBody_ctl01__rdoAM";

		if (document.getElementById("ctl00__phBody_ctl01__rdoAS").checked)
			id = "ctl00__phBody_ctl01__rdoAS";

		if (document.getElementById("ctl00__phBody_ctl01__rdoAG").checked)
			id = "ctl00__phBody_ctl01__rdoAG";

		if (document.getElementById("ctl00__phBody_ctl01__rdoAGPlus").checked)
			id = "ctl00__phBody_ctl01__rdoAGPlus";
		}	
		catch(err){}

	} // end else

	if (id.indexOf("AGPlus") > -1){
		try{document.getElementById("ctl00__phBody_ctl00__txtAGPlusDescriptor").disabled = "";}catch(err){}
		try{document.getElementById("ctl00__phBody_ctl01__txtAGPlusDescriptor").disabled = "";}catch(err){}
	}else{
		try{document.getElementById("ctl00__phBody_ctl00__txtAGPlusDescriptor").disabled = "disabled";}catch(err){}
		try{document.getElementById("ctl00__phBody_ctl01__txtAGPlusDescriptor").disabled = "disabled";}catch(err){}
	}
} // end function EnableDisableDescriptor
