jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

function hideMail(el, name, site, ext){
	var z = 'mail'+'to';
	var str = '<a href="'+z+'&#58;'+name+'&#64;'+site+'&#46;'+ext+'"> '+name+'&#64;'+site+'&#46;'+ext+'</a>';
	jQuery("."+el).html(str);
}
function winOpen(pageurl) {
	window.open(pageurl,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=350,height=400,left=50,top=200');
}

function reset_fields(){
	jQuery("#gt-2").hide();
	jQuery("#ogt3").hide();
}
function dolist(html){
	jQuery("#gt-2").html(html);
	jQuery("#gt-2").show();
	get_price();
	bind_service();
}
function donolist(html){
	jQuery("#gt-2").html(html);
	jQuery("#gt-2").show();
}
function remove_this(){
	jQuery(this).parent().remove();
}
function show_price(price){
	jQuery("#gt-price").html(price);
}
function get_price(){
	var safename = jQuery("#service").find("option:selected").val();
	var cat = jQuery("#category").find("option:selected").val();
	jQuery.ajax({
		type: "GET",
		data: "&safename="+safename+"&cat="+cat+"&sid="+Math.random(),
		url: "get-list.php",
		success: function(html){
			jQuery("#ogt3").find("#gt-price").html(html);
			jQuery("#ogt3").show();
		},
		error:function (xhr, ajaxOptions, thrownError){
			alert(xhr.status+"\n"+thrownError);
		}
	});
}
function bind_service(){
	jQuery("#service").bind("change", function(){
		get_price();
	});
}
function additem(){
	items = parseInt(jQuery("#allitems").val()) + 1;
	jQuery("#allitems").val(items);
	return items;
}
function removeitem(){
	items = parseInt(jQuery("#allitems").val()) - 1;
	jQuery("#allitems").val(items);
	if(items > 0) reorder_items();
}
function reorder_items(){
	var start = 1;
	jQuery(".gt-cart-item").each(function(){
		jQuery(this).find(".gt-cart-serv").attr("name", "description"+start);
		jQuery(this).find(".gt-cart-price").attr("name", "subtotal"+start);
		jQuery(this).find(".gt-cart-quant").attr("name", "quantity"+start);
		start++;
	});
}
jQuery(function(){
	if($.cookie('totto_cookie')){
		var bolink = $.cookie('totto_cookie');
		if(bolink == 'http://tottospa.com/book-online.php'){
			jQuery("a[href='http://onlinebooking.salonspaware.com/tottosalon/']").attr('href','http://tottospa.com/book-online.php').removeAttr("target");
		}
	} else {
		jQuery("a[href='http://onlinebooking.salonspaware.com/tottosalon/']").addClass('tbshow');
	}
	jQuery('.tbshow').click(function(){
		tb_show('','http://tottospa.com/bookonline-help.php?inlineId=myOnPageContent&amp;modal=true&amp;height=190&amp;width=300');
		return false;
	});
	jQuery('.popup').click(function(){
		winOpen('http://tottospa.com/privacy-policy.php');
		return false;
	});
	jQuery('.terms').click(function(){
		winOpen('http://tottospa.com/terms.php');
		return false;
	});
	
	jQuery("#category").change(function(){
		var cat = jQuery(this).find("option:selected").val();
		if( cat != "0" ){
			reset_fields();
			jQuery.ajax({
				type: "GET",
				data: "&jscat="+cat+"&sid="+Math.random(),
				url: "get-list.php",
				success: function(html){
					if(cat == "6" || cat == "8" || cat == "dollar") donolist(html);
					else dolist(html);
				},
				error:function (xhr, ajaxOptions, thrownError){
					alert(xhr.status+"\n"+thrownError);
				}
			});
		}
	});
	
	if(jQuery("#service").length > 0) bind_service();
	jQuery(".gt-cart-remove").live("click",function(){
		jQuery(this).parent().remove();
		removeitem();
		return false;
	});
	
	jQuery("#gt-dollar-add").live("click", function(){
		var dollar = parseInt( jQuery.trim( jQuery("#service").val() ) );
		var re = /\d/;
		if( dollar && re.test(dollar) ){
			if(jQuery("#allitems").val() <= 5){
				curitem = additem();
				div = '<div class="gt-cart-item">';
				div += '<input type="text" name="name'+curitem+'" class="gt-cart-serv" value="'+jQuery("#category").find("option:selected").html()+'" readonly="readonly" />';
				div += '$<input type="text" name="subtotal'+curitem+'" class="gt-cart-price" value="'+jQuery("#service").val()+'" readonly="readonly" />';
				div += '<input type="hidden" value="1" class="gt-cart-quant" name="quantity'+curitem+'" />';
				div += '<input type="hidden" class="gt-cart-safe" name="description'+curitem+'" value="Dollar Value" />';
				div += '<a href="#" class="gt-cart-remove">remove</a></div>';
				jQuery("#gt-cart").append(div);
			} else {
				alert("Limit of 5 items");
			}
		} else {
			alert("Please Enter a number");
		}
		return false;
	});
	
	jQuery("#gt-price-add").click(function(){
		curitem = additem();
		if(jQuery("#allitems").val() <= 5){
			div = '<div class="gt-cart-item">';
			div += '<input type="text" class="gt-cart-cat" value="'+jQuery("#category").find("option:selected").html()+'" readonly="readonly" />';
			div += '<input type="text" name="name'+curitem+'" class="gt-cart-serv" value="'+jQuery("#service").find("option:selected").html()+'" readonly="readonly" />';
			div += '$<input type="text" name="subtotal'+curitem+'" class="gt-cart-price" value="'+jQuery("#gt-price").html()+'" readonly="readonly" />';
			div += '<input type="hidden" value="1" class="gt-cart-quant" name="quantity'+curitem+'"/>';
			div += '<input class="gt-cart-safe" type="hidden" name="description'+curitem+'" value="'+jQuery("#service").find("option:selected").val()+'" /><a href="#" class="gt-cart-remove">remove</a></div>';
			jQuery("#gt-cart").append(div);
		} else {
			alert("Limit of 5 items");
		}
		return false;
	});
	
	jQuery("#reset-cart").click(function(){
		if(jQuery(".gt-cart-item").length > 0){
			jQuery(".gt-cart-item").remove();
			jQuery("#allitems").val(0);
		}
		return false;
	});
	
	jQuery("#gift-cart").submit(function(){
		if(jQuery(".gt-cart-item").length < 1) return false;
	});
	
	jQuery("#gt-select").submit(function(){
		return false;
	});
});