
function show_country_list(country)
{
	document.getElementById('delivery_country_list_america').style.display = 'none';
	document.getElementById('delivery_country_list_rest_of_the_world').style.display = 'none';
	document.getElementById('delivery_country_list_europe').style.display = 'none';
	document.getElementById('region_container_america').className = 'america';
	document.getElementById('region_container_rest_of_the_world').className = 'rest_of_the_world';
	document.getElementById('region_container_europe').className = 'europe';
	
	
	document.getElementById('region_container_'+country).className = country+' active';
	document.getElementById('delivery_country_list_'+country).style.display = 'block';
}


function process_my_profile()
{
	var error = "";
	if(document.getElementById('b_first_name').value=='')
	{
		error+="Please enter your billing first name\n";
	}
	if(document.getElementById('b_last_name').value=='')
	{
		error+="Please enter your billing last name\n";
	}
	if(document.getElementById('b_address1').value=='')
	{
		error+="Please enter the first line of your billing address\n";
	}
	
	if(document.getElementById('b_city').value=='')
	{
		error+="Please enter your billing city\n";
	}
	
	if(document.getElementById('b_postcode').value=='')
	{
		error+="Please enter your billing postcode\n";
	}
	
	if(document.getElementById('b_country').value=='')
	{
		error+="Please enter your billing country\n";
	}
	
	if(document.getElementById('d_first_name').value=='')
	{
		error+="Please enter your delivery first name\n";
	}
	if(document.getElementById('d_last_name').value=='')
	{
		error+="Please enter your delivery last name\n";
	}
	if(document.getElementById('d_address1').value=='')
	{
		error+="Please enter the first line of your delivery address\n";
	}
	
	if(document.getElementById('d_city').value=='')
	{
		error+="Please enter your delivery city\n";
	}
	
	if(document.getElementById('b_postcode').value=='')
	{
		error+="Please enter your delivery postcode\n";
	}
	
	if(document.getElementById('b_country').value=='')
	{
		error+="Please enter your delivery country\n";
	}	
	


	if(error == "")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
	
}
function process_change_password()
{
	var error = "";
	if(document.getElementById('new_password').value=='')
	{
		error+="Please enter your new password\n";
	}
	if(document.getElementById('confirm_password').value=='')
	{
		error+="Please confirm your new password\n";
	}
	if(document.getElementById('new_password').value!='' && document.getElementById('confirm_password').value!='' && document.getElementById('new_password').value != document.getElementById('confirm_password').value)
	{
		error+="Your passwords do not match\n";
	}
	if(error == "")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
}
function move_up(num)
{
	var x = num*322;
	$("#product_image").animate({right:x+'px'},{queue:false,duration:100});
	
}

function show_lrg(id,basepath,ref)
{

	document.getElementById('imgimg').src=basepath+'/include/file.php?product_ref='+ref+'&t=product&image_num='+id;
	document.getElementById('jqzoom_product').href=basepath+'/image/product/'+ref+'/'+id+'.jpg';
	
	setTimeout('$(".jqzoom").jqzoom();',1);
	
}
function text_counter(field,maxlimit) 
{
	if (document.getElementById(field).value.length <= maxlimit) // if too long...trim it!
		document.getElementById('char_cnt_'+field).innerHTML = maxlimit - document.getElementById(field).value.length;
	else
		document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
		
}
function clearthis(id,txt)
{
	if(document.getElementById(id).value == txt)
	{
		document.getElementById(id).value='';
	}
}
function checkthis(id,txt)
{
	if(document.getElementById(id).value == '')
	{
		document.getElementById(id).value = txt;
	}
}

function toggle_overlay(id,dir)
{

	var x = "#overlay_"+id;
	if(dir=="on")
	{
		$(x).animate({left:'-118px'},{queue:false,duration:300});
	}
	else
	{
		$(x).animate({left:'0px'},{queue:false,duration:300});
	}

}

function toggle_box(id,div,type)
{
	switch(type)
	{
		case "radio":
			if(id.value == '1')
			{
				document.getElementById(div).style.display = 'block';
			}
			else
			{
				document.getElementById(div).style.display = 'none';
			}
		break;
	}
}

function toggle_password_visibility()
{
	if(document.getElementById('change_password').checked==true)
	{
		document.getElementById('password').disabled=false;
		document.getElementById('confirm_password').disabled=false
	}
	else
	{
		document.getElementById('password').disabled=true;
		document.getElementById('confirm_password').disabled=true;
	}		
}

