/******************************************************
	FAQ PAGE JAVASCRIPT FUNCTIONALITY
******************************************************/

/**
* matty_nopobox()
* Validate against P.O Box addresses in form fields.
**/

function matty_nopobox(addressline) {
	var check_value = addressline.val().toLowerCase();
	// var pattern = /^([pP]{1}(.*?)[oO]{1}(.*?))?([bB][oO]?[xX])(\s+)([0-9]+)/g;
	
	// var pattern = /^([pP]{1}(.*?)[oO]{1}(.*?))?([bB][oO]?[xX])/; // Check for any variation of P.O Box
	var pattern 			= /^([pP]{1}(.*?)[oO]{1}(.*?))/; // Check for any variation of P.O or PO
	var pattern_fulltext 	= /^([pP]{1}[oO]{1}[sS]{1}[tT]{1}(.*?)[oO]{1}[fF]{1}[fF]{1}[iI]{1}[cC]{1}[eE]{1}(.*?))/; // Check for any variation of Post Office
	
	var result 				= pattern.test(addressline.val());
	var result_fulltext 	= pattern_fulltext.test(addressline.val());
	
	if (result === true || result_fulltext === true) {
		alert('P.O Box addresses are not permitted for courier. Please enter a physical address.');
		addressline.attr('value', '');
		addressline.focus();
		return false;
	}

} // End matty_nopobox()

function getEventCaller(e) {
	if (window.addEventListener) {
		return document.getElementById(e.target.id);
	} else {
		return document.getElementById(window.event.srcElement.id);
	}
}

jQuery(document).ready(function(){

jQuery('.small_videos li span').css('opacity', '0.7');

//When you click on a link with class of poplight and the href starts with a # 
jQuery('a.poplight[href^=#]').click(function() {
    var popID = jQuery(this).attr('rel'); //Get Popup Name
    var popURL = jQuery(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    jQuery('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://test.sisterlilianremedies.co.za/skin/frontend/vital/sister_lilian/assets/images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = (jQuery('#' + popID).height() + 80) / 2;
    var popMargLeft = (jQuery('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    jQuery('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    jQuery('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    jQuery('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
jQuery('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    jQuery('#fade , .popup_block').fadeOut(function() {
        jQuery('#fade, a.close').remove();  //fade them both out
    });
    return false;
});

	
/* Graphicmail popup on elements with the .graphicmail class. */

var open_graphicmail = function () {

	window.open('http://www.graphicmail.co.za/RWCode/subscribe.asp?SiteID=11010&Mode=subscribe','','top=-200,left=75,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=350');
	
} // End OpenGM()
	
jQuery('.graphicmail').unbind('click');

jQuery('.graphicmail').bind('click', open_graphicmail);

/* Graphicmail popup on elements with the .graphicmail class. */
	
	
	// var tmp_01 = '';
	/*
	jQuery('input#street_1').focus( function () {
		
		tmp_01 = jQuery(this).val();
		jQuery(this).val() = '';
		
	});
	*/
	
	jQuery('input#street_1').blur( function () {
		
		if (jQuery(this).val().length > 1) {
			var tmpStr = jQuery(this);
			matty_nopobox(tmpStr);
		}
		
	});
	
	jQuery('input#street_2').blur( function () {
	
		if (jQuery(this).val().length > 1) {
			var tmpStr = jQuery(this);
			matty_nopobox(tmpStr);
		}
		
	});
	
	jQuery("input[title*='Street Address']").blur( function () {
		
		if (jQuery(this).val().length > 1) {
			var tmpStr = jQuery(this);
			matty_nopobox(tmpStr);
		}
		
	});
	
	jQuery("input[title*='Telephone']").mask("(999) 999-9999");
	
	jQuery('.faqpage h2').next().hide();
	jQuery('.faqpage h2').addClass('faq-arrow-down');
	jQuery('.faqpage h3').addClass('faq-arrow-down');
	jQuery('.faqpage h3').prepend('<h2 class="float_left">Q:</h2>');
	jQuery('.faqpage h3').siblings().css('display', 'none');
	
	jQuery('.faqpage h2').click ( function () {
		jQuery(this).next().toggle();
		if ( jQuery(this).hasClass('faq-arrow-down') ) {
			jQuery(this).removeClass('faq-arrow-down');
			jQuery(this).addClass('faq-arrow-up');
		} else if ( jQuery(this).hasClass('faq-arrow-up') ) {
			jQuery(this).removeClass('faq-arrow-up');
			jQuery(this).addClass('faq-arrow-down');
		}
	} );

	jQuery('.faqpage ul li h3').click (function (e) {
		
		if ( jQuery(this).hasClass('faq-arrow-down') ) {
			jQuery(this).removeClass('faq-arrow-down');
			jQuery(this).addClass('faq-arrow-up');
		} else if ( jQuery(this).hasClass('faq-arrow-up') ) {
			jQuery(this).removeClass('faq-arrow-up');
			jQuery(this).addClass('faq-arrow-down');
		}
		
		var eventCaller;
		
		if (window.addEventListener) {
			eventCaller = e.target;
		} else {
			eventCaller = window.event.srcElement;
		}
		
		var nextSibling = eventCaller.nextSibling;
		
		while(nextSibling != undefined) {
			if ( typeof (nextSibling.tagName) == 'string' ) {
				nextSibling.style.display = (nextSibling.style.display == 'none' || nextSibling.style.display == '') ? 'block' : 'none';
				// jQuery(this).next().toggle();
			}
			nextSibling = nextSibling.nextSibling;
		}
	});
});
/******************************************************/
/******************************************************
	jCarousel CONFIGURATION
******************************************************/

jQuery(document).ready( function() {
	jQuery("#home_slider .jCarouselLite").jCarouselLite({
		btnNext: "#home_slider .next a",
		btnPrev: "#home_slider .prev a", 
		visible: 5
	});
});

jQuery(document).ready( function() {
	jQuery(".slide_carerange").jCarouselLite({
		btnNext: "a.forward_care",
		btnPrev: "a.back_care", 
		visible: 4,
		circular: false
		
	});
});

jQuery(document).ready( function() {
	jQuery(".slide_rescuerange").jCarouselLite({
		btnNext: "a.forward_rescue",
		btnPrev: "a.back_rescue", 
		visible: 4,
		circular: false
	});
});

jQuery(document).ready( function() {
	jQuery(".slide_salts").jCarouselLite({
		btnNext: "a.forward_salts",
		btnPrev: "a.back_salts", 
		visible: 4,
		circular: false
	});
});

jQuery(document).ready( function() {
	jQuery(".slide_single").jCarouselLite({
		btnNext: "a.forward_single",
		btnPrev: "a.back_single", 
		visible: 4,
		circular: false
	});
});


/******************************************************/
/******************************************************
	FUNCTIONS TO EMPTY AND RE-FILL A TEXT FIELD
******************************************************/

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

/******************************************************/
/******************************************************
	FUNCTION TO VALIDATE SITE SEARCH FORM
******************************************************/

/*
function validate_sitesearch(){
	
	var bError = 0
	
	if(document.frm_search.txt_search.value == "" || toLowerCase(document.frm_search.txt_search.value) == 'search site'){
		if(bError==0){
			alert("Please enter a search.")
			bError=1
			return false
		}
	}

	
				
	if(bError==0){
		document.frm_search.submit()
	}
}
*/


/******************************************************/
