/***********************************************
* jQuery functions execute
***********************************************/
$(document).ready(function() {                
              
	/*cmx form */
	if(jQuery.browser.mozilla) {
		$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                          	var $labelContent = $(this).html();
                                       var $labelWidth = $(this).css('width');
                                       $(this).empty();
                                       $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                       $(this).prepend('</span>');
                                       $(this).css('display', '-moz-inline-box');
                                       $(this).find('span').html($labelContent);
                                       $('form.cmxform').show();
                                });
                };             


	/*external link*/
	$('a[@rel$="external"]').click(function(){this.target = "_blank";});
	/*thckbox opacity*/
	$('.thickbox').click(function() {$('.TB_overlayBG').css('opacity', '0.75');});
	
	/*email protect*/
	$("span.safemail").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
		$(this).remove();
	});
	
	/* Popup window */
   $(".popup").popupwindow();

	/*accordion navigation*/
	$('ul#catalogue-nav').accordion({
			active: false,
			header: '.firstlevel',
			navigation: true,
			event: 'click',
			autoheight: true,
			alwaysOpen: false
		});
	
	/*text scroller*/
	$('#scroll').cycle({ 
	    fx:    'scrollLeft', 
		speed: 5000,
		timeout: 5000,
		delay: 2000 
	});
	
	/*round corner*/
	$('ul#staff> li').corner("rounded 10px top bottom");
	$('ul.brochure-listings').corner("rounded 10px top bottom");
	$('ul.brochure-listings> li').corner("rounded 10px top bottom");
	$('#enquiry-form').corner("rounded 10px top bottom");
	$('ul#link-listings> li').corner("rounded 10px top bottom");
	$('ul#special-listings> li').corner("rounded 10px top bottom");
	$('ul#product-listings li').corner("rounded 10px top bottom");
	$('.box-wrap').corner("rounded 10px top bottom");
	$('#side-affiliates').corner("rounded 10px top bottom");
	$('#popup #container').corner("rounded 10px top bottom");
	$('.breadcrumb').corner("rounded 10px top bottom");
	$('.thumbnails').corner("rounded 10px top bottom");
	$('.thumbnails-inline').corner("rounded 10px top bottom");

	/*set hover class for anything*/
	$('form.cmxform input.send').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('a.send').hover(function() {$(this).addClass('sendhover');}, function() {$(this).removeClass('sendhover');});
	
	/*table*/
	/*$(".desc table").wrap('<div class="product-table"></div>');

	$(".product-table table").removeAttr("style");
	$(".product-table table").removeAttr("border");
	$(".product-table table tr").removeAttr("style");
	$(".product-table table td").removeAttr("style");
	$(".product-table table p").removeAttr("style");
	$(".product-table table span").removeAttr("style");

	$(".product-table table tr:even").addClass("even");
	$(".product-table table tr:odd").addClass("odd");

	$(".product-table table tr:first-child").addClass("header");
	$(".product-table table tr td.header:first-child").addClass("model");
	$(".product-table table tr td:first-child").addClass("first-column");
	$(".product-table table tr td.header:nth-child(1)").addClass("product-code");*/

});


/***********************************************
* Form fields Validation Script
***********************************************/

function ValidateForm1(f){

	with(f){
		if (isEmpty(_1_Name.value)) {alert("Please enter your Name");_1_Name.focus();return false;}
		if (isEmpty(_2_Email_From.value)) {alert("Please enter your Email Address");_2_Email_From.focus();return false;}
		if ( !isEmail(_2_Email_From.value) ) {alert("Please enter a valid Email Address."); _2_Email_From.focus();return false;}
		if (isEmpty(_3_Phone.value)) {alert("Please enter your Phone Number");_3_Phone.focus();return false;}
		if (isEmpty(_5_Enquiries.value)) {alert("Please enter your Enquiry");_5_Enquiries.focus();return false;}
	}
	return true;
 }