function newsletter_subscription(basepath)
{
	if(document.getElementById('name').value=='Name' || document.getElementById('email').value=='Email address' || document.getElementById('name').value=='' || document.getElementById('email').value=='')
	{
		alert("Please enter your name and email address");
	}
	else
	{
	
		$.ajax({
			beforeSend: function () {document.getElementById('subscribe_to_newsletter').innerHTML = '<h1>subscribe to<br />our newsletter</h1><div style="text-align:center;width:170px;padding-top:50px;"><img src="'+basepath+'/image/loading.gif" /></div>';}, 
			type: "POST",
			url: basepath+"/process/newsletter_subscription.php",
			data: "name="+document.getElementById('name').value+"&email="+document.getElementById('email').value,
			  
			success: function(html){
				if(html == "1")
				{
					document.getElementById('subscribe_to_newsletter').innerHTML = '<h1>subscribe to<br />our newsletter</h1><p>Thank you for subscribing to our free newsletter</p>';
				}
				else
				{
					alert('There was a problem processing your subscription');
				}
			}
		});
		
	}
	return false;
}

function send_slider_login_form(basepath)
{
	if(document.getElementById('slider_email').value=='' || document.getElementById('slider_password').value=='')
	{
		document.getElementById('slider_error_message').style.display = 'block';
		document.getElementById('slider_error_message').innerHTML = 'Email and password required';
	}
	else
	{
		$.ajax({
			beforeSend: function () {document.getElementById('slider_login_button').innerHTML = '<img src="'+basepath+'/image/loading.gif" /></div>';}, 
			type: "POST",
			url: basepath+"/process/login.php",
			data: $("#slider_login_form").serialize(),
			  
			success: function(html){
				if(html != "")
				{
					
					var expiredays = 30;
					var exdate=new Date();
					exdate.setDate(exdate.getDate()+expiredays);
					document.cookie="lovemomiji"+ "=" +document.getElementById('auth').value+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
			
					location.href=document.getElementById('request_uri').value;
					
				}
				else
				{
					document.getElementById('slider_error_message').style.display = 'block';
					document.getElementById('slider_error_message').innerHTML = 'Login failed';
					document.getElementById('slider_login_button').innerHTML = '<div class="btn slider_login"><input type="image" id="login" name="login" src="'+basepath+'/image/button/login.jpg" /></div>';
					
				}
			}
		});
	}
	return false;
}
function send_blog_reply_form(basepath,blog_entry_id)
{
	if(document.getElementById('message').value=='')
	{
		alert("Please enter your message");
	}
	else
	{
		$.ajax({
			beforeSend: function () {document.getElementById('comment_form_container').innerHTML = '<div style="text-align:center;width:470px;padding-top:50px;"><img src="'+basepath+'/image/loading.gif" /></div>';}, 
			type: "POST",
			url: basepath+"/process/send_blog_reply.php",
			data: "message="+document.getElementById('message').value+'&blog_entry_id='+blog_entry_id,
			  
			success: function(html){
				if(html == "1")
				{
					document.getElementById('comment_form_container').innerHTML = '<h2>Thank you for your comments</h2><p>Thanks for taking the time to submit your comments</p>';
				}
				else
				{
					alert('There was a problem processing your comment');
				}
			}
		});
		
	}
	return false;
}

function process_login_form()
{
	var error = "";
	if(document.getElementById('email').value=="")
	{
		error += "Please enter your email\n";
	}
	if(document.getElementById('password').value=="")
	{
		error += "Please enter your password\n";
	}
	if(error=="")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;		
	}	
}

function process_product_form()
{
	var error = "";
	if(document.getElementById('qty').value=="")
	{
		error += "Please select a quantity\n";
	}
	if(document.getElementById('add_personal_message').checked== true && document.getElementById('personal_message').value=="")
	{
		error += "Please enter your personal message\n";
	}
	if(error=="")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;		
	}
}
function process_payment_form()
{
	var error = "";
	if(document.getElementById('cardholder_name').value=="")
	{
		error += "Please enter the cardholder name\n";
	}
	if(document.getElementById('card_number').value=="")
	{
		error += "Please enter the card number\n";
	}
	if(document.getElementById('card_type').value=="")
	{
		error += "Please select a card type\n";
	}
	if(document.getElementById('expiry_date').value=="")
	{
		error += "Please enter the expiry date\n";
	}
	if(document.getElementById('cvv_code').value=="")
	{
		error += "Please enter the cvv code\n";
	}
	
	if(error=="")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;		
	}
}

function process_billing_and_shipping(basepath, website_region)
{
	var error = "";
	var RE_EMAIL = /^(\w+[\-\.])*\w+@(\w+[\-\.])+[A-Za-z]+$/;
		
	if(document.getElementById('d_country').value=="")
	{
		error += "Please select your delivery country\n";
	}
	if(document.getElementById('d_first_name').value=="")
	{
		error += "Please enter your first name\n";
	}
	if(document.getElementById('d_last_name').value=="")
	{
		error += "Please enter your last name\n";
	}
	if(document.getElementById('d_address1').value=="")
	{
		error += "Please enter the first line of your address \n";
	}
	
	if(document.getElementById('d_city').value=="")
	{
		error += "Please enter your city\n";
	}
	if(document.getElementById('d_postcode').value=="")
	{
		error += "Please enter your postcode\n";
	}
	if(document.getElementById('email').value=="")
	{
		error += "Please enter your email\n";
	}
	else if (!RE_EMAIL.test(document.getElementById('email').value)) 
	{
		error += "Please enter a valid email address\n";
	}
	if(document.getElementById('tel').value=="")
	{
		error += "Please enter your contact number\n";
	}
	
	if(document.getElementById('delivery_address').checked==true)
	{
		if(document.getElementById('b_country').value=="")
		{
			error += "Please select your billing country\n";
		}
		if(document.getElementById('b_first_name').value=="")
		{
			error += "Please enter your billing first name\n";
		}
		if(document.getElementById('b_last_name').value=="")
		{
			error += "Please enter your billing last name\n";
		}
		if(document.getElementById('b_address1').value=="")
		{
			error += "Please enter the first line of your billing address \n";
		}
		
		if(document.getElementById('b_city').value=="")
		{
			error += "Please enter your billing city\n";
		}
		if(document.getElementById('b_postcode').value=="")
		{
			error += "Please enter your billing postcode\n";
		}
	}
	
	if(document.getElementById('terms').checked == false)
	{
		error += "Please agree to the terms and conditions\n";
	}
	
	if(website_region == 'USWEB' && document.getElementById('us_delivery_type').value=="")
	{
		error += "Please select your delivery address type\n";
	}
	
	if(error == "")
	{
		$.ajax({
			type: "POST",
			url: basepath+"/process/check_register_email.php",
			data: "email="+document.getElementById('email').value,
			success: function(html){
				if(html == "1")
				{
					return false;
				}
				else
				{
					return true;
				}
			
			}
		
		});
	
	}
	else
	{
		alert(error);
		return false;
	}
}

function validate_registration_form(basepath)
{
	var error = "";
	if(document.getElementById('first_name').value=="")
	{
		error += "Please enter your first name\n";
	}
	if(document.getElementById('last_name').value=="")
	{
		error += "Please enter your last name\n";
	}
	if(document.getElementById('email').value=="")
	{
		error += "Please enter your email\n";
	}
	
	if(document.getElementById('password').value=="")
	{
		error += "Please enter your password\n";
	}
	if(document.getElementById('confirm_password').value=="")
	{
		error += "Please confirm your password\n";
	}
	if(document.getElementById('password').value != document.getElementById('confirm_password').value)
	{
		error += "Password mismatch\n";
	}
	
	if(document.getElementById('terms').value=="")
	{
		error += "Password agree to the terms and conditions\n";
	}
	
	if(error == "")
	{
		$.ajax({
			type: "POST",
			url: basepath+"/process/check_register_email.php",
			data: "email="+document.getElementById('email').value,
			  
			success: function(html){
				if(html == "0")
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		});
		
	}
	else
	{
		alert(error);
		return false;
	}
}

function show_div(id)
{
	
	  $("#"+id).animate({ 
        width: "100px",
        paddingLeft:"20px"
      }, 500 );
    
}
function hide_div(id)
{
	
	  $("#"+id).animate({ 
        width: "0px",
        display: "none"
      }, 500 );
    
}

$(document).ready(function(){
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.boxgrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});
	//Horizontal Sliding
	$('.home_text.slideright').hover(function(){
		$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	//Diagnal Sliding
	$('.boxgrid.thecombo').hover(function(){
		$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
	});
	//Partial Sliding (Only show some of background)
	$('.boxgrid.peek').hover(function(){
		$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});
	//Full Caption Sliding (Hidden to Visible)
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:160});
	});
	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});
	});
	
});

/*
$(document).ready(function(){
    
    $('#add_to_basket').click(function () {
    	
	   	$.ajax({
<!--			beforeSend: function () {document.getElementById('subscribe_to_newsletter').innerHTML = '<h1>subscribe to<br />our newsletter</h1><div style="text-align:center;width:170px;padding-top:50px;"><img src="'+basepath+'/image/loading.gif" /></div>';},--> 
			type: "POST",
			url: "../process/add_to_basket.php",
			data: $("#product_form").serialize(),
			  
			success: function(html){
			document.getElementById('basket_summary_slider').innerHTML = html;
				if ($("#basket_summary_slider").is(":hidden")) {
			        $("#basket_summary_slider")
			        .slideDown()
			         .animate({opacity: 1.0}, 3000)
			         .slideUp();
			      } else {
			        $("#basket_summary_slider").hide();
			      }
			}
		});
    	
      
    });

  });
*/
function toggle_product_info_container(box)
{
	switch(box)
	{
		case "info":
			document.getElementById('product_info_container_link_delivery').className='';
			document.getElementById('product_info_container_link_info').className='active';
			$("#product_info_wrap").stop().animate({left:'0px'},{queue:false,duration:300});
		break;
		case "delivery":
			document.getElementById('product_info_container_link_info').className='';
			document.getElementById('product_info_container_link_delivery').className='active';
			$("#product_info_wrap").stop().animate({left:'-320px'},{queue:false,duration:300});
		break;
	}
}
function toggle_summary_slider(type)
{
	if(type=="basket")
	{
		if ($("#basket_summary_slider").is(":hidden")) {
	       $("#basket_summary_slider")
	       .slideDown('fast')
	        .animate({opacity: 1.0}, 3000)
	        .slideUp();
	     } else {
	       $("#basket_summary_slider").hide();
	     }
	}
	else if(type="login")
	{
		if ($("#login_slider").is(":hidden")) {
	       $("#login_slider")
	       .slideDown()
	     } else {
	       $("#login_slider")
	       .slideUp()
	     }
	
	}
	
}
function close_live_search_results_inner()
{
document.getElementById('live_search_results').style.display = 'none';
}

function hide_confirm_delete_msg(id)
{
	var x = "#confirm_delete_msg_"+id;
	$(x).animate({left:'-670px'},{queue:false,duration:300});
}
function basket_confirm_delete(id)
{
	var x = "#confirm_delete_msg_"+id;
	$(x).animate({left:'0px'},{queue:false,duration:300});
}
function add_wishlist_item_to_basket(id,basepath,price)
{

	var x = "#confirm_delete_msg_"+id;
	var y = "#basket_row_"+id;
	
	$.ajax({
		type: "POST",
			url: basepath+"/process/add_wishlist_item_to_basket.php",
			data: "product_detail_id="+id+"&price="+price+"&qty=1",
			success: function(html){
				$(x).animate({left:'-670px'},{queue:false,duration:300});
				$(y).animate({opacity: 0}, 1500).slideUp();
			},
			error: function(html){
				alert(html)
			}
	});
}

function delete_from_basket(id,basepath,type)
{
	var x = "#confirm_delete_msg_"+id;
	var y = "#basket_row_"+id;
	if(type == "basket")
	{
		var path = basepath+"/process/delete_basket_order_item.php";
	}
	else if(type == "wishlist")
	{
		var path = basepath+"/process/delete_wishlist_order_item.php";
	}
	$.ajax({
		type: "POST",
			url: path,
			data: "order_detail_id="+id,
			success: function(html){
				$(x).animate({left:'-670px'},{queue:false,duration:300});
				$(y).animate({opacity: 0}, 1500).slideUp();
				document.getElementById('basket_summary_item_'+id).innerHTML='';
				
				price_array = html.split('|');
				if(price_array[0] > 0)
				{
					document.getElementById('basket_sub_total').innerHTML=price_array[2]+price_array[0];
					document.getElementById('basket_total').innerHTML=price_array[2]+price_array[1];
					document.getElementById('basket_summary_item_sub_total').innerHTML=price_array[2]+price_array[0];
					
				}
				else
				{ 
					$('#basket_total_container').animate({opacity: 0}, 1500).slideUp();
					$('#basket_sales_option').animate({opacity: 0}, 1500).slideUp();
					$('#basket_titles').animate({opacity: 0}, 1500).slideUp();
					document.getElementById('num_basket_summary_items').innerHTML = '0 items';
					setTimeout("document.getElementById('basket_container').innerHTML='Your basket is empty';",1500);
					document.getElementById('basket_summary_slider').innerHTML ='<h1>basket summary</h1>Your basket is empty';
				}
			},
			error: function(html){
				alert(html)
			}
	});
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function close_archive()
{
	$('#story_archive_detail_container').animate({opacity: 0}, 750);
	setTimeout("document.getElementById('story_archive_detail_container').style.display = 'none';",750);
	
}
function show_archive(story_product_id, top, basepath)
{
	$('#story_archive_detail_container').animate({opacity: 0}, 750);
	setTimeout("document.getElementById('story_archive_detail_container').style.display = 'none';",750);
	$.ajax({
		type: "POST",
			url: basepath+"/process/get_story_archive_details.php",
			data: "story_product_id="+story_product_id,
			success: function(html){
				
				setTimeout("document.getElementById('story_archive_detail_container').style.display = 'block';",750);
				document.getElementById('story_archive_detail_container').innerHTML=html;
				/*document.getElementById('story_archive_detail_container').style.marginTop = top;*/
				setTimeout("$('#story_archive_detail_container').animate({top:"+top+"+'px'},{queue:false,duration:100});",750);
								
				setTimeout("$('#story_archive_detail_container').animate({opacity: 1}, 750);",750);
			},
			error: function(html){
				alert(html)
			}
	});
}
function remove_basket_message(id,basepath)
{
	var price_array = new Array();
	$.ajax({
		type: "POST",
		url: basepath+"/process/remove_basket_order_item_message.php",
		data: "order_detail_id="+id,
		success: function(html){
		
			price_array = html.split('|');
			document.getElementById('item_total_'+id).innerHTML=price_array[3]+price_array[0];
			document.getElementById('basket_sub_total').innerHTML=price_array[3]+price_array[1];
			document.getElementById('basket_total').innerHTML=price_array[3]+price_array[2];
			
			/*document.getElementById('basket_giftwrap_'+id).innerHTML="<a href=\"javascript:void(0);\" class=\"active\" onclick=\"toggle_basket_giftwrap('"+id+"','add','"+basepath+"')\" >add</a>";*/
			document.getElementById('basket_personal_message_textbox_'+id).style.display = 'none';
			document.getElementById('basket_personal_message_text_'+id).style.display = 'none';
			document.getElementById('basket_personal_message_'+id).innerHTML = "<a href=\"javascript:void(0);\" class=\"active\" onclick=\"document.getElementById('basket_personal_message_text_"+id+"').style.display = 'none'; document.getElementById('basket_personal_message_textbox_"+id+"').style.display = 'block';\">add</a>";
			document.getElementById('basket_presonal_message_price_'+id).innerHTML=price_array[3]+'0.00';
		},
		error: function(html){
			alert(html)
		}
	});
	
	return false;
}
function add_delivery(freight_method_guid,basepath)
{
	var price_array = new Array();
	$.ajax({
		type: "POST",
		url: basepath+"/process/update_basket_delivery.php",
		data: "freight_method_guid="+freight_method_guid,
		success: function(html){
			price_array = html.split('|');
			document.getElementById('basket_shipping').innerHTML=price_array[3]+price_array[0];
			document.getElementById('basket_sub_total').innerHTML=price_array[3]+price_array[1];
			document.getElementById('basket_total').innerHTML=price_array[3]+price_array[2];
		},
		error: function(html){
			alert(html)
		}
	});
	
	return false;
}
function add_basket_message(id,basepath)
{
	var price_array = new Array();
	$.ajax({
		type: "POST",
		url: basepath+"/process/update_basket_order_item_message.php",
		data: "order_detail_id="+id+"&message="+document.getElementById('basket_personal_message_textbox_'+id).value,
		success: function(html){
			price_array = html.split('|');
			document.getElementById('item_total_'+id).innerHTML=price_array[5]+price_array[0];
			document.getElementById('basket_sub_total').innerHTML=price_array[5]+price_array[1];
			document.getElementById('basket_total').innerHTML=price_array[5]+price_array[2];
			
			/*document.getElementById('basket_giftwrap_'+id).innerHTML="<a href=\"javascript:void(0);\" class=\"active\" onclick=\"toggle_basket_giftwrap('"+id+"','add','"+basepath+"')\" >add</a>";*/
			document.getElementById('basket_personal_message_textbox_'+id).style.display = 'none';
			document.getElementById('basket_personal_message_text_'+id).style.display = 'block';
			document.getElementById('basket_personal_message_text_'+id).innerHTML=document.getElementById('basket_personal_message_textbox_'+id).value;
			document.getElementById('basket_personal_message_'+id).innerHTML ="<a href=\"javascript:void(0);\" class=\"active\" onclick=\"document.getElementById('basket_personal_message_text_"+id+"').style.display = 'none'; document.getElementById('basket_personal_message_textbox_"+id+"').style.display = 'block';\">edit</a> | <a href=\"javascript:void(0);\" onclick=\"remove_basket_message('"+id+"','"+basepath+"');\" class=\"active\">remove</a>";
			
			document.getElementById('basket_presonal_message_price_'+id).innerHTML=price_array[5]+price_array[4];
	
		},
		error: function(html){
			alert(html)
		}
	});
	
	return false;
}

function toggle_basket_giftwrap(id,type,basepath)
{
	var price_array = new Array();
	$.ajax({
		type: "POST",
		url: basepath+"/process/update_basket_order_item_giftwrap.php",
		data: "order_detail_id="+id+"&type="+type,
		success: function(html){
		
			price_array = html.split('|');
			document.getElementById('item_total_'+id).innerHTML=price_array[5]+price_array[0];
			document.getElementById('basket_sub_total').innerHTML=price_array[5]+price_array[1];
			document.getElementById('basket_total').innerHTML=price_array[5]+price_array[2];
			switch(type)
			{
				case "add":
					document.getElementById('basket_giftwrap_'+id).innerHTML="<a href=\"javascript:void(0);\" class=\"active\" onclick=\"toggle_basket_giftwrap('"+id+"','remove','"+basepath+"')\" >remove</a>";
					document.getElementById('basket_giftwrap_price_'+id).innerHTML=price_array[5]+price_array[3];
				break;
				case "remove":
					document.getElementById('basket_giftwrap_'+id).innerHTML="<a href=\"javascript:void(0);\" class=\"active\" onclick=\"toggle_basket_giftwrap('"+id+"','add','"+basepath+"')\" >add</a>";
					document.getElementById('basket_giftwrap_price_'+id).innerHTML=price_array[5]+price_array[3];
				break;
			}
		},
		error: function(html){
			alert(html)
		}
	});
	
}
function update_basket_qty(id, type, basepath)
{
	var current_value = parseInt(document.getElementById("basket_qty_"+id).value);
	var new_value = ""; 
	if(type == "plus")
	{
		new_value = current_value+1;
	}
	else if(type == "minus")
	{
		if(current_value > 1)
		{
			new_value = current_value-1;
		}
		else
		{
			new_value = current_value;
		}
	}
	if(current_value > 1)
	{
		var price_array = new Array();
		$.ajax({
			type: "POST",
			url: basepath+"/process/update_basket_order_item_qty.php",
			data: "order_detail_id="+id+"&qty="+new_value,
			success: function(html){
				price_array = html.split('|');
				document.getElementById('item_total_'+id).innerHTML=price_array[5]+price_array[0];
				document.getElementById('basket_giftwrap_price_'+id).innerHTML=price_array[5]+price_array[3];
				document.getElementById('basket_presonal_message_price_'+id).innerHTML=price_array[5]+price_array[4];
				document.getElementById('basket_sub_total').innerHTML=price_array[5]+price_array[1];
				document.getElementById('basket_total').innerHTML=price_array[5]+price_array[2];
			},
			error: function(html){
				alert(html)
			}
		});
	}
	
	document.getElementById("basket_qty_"+id).value = new_value;
	return false;
}

function toggle_tip(row,type,elem)
{
	var error = "";
	var success = "";
	var tip = "";
	var RE_EMAIL = /^(\w+[\-\.])*\w+@(\w+[\-\.])+[A-Za-z]+$/;
	switch(type)
	{
		case "email":
			if(elem.value==""){tip = "Please enter your email";}
			else if (!RE_EMAIL.test(elem.value)){error = "Please enter a valid email address";}
			else{success = "OK";}
		break;
		case "b_country":
			if(elem.value==""){tip = "Please select your billing country";}
			else{success = "OK";}
		break;
		case "us_delivery_type":
			if(elem.value==""){tip = "Please select the address type";}
			else{success = "OK";}
		break;
		case "b_address1":
		case "d_address1":
			if(elem.value==""){tip = "Please enter address line 1";}
			else{success = "OK";}
		break;
		case "b_address2":
		case "d_address2":
			if(elem.value==""){tip = "Please enter address line 2";}
			else{success = "OK";}
		break;
		case "b_city":
		case "d_city":
			if(elem.value==""){tip = "Please enter your city";}
			else{success = "OK";}
		break;
		case "b_postcode":
		case "d_postcode":
			if(elem.value==""){tip = "Please enter your postcode";}
			else{success = "OK";}
		break;
		case "tel":
			if(elem.value==""){tip = "Please select your contact number";}
			else{success = "OK";}
		break;
		case "gender":
			if(elem.value==""){tip = "Please select your gender";}
			else{success = "OK";}
		break;
		case "first_name":
			if(elem.value==""){tip = "Please enter your first name";}
			else{success = "OK";}
		break;
		case "d_country":
			if(elem.value==""){tip = "Please enter your delivery country";}
			else{success = "OK";}
		break;
		case "last_name":
			if(elem.value==""){tip = "Please enter your last name";}
			else{success = "OK";}
		break;
		case "age":
			if(elem.value==""){tip = "Please enter your age";}
			else{success = "OK";}
		break;
		case "password":
			if(elem.value==""){tip = "Please enter your password";}
			else{success = "OK";}
		break;
		case "confirm_password":
			if(elem.value==""){tip = "Please confirm your password";}
			else if (elem.value!=document.getElementById('password').value){error = "Passwords do not match";}
			else{success = "OK";}
		break;
		
		case "cardholder_name":
			if(elem.value==""){tip = "Please the card holder's name";}
			else{success = "OK";}
		break;
		case "card_number":
			if(elem.value==""){tip = "Please the card number";}
			else{success = "OK";}
		break;
		case "card_type":
			if(elem.value==""){tip = "Please select your card type";}
			else{success = "OK";}
		break;
		case "expiry_date":
			if(elem.value==""){tip = "Please add your expiry date (MM/YY)";}
			else{success = "OK";}
		break;
		case "start_date":
			if(elem.value==""){tip = "Please add your start date (MM/YY)";}
			else{success = "OK";}
		break;
		case "cvv_code":
			if(elem.value==""){tip = "Please add your cvv code";}
			else{success = "OK";}
		break;
		case "issue_num":
			if(elem.value==""){tip = "Please add your issue number";}
			else{success = "OK";}
		break;
		
	}
	if(tip!="")
	{
		document.getElementById(row).className = 'form_tip tip';
		document.getElementById(row).innerHTML = tip;
	}
	if(error!="")
	{
		document.getElementById(row).className = 'form_tip error';
		document.getElementById(row).innerHTML = error;
	}
	if(success!="")
	{
		document.getElementById(row).className = 'form_tip success';
		document.getElementById(row).innerHTML = success;
	}
	$('#'+row).stop().animate({left:'0px'},{queue:false,duration:300});
}
function close_tip(row)
{
	$('#'+row).stop().animate({left:'-200px'},{queue:false,duration:300});
}

function search_suggest(basepath,site_section_id,region)
{
	$.ajax({
		type: "POST",
		url: basepath+"/process/live_search.php",
		data: $("#search_text").serialize(),
		success: function(html){
			var a = new Array();
			a = html.split('|');
			if(a[0]==1)
			{		
				document.getElementById('live_search_results').style.display = 'block';
				document.getElementById('live_search_results_inner').innerHTML = a[1];
				document.getElementById('search_href_link').href=basepath+"/shop/"+region+"/search_results/"+document.getElementById('search').value+"/name/name/1/1";
			}
			else
			{
				document.getElementById('live_search_results').style.display = 'none';
			}
		}
	});
}