var dm = ('https:' == document.location.protocol ? $('base').attr('href').replace('http:', 'https:') : $('base').attr('href'));
function show_cart(){
	if($("#cart").css('display') == 'block'){ $("#cart").slideUp(300).delay(800); } $("#cart").slideDown("slow");
}
function get_cart_item(p, a){	
	var url = "ajaxfun/getCartLastItem/"+p+"/"+a;
	$.ajax({ url: url, type: "GET", dataType: 'json', cache: false, success: function(datas){
			var citem_content;
			if(datas.citem != ''){
				citem_content = '<div id="product_pic"><a href="prods/' + datas.citem.prod_id + '" title=""><img src="' + datas.citem.prod_thumb +'" alt="' + datas.citem.prod_name + '" /></a></div><div id="product_infor"><span class="gray">' + datas.citem.prod_name + '</span><br />' ;
					if(datas.citem.prod_attr != ''){ citem_content += '<span class="black">' + datas.citem.prod_attr + '</span><br />'; }
					citem_content += _ge('cart_item_price') + ' <span class="orange">' + datas.citem.prod_price + '</span><br />' + _ge('cart_item_qty') + ' <span class="black">' + datas.citem.prod_qty + '</span>' + '</div>';				
				$('#cart_content').html(citem_content); $('#total_price').html(datas.amt); 
			}
			else{
				$('#cart_content').html('<div id="product_infor">' + _ge('cart_no_item') + '</div>');
			}
		}
	});	
}
function reload_item_cart(){ var url = "ajaxfun/getCartItemCounts"; $.ajax({ url: url, type: "GET", cache: false, success: function(itm_msg){ $("#citems").html(itm_msg); $("#total_count").html(itm_msg); } }); }
//function get_cart_amt(){ $.ajax({ url: "ajaxfun/getCartAmt", type: "GET", cache: false, success: function(amts){ $('#total_price').html(amts); } }); } function get_cart_list(){ var url = "ajaxfun/getCartList"; $.ajax({ url: url, type: "GET", dataType: 'json', cache: false, success: function(result){ $.each(result, function(i, citem){ }); } }); }
function reload_cart(){ reload_item_cart(); }