function ValidateForm2(f){

	with(f){
		if (isEmpty(_1_Product_Name.value)) {alert("Please enter the Product Name");_1_Product_Name.focus();return false;}
		if (isEmpty(_2_Product_Model_Number.value)) {alert("Please enter the Product Model Number");_2_Product_Model_Number.focus();return false;}
		if (isEmpty(_3_Name.value)) {alert("Please enter your Name");_3_Name.focus();return false;}
		if (isEmpty(_4_Email_From.value)) {alert("Please enter your Email Address");_4_Email_From.focus();return false;}
		if (!isEmail(_4_Email_From.value) ) {alert("Please enter a valid Email Address."); _4_Email_From.focus();return false;}
		if (isEmpty(_5_Phone.value)) {alert("Please enter your Phone Number");_5_Phone.focus();return false;}
		if (isEmpty(_7_Enquiries.value)) {alert("Please enter your Enquiry");_7_Enquiries.focus();return false;}
	}
	return true;
 }
 
 function ValidateForm3(f){

	with(f){
		if (isEmpty(_1_Brand_Name.value)) {alert("Please enter the Brand Name");_1_Brand_Name.focus();return false;}
		if (isEmpty(_2_Brochure_Title.value)) {alert("Please enter the Brochure Title");_2_Brochure_Title.focus();return false;}
		if (isEmpty(_3_Name.value)) {alert("Please enter your name");_3_Name.focus();return false;}
		if (isEmpty(_4_Email_From.value)) {alert("Please enter your Email Address");_4_Email_From.focus();return false;}
		if (!isEmail(_4_Email_From.value) ) {alert("Please enter a valid Email Address."); _4_Email_From.focus();return false;}
		if (isEmpty(_5_Phone.value)) {alert("Please enter your Phone Number");_5_Phone.focus();return false;}
	}
	return true;
 }

 
function ValidateForm4(f){

	with(f){
		if (isEmpty(_1_Customer_Name.value)) {alert("Please enter your Name");_1_Customer_Name.focus();return false;}
		if (isEmpty(_2_Street_Address1.value)) {alert("Please enter your Street Address");_2_Street_Address1.focus();return false;}
		if (isEmpty(_4_Suburb.value)) {alert("Please enter your Suburb");_4_Suburb.focus();return false;}
		if (isEmpty(_5_Postcode.value)) {alert("Please enter your Postcode");_5_Postcode.focus();return false;}
		if (isEmpty(_6_Phone.value)) {alert("Please enter a Contact Phone Number");_6_Phone.focus();return false;}
		if (isEmpty(_9_Email_From.value)) {alert("Please enter your Email Address");_9_Email_From.focus();return false;}
		if ( !isEmail(_9_Email_From.value) ) {alert("Please enter a valid Email Address."); _9_Email_From.focus();return false;}
		if (isEmpty(_11_Date_of_installation.value)) {alert("Please enter the date of installation");_11_Date_of_installation.focus();return false;}
		if (isEmpty(_12_Brand_of_Unit.value)) {alert("Please enter the Brand of Unit");_12_Brand_of_Unit.focus();return false;}
		if (isEmpty(_13_Type_of_System.value)) {alert("Please enter the Type of System");_13_Type_of_System.focus();return false;}

		if (isEmpty(_14_Indoor_Unit_Model_Number.value)) {alert("Please enter the Indoor Unit Model Number");_14_Indoor_Unit_Model_Number.focus();return false;}
		if (isEmpty(_19_Fault_Code_and_Nature_of_Fault.value)) {alert("Please report the Fault Code or Nature of Fault");_19_Fault_Code_and_Nature_of_Fault.focus();return false;}
	}
	return true;
 }

 function ValidateForm5(f){

	with(f){
		if (isEmpty(_1_Brand_Name.value)) {alert("Please enter the Brand Name");_1_Brand_Name.focus();return false;}
		if (isEmpty(_2_Manual_Title.value)) {alert("Please enter the Manual Title");_2_Manual_Title.focus();return false;}
		if (isEmpty(_3_Name.value)) {alert("Please enter your name");_3_Name.focus();return false;}
		if (isEmpty(_4_Email_From.value)) {alert("Please enter your Email Address");_4_Email_From.focus();return false;}
		if (!isEmail(_4_Email_From.value) ) {alert("Please enter a valid Email Address."); _4_Email_From.focus();return false;}
		if (isEmpty(_5_Phone.value)) {alert("Please enter your Phone Number");_5_Phone.focus();return false;}
	}
	return true;
 }
