/***********************************************
* 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";});
	
	/* Popup window */
	var profiles = {standardwindow:{height:500,width:780,center:1,toolbar:0,status:1,menubar:1,scrollbars:1,resizable:0},smallwindow:{height:400,width:450,status:1,menubar:1,resizable:0,left:50,top:50}};
   $(function(){$('.popup').popupwindow(profiles);});

	/*on focus for input boxes*/
	$.fn.search = function() {
		return this.focus(function() {if( this.value == this.defaultValue ) {this.value = "";}})
		.blur(function() {if( !this.value.length ) {this.value = this.defaultValue;}});};

		//on the click of the search input, clear string
		if($("input.searchkey").val() == "search our products")
		{
			$("input.searchkey").search();
		}
	

	/* on the search form submit */
	$("form#SearchProduct").submit(function(){
		//if the user submits search our products, clear string
		if($("input.searchkey").val() == "search our products")
		{
			$("input.searchkey").val("");
		}

		//get the length of the string
		var searchLength = $("input.searchkey").val().length;

		//if the search string is less than 3 characters alert the user
		if(searchLength >= 0 && searchLength < 3)
		{
			alert("You must place at least three characters");
			$("input.searchkey").focus();
			return false;
		}
	});
	
	/*accordion navigation*/
	$('ul#catalogue-nav').accordion({
			active: false,
			header: '.firstlevel',
			navigation: true,
			autoheight: false,
			alwaysOpen: false
		});
	$('ul#catalogue-nav li.active:even').addClass('alt-bg');
			
	/*set hover class for anything*/
	$('form.cmxform.send').hover(function() {$(this).addClass('sendhover');}, function() {$(this).removeClass('sendhover');});
	$('ul.listings li').hover(function() {$(this).addClass('lihover');}, function() {$(this).removeClass('lihover');});
	$('a.send1').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('#search input.submitbut').hover(function() {$(this).addClass('searchhover');}, function() {$(this).removeClass('searchhover');});
	
});


/***********************************************
* Safe email links
***********************************************/

function hideEmail1() {
	var s1 = "info";
			var s2 = "@";
			var s3 = "antiquesandcollectables.com.au";
			var s4 = "?Subject=Enquiry%20from%20" + s3;
			var s5 = s1 + s2 + s3;
			document.write("<a href=" + "mail" + "to:" + s1 + s2 + s3 + s4 + ">" + s5 + "</a>");
}

function hideEmail2() {
	var s1 = "info";
			var s2 = "@";
			var s3 = "antiquesandcollectables.com.au";
			var s4 = "?Subject=Enquiry%20from%20" + s3;
			var s5 = "Click here to email us";
			document.write("<a href=" + "mail" + "to:" + s1 + s2 + s3 + s4 + ">" + s5 + "</a>");
}

/***********************************************
* Form fields Validation Script
***********************************************/

function ValidateForm(f){

	with(f){
		if (isEmpty(_1_Product_Name.value)) {alert("Please enter the Product Name");_1_Product_Name.focus();return false;}
		if (isEmpty(_2_Stock_Number.value)) {alert("Please enter the Stock Number");_2_Stock_Number.focus();return false;}
		if (isEmpty(_3_Name.value)) {alert("Please enter your Name");_3_Name.focus();return false;}
		if (isEmpty(_5_Email_From.value)) {alert("Please enter your Email Address");_5_Email_From.focus();return false;}
		if ( !isEmail(_5_Email_From.value) ) {alert("Please enter a valid Email Address."); _5_Email_From.focus();return false;}
		if (!isEmpty(_6_Phone.value)) {if (!IsNumber(_6_Phone.value, true)) {alert("Please enter only numbers for your Phone");_6_Phone.focus();return false;}}
		if (isEmpty(_7_Enquiries.value)) {alert("Please enter your Enquiry");_7_Enquiries.focus();return false;}
	}
	return true;
 }


/***********************************************
* Form fields Validation Script 2
***********************************************/

function ValidateForm2(f){

	with(f){
		if (isEmpty(_1_Name.value)) {alert("Please enter your Name");_1_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)) {if (!IsNumber(_6_Phone.value, true)) {alert("Please enter only numbers for your Phone");_5_Phone.focus();return false;}}
		if (isEmpty(_6_Antique.value)) {alert("Please enter your enquired Antique Name");_6_Antique.focus();return false;}
		if (isEmpty(_7_Enquiries.value)) {alert("Please enter your Enquiry");_7_Enquiries.focus();return false;}
	}
	return true;
 }
 