/***********************************************
* jQuery functions execute
***********************************************/

//bookmark function

function bookmarksite(title,url){
	if (window.sidebar) 
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ 
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
		window.external.AddFavorite(url, title);
}


jQuery(document).ready(function(){                  
	//HideBank Transfer Div
	$("#bankTransfer").css("display","none");
	
	$("#checkme").click(function(){
		// If checked
		if ($("#checkme").is(":checked")) {
			//show theBanktransfer and hide Credit Card
			$("#creditCard").hide("fast");
			$("#bankTransfer").show("fast");
		} else {     
			//hide theBanktransfer and show Credit Card
			$("#creditCard").show("fast");
			$("#bankTransfer").hide("fast");
		} // end if
	})    
	
	/*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();
                                });
                };             
	
	$('body').css('overflow-x', 'hidden');
	$('a[rel*=external]').click( function(){this.target = "_blank";});
	$("#logo").css('cursor', 'pointer').click( function() { window.location = './';});
	/*colorbox*/
	$("a.popup").css('cursor', 'pointer').colorbox();
	$("#add-to-cart").css('cursor', 'pointer').colorbox({width:"500", inline:true, href:"#add-cart_contents"})
	$(".feedbackpopup").css('cursor', 'pointer').colorbox({width:"600", inline:true, href:"#feedback_contents"});
	$(".privacypopup").css('cursor', 'pointer').colorbox({width:"750", inline:true, href:"#privacy_contents"});
	$(".termspopup").css('cursor', 'pointer').colorbox({width:"750", inline:true, href:"#terms_contents"});
	/*rounded corners*/
	/* image for text contents*/
	$('.text-contents').prepend('<div class="text-top">&nbsp;</div>');

	/*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;}});};
	$(".replace_text").search();
	
	/*email protect*/
	$("span.safermailing").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();
	});
			
	/*set hover class for anything*/
	$('#mini-cart').css('cursor', 'pointer').click(function(){window.location = $(this).find('a').attr("href");});
	$('input.searchnow').css('cursor', 'pointer').hover(function() {$(this).addClass('searchhover');}, function() {$(this).removeClass('searchhover');});
	$('form.cmxform input.send, input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	
	/*dimming images on hover*/
	$('.dimmer').css('opacity', '0.55').css('cursor', 'pointer');
	$('.dimmer').hover(function() {$(this).css('opacity', '1.0');}, function() {$(this).css('opacity', '0.55')});
	
	/*advanced hide and show*/
	$('ul.product_range li> ul').hide();
	$('ul.product_range li> a').click(function() {
	$(this).next('ul').slideToggle('fast')
	.parent().siblings('li').find('ul:visible').slideUp('fast');});

});

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

function ValidateForm(f){
	with(f){
		if (isEmpty(fullname.value)) {alert("Please enter your Full Name");fullname.focus();return false;}
		if (isEmpty(email.value)) {alert("Please enter your Email Address");email.focus();return false;}
		if (!isEmail(email.value) ) {alert("Please enter a valid Email Address."); email.focus();return false;}
		if (isEmpty(contact.value)) {alert("Please enter your Contact Number");contact.focus();return false;}
		if (isEmpty(comments.value)) {alert("Please enter your Feedback Comments");comments.focus();return false;}
	}
	return true;
 }
 
 function ValidateForm1(f){
	with(f){
		if (isEmpty(firstname.value)) {alert("Please enter your First Name");firstname.focus();return false;}
		if (isEmpty(lastname.value)) {alert("Please enter your Last Name");lastname.focus();return false;}
		if (isEmpty(email.value)) {alert("Please enter your Email Address");email.focus();return false;}
		if (!isEmail(email.value) ) {alert("Please enter a valid Email Address."); email.focus();return false;}
		if (isEmpty(phone.value)) {alert("Please enter your Phone Number");phone.focus();return false;}
		if (isEmpty(enquiries.value)) {alert("Please enter your Enquiry");enquiries.focus();return false;}
	}
	return true;
 }