function checkLength(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass('ui-state-error');
		updateTips("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}

}

//To Validate Tax ID
function ValidateTaxID(sTaxID){
	try{
		var i; var a1, a2, a3, a4, a5; var b1, b2, b3, b4, b5; var c1, c2, c3, c4; var d1, d2, d3, d4, d5, d6, d7; var cd8;
	
		if(sTaxID.length != 8) return false;
	
		var c; for (i = 0; i < 8; i++){ c = sTaxID.charAt(i); if ("0123456789".indexOf(c) == -1) return false; }
	
		d1 = parseInt(sTaxID.charAt(0)); d2 = parseInt(sTaxID.charAt(1)); d3 = parseInt(sTaxID.charAt(2)); d4 = parseInt(sTaxID.charAt(3)); d5 = parseInt(sTaxID.charAt(4)); d6 = parseInt(sTaxID.charAt(5)); d7 = parseInt(sTaxID.charAt(6)); cd8 = parseInt(sTaxID.charAt(7));
		c1 = d1; c2 = d3; c3 = d5; c4 = cd8;
		
		a1 = parseInt((d2 * 2) / 10); b1 = (d2 * 2) % 10;
		a2 = parseInt((d4 * 2) / 10); b2 = (d4 * 2) % 10;
		a3 = parseInt((d6 * 2) / 10); b3 = (d6 * 2) % 10;		
		a4 = parseInt((d7 * 4) / 10); b4 = (d7 * 4) % 10;		
		a5 = parseInt((a4 + b4) / 10); b5 = (a4 + b4) % 10;
		
		if((a1 + b1 + c1 + a2 + b2 + c2 + a3 + b3 + c3 + a4 + b4 + c4) % 10 == 0) return true;		
		if(d7 = 7){
			if((a1 + b1 + c1 + a2 + b2 + c2 + a3 + b3 + c3 + a5 + c4) % 10 == 0) return true;
		}
	
		return false;
	}
	catch(e){
		return false;
	}
}

$(function(){	
	$(document).click(function(e) { if (e.button == 0) { $("#cart").slideUp(300); } });
	
	

	// Search
	$('#search_form').submit(function(){ if($('#keywords').val() != ''){ var hurl = $('#search_form').attr("action"); $('#search_form').attr("action", hurl+"search/index/"); return true; } return false; });
	$('.search_submit').click(function(){ $('#search_form').submit(); });	
	$('#keywords').click(function(){ if($(this).val()===$(this).attr('alt')){ $(this).val(''); } }).blur(function(){ if($(this).val().length === 0 ){ $(this).val($(this).attr('alt')); }	
	});
	
	/*cart items*/ $('#mini_cart').live('mouseover mouseleave', function(event){if(event.type == 'mouseover'){$(this).find('span').removeClass();$(this).find('span').addClass('color_green');}else{$(this).find('span').removeClass();$(this).find('span').addClass('color_orange');}});reload_cart(); 
	/*setting*/$('.input_only_number').numeric();	
	/*shopping cart*/ $('#close').click(function(){ document.getElementById("cart").style.display = "none"; });
			
	// /*for menu*/
	// var mimg;
	// //if($("img[name='menu_0']").attr('source').indexOf("_hover", 0) > 0){ //	$('div.navbg').css('height', '70px'); //} //else{
	// $('div.navbg').css('height', '55px');
	// //}
	// var mchild=$('ul.sf-menu > li').length-1;
	// $('ul.sf-menu > li:lt('+mchild+')').mouseover(function(){		
		// mimg = $(this).children().find('img');		
		// //if(mimg.attr('name') == 'menu_0'){ //	$('div.navbg').css('height', '70px'); //} //else{
		// $('div.navbg').css('height', '55px');
		// //}
		// src = mimg.attr('src');
		
		// if(src.indexOf("_hover", 0) < 0) {
			// ext=src.substr(src.lastIndexOf('.'), src.length);			
			// pfix=src.substring(0, src.indexOf(ext));
			// hsrc=pfix+'_hover'+ext;		
			// mimg.attr('src', hsrc);
		// }
	// }).mouseout(function(){	
		// ming = $(this).children().find('img');		
		// //if($("img[name='menu_0']").attr('source').indexOf("_hover", 0) > 0){ //$('div.navbg').css('height', '70px'); //} //else{
		// $('div.navbg').css('height', '55px');
		// //}
		// if(ming.attr('source').indexOf("_hover", 0) < 0){			
			// src = mimg.attr('src').replace('_hover', '');
			// mimg.attr('src', src);
		// }
	// });
	// $("ul.sf-menu").superfish({ pathClass: 'current', delay: 100 });
	
	var li_class='',menu_img='',line_img='',menu_line_class='', mline='', mclass='';
	$('.top_menu ul > li').mouseover(function(){
		//li_class = $(this).attr('class');
		//menu_line_class = $('#menu_line').attr('class');
		/*switch($(this).index()){
			case 0:
				mclass = 'li_roll';
				//mline = 'blue_line';
				break;
			case 1:
				mclass = 'li_roll2';
				//mline = 'pink_line';
				break;
			case 2:
				mclass = 'li_roll3';
				//mline = 'white_line';
				break;
			case 3:
				mclass = 'li_roll4';
				//mline = 'orange_line';
				break;
		}				
		$(this).attr('class', mline);*/
		
		menu_img = $(this).find('img').attr('src');
		if(menu_img.indexOf("_rollover", 0) < 0){
			if(menu_img.indexOf("_current", 0) > -1) return false;
			//$(this).find('img').css('margin-bottom', '4px');
			ext=menu_img.substr(menu_img.lastIndexOf('.'), menu_img.length);			
			pfix=menu_img.substring(0, menu_img.indexOf(ext));
			hsrc=pfix+'_rollover'+ext;		
			$(this).find('img').attr('src', hsrc);				
		}
	}).mouseout(function(){				
		if($(this).find('img').attr('src').indexOf("_rollover", 0) > -1){			
			//$(this).find('img').css('margin-bottom', '0');
			$(this).find('img').attr('src', menu_img);			
		}
		
		//$('#menu_line').attr('class', menu_line_class);
		//$(this).attr('class', li_class);
	});
	
});