// JavaScript Document
var intval=""
var path = "http://www.designiti.com/vtest/";

jQuery(document).ready(function() {
	//show_mask("0.5");
	//show_loading();
		
	$(".scroll-pane").jScrollPane({showArrows:true});
	//setTimeout("hide_mask();",1000);	
	$("#submit_info").hide();
	$("#legal_terms").hide();
	$("#unwatch").hide();
	update_cart();
	$("#email").val("");
	$("#password").val("");	
	//$(".hand").css("cursor","pointer");	

	$(".menu_project_icon").css("cursor","pointer");
	$(".menu_project_icon").click(function(){
			window.location.href='home.php';
	});	
	
 	$(document).bind("contextmenu",function(e){
        return true;
    });
	
	$(".sf_menu").click(function(){							
		$("#search_filter").val($(this).attr("id"));
		$("#sf_select").html($(this).html());
		$(".d_menu").show();
		$("."+$(this).attr("id")).hide();
		$("#sf_menu").hide();
		$("#mask").hide();
	});	
	$("#w_shop").hover(
		  function () {
			  $(".d_shop, .li2_shop").show();
			  $(".li_shop").fadeIn(300);
			  $(".d_social").hide();
			  $(".d_news").hide();
			  $(".d_info").hide();	
		  }, 
		  function () {$(".w_shop, .li2_shop").hide();}
	);
	$(".w_shop").hover(
		  function () {
			  $(".d_shop, .li2_shop").show();
			  $(".li_shop").show();
		  }, 
		  function () {$(".w_shop, .li2_shop").fadeOut(600);}
	);
	
	$("#w_social").hover(
		  function () {
			  $(".d_social, .li2_social").show();
			  $(".li_social").fadeIn(300);
			  $(".d_shop").hide();
			  $(".d_news").hide();
			  $(".d_info").hide();	
		  }, 
		  function () {
			  $(".w_social, .li2_social").hide();
		  }
	);
	
	$(".w_social").hover(
		  function () {
			 $(".d_social, .li2_social").show();
			 $(".li_social").show();
		  }, 
		  function () {
			 $(".w_social, .li2_social").fadeOut(600);
		  }
	);
	
	$("#w_news").hover(
		  function () {
			  $(".d_news").show();
			  $(".li_news").fadeIn(300);
			  $(".d_social").hide();
			  $(".d_shop").hide();
			  $(".d_info").hide();				  
		  }, 
		  function () {$(".w_news").hide();}
	);
	$(".w_news").hover(
		  function () {
			  $(".d_news").show();
			  $(".li_news").show();			  
		  }, 
		  function () {$(".w_news").fadeOut(600);}
	);
	
	$("#w_info").hover(
		  function () {
			  $(".d_info").show();
			  $(".li_info").fadeIn(300);
			  $(".d_social").hide();
			  $(".d_shop").hide();
			  $(".d_news").hide();				  
		  }, 
		  function () {$(".w_info").hide();}
	);	
	$(".w_info").hover(
		  function () {
			  $(".d_info").show();
			  $(".li_info").show();			  
		  }, 
		  function () {$(".w_info").fadeOut(600);}
	);	
	
	$("#joinus, #joinus2 , #joinus3").click(function(){
		show_mask(0.0);		
		$(".login_sub").fadeOut("slow");
		$(".joinus_sub").fadeTo(0, 0.95);
		$(".joinus_sub").show();
		return false;
	});
	$("#login").click(function(){
		show_mask(0.0);								
		$(".login_sub").fadeTo(0, 0.95);
		$(".login_sub").show();
		return false;
	});	
	$("#forget_pass").click(function(){
		show_mask(0.0);								
		$(".login_sub").hide();
		$(".forget_sub").fadeTo(0, 0.95);
		$(".forget_sub").show();		
		return false;
	});
	$(".d_comvote").hover(
		  function () {
			  $(".comvote_btn").removeclass("comvote_btn");
			  $(".comvote_btn").addclass("comvote_btn_active");		  
		  }
	);	
	
	$("#mask").click(function(){								   
			$(".joinus_sub, .login_sub, .forget_sub").fadeOut("slow");
			$(".joinus_sub input[type='text'],.joinus_sub input[type='password']").each(function(){
				$(this).val("");
			});
			$(".login_sub input[type='text'],.login_sub input[type='password']").each(function(){	
				$(this).val("");
			});
			$(".login_sub input[type='checkbox']").removeAttr("checked");
			$("#account_menu, #category_menu, .sort_design_menu, .product_type_menu").hide();
			$("#mask").hide();
			$(".error_login").html("");
	});	
	$("#account_head").click(function(){
	    show_mask(0.0);	
		$("#account_menu").slideDown("fast");
		return false;
	});	
	$(".category_head").click(function(){
	    show_mask(0.0);	
		$("#category_menu").slideDown("fast");
		return false;
	});		

	$(".category_head").hover(
		function(){
			//alert("#"+$(this).attr('id')+" > img");
			$("#"+$(this).attr('id')+" > img").attr("src",path+"images/arrow_cate_on.jpg");
		}, 
		function(){
			$("#"+$(this).attr('id')+" > img").attr("src",path+"images/arrow_cate.jpg");
		}
    );		
	$("#account_head").hover(
		function(){
			$(".arrow_down").attr("src",path+"images/arrow_orangedown.gif");
		}, 
		function(){
			$(".arrow_down").attr("src",path+"images/arrow_greydown.gif");
		}
    );
	$(".sort_design_head").click(function(){
	    show_mask(0.0);	
		//alert("#"+$(this).attr('id')+"_menu");
		$("#"+$(this).attr('id')+"_menu").slideDown("fast");
		return false;
	});		
	$(".sort_design_head").hover(
		function(){
			//alert("#"+$(this).attr('id')+" > img");
			$("#"+$(this).attr('id')+" > img:last").attr("src","images/arrow_orangedown.gif");
		}, 
		function(){
			$("#"+$(this).attr('id')+" > img:last").attr("src","images/arrow_greydown.gif");
		}
    );	
	$(".menu_profile").click(function(){
		$(".menu_profile").removeClass("link_orange_active");							  
		$(this).addClass("link_orange_active");
		//$("#myprofile_body").css("padding-top","5px");
		$("#myprofile_body").html("<div class=\"loading\" align=\"center\" style=\"margin-top:150px;\"><img src=\"images/loading.gif\"/></div>");
		var url = $(this).attr("page");
			$.get(url, function(data){
				$("#myprofile_body").html(data);
				$(".scroll-pane").jScrollPane({showArrows:true});
			});			
	});			
	$(".color").click(function(){	
		$(".color").css("border","2px solid #FFF");							   
		$(this).css("border","2px solid #333");
		$("#color").val($(this).attr("title"));
	});
	$(".vote_d_type img").hover(
		function(){
			//alert("#"+$(this).attr('id')+" div");
			$("."+$(this).attr('id')).show();
		},
		function(){
			$("."+$(this).attr('id')).hide();						 
		}		
	);
});
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}
function chack_eng_text(id){

     var str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
     var val=$("#"+id).val();
     var valOK = true;
     
     for (i=0; i<val.length & valOK; i++){
           valOK = (str.indexOf(val.charAt(i))!= -1) 
     }
     if(!valOK){
           show_error("English only please.");
		   $("#"+id).val(val.substr(0,(val.length-1)));
           return false
     }return true
}
function clear_joinus(){
			$(".joinus_sub, .login_sub, .forget_sub").fadeOut("slow");
			$(".joinus_sub input[type='text'],.joinus_sub input[type='password']").each(function(){
				$(this).val("");
			});
			$(".login_sub input[type='text'],.login_sub input[type='password']").each(function(){	
				$(this).val("");
			});
			$(".login_sub input[type='checkbox']").removeAttr("checked");
			$("#account_menu, #category_menu, .sort_design_menu, .product_type_menu").hide();
			$("#mask").hide();
			$(".error_login").html("");	
}
function menu_mylikebox_click(obj){
		//$(".menu_profile_sub").removeClass("link_black_active");							  
		//$(this).addClass("link_black_active");	
		//$("#myprofile_body").css("padding-top","5px");
		$("#myprofile_body").html("<div class=\"loading\"><img src=\"images/loading.gif\"/></div>");		
		var url = $(obj).attr("page");
			$.get(url, function(data){
				$("#myprofile_body").html(data);
				$(".scroll-pane").jScrollPane({showArrows:true});
			});		
}
function vote_d_zoom(){
	$("#zoom").show();
	//var h = $(window).height();
	//$("#zoom_body").css("height",h+"px");
	var w = document.body.clientWidth;
	$("#zoom_body").css("width",(w-0)+"px");
}
function vote_d_unzoom(){
	$("#zoom").hide();
}
function zoom(){
	$("#zoom_image .img").attr("src",$('#product_detail_image .active').attr("src"));
	show_mask("0.5");
	hide_loading();
	$("#zoom").show();
	//var h = document.body.clientHeight;	
	var h = $(window).height(); 
	//alert(h+" - "+h2);
	$("#zoom_body").css("height",h+"px");
	var w = document.body.clientWidth;
	$("#zoom_body").css("width",(w-0)+"px");
}
function unzoom(){
	hide_mask();
	$("#zoom").hide();
}
function reload(){
	window.location.reload();
}
function show_mask(opacity){
		var pad = 54;
		//var w = document.body.clientWidth;
		var w = $(window).width();
		var wcontainer = $(".container").innerWidth();
		var l = ((w-wcontainer)/2)+pad;
		var h = $(window).height(); 
		var h2 = document.body.clientHeight;
		if(h2>h){h=h2;}
		$("#mask").css("width",(w-0)+"px");
		$("#mask").css("left",-l+"px");
		$("#mask").css("height",h+"px");
		$("#mask").css("top",-pad+"px");		
		$('#mask').fadeTo(0, opacity);	
		$('#mask').fadeIn("slow");
}
function hide_mask(){
		$("#mask").hide();	
}
function show_loading(){
		//var h = document.body.clientHeight/2;
		//$("#loading").css("top",(h)+"px");
		$("#loading").center();
		$("#loading").show();
}
function hide_loading(){
		$("#loading").hide();	
}
function forget_pass(){
	var email=$("#forget_email").val();
	if(email=="" || email==null){
		$(".error_login").html("Please fill in your email!");	
	}else{
		$(".error_login").html(".");		
		$.get("forget_pass.php",{email: email},
		function(data){
			$(".error_login").html(data);
			if(data == "OK"){
				$(".error_login").html("Your password has been sent to the email address you provided.");
			}else{
				$(".error_login").html(data);		
			}
		});		
	}
}
function check_login(ROOT_PATH){
	//alert(ROOT_PATH);
	//$(".error_login").html("");
	var email=$("#login_email").val();
	var password=$("#login_password").val();
	var remember_me=$("#remember_me").attr('checked');
	var backurl=$("#backurl").val();
	
	if(email=="" || email==null){
		$(".error_login").html("Please fill in your email!");	
	}else if(password=="" || password==null){
		$(".error_login").html("Please fill in your password!");	
	}else{
		$(".error_login").html(".");		
		$.get("login.php",{ email: email,password: password,remember_me:remember_me},
		function(data){
			$(".error_login").html(data);
			if(data == "OK"){
				//window.location.href=ROOT_PATH+"myprofile.php";
				if(backurl==" " || backurl=="" || backurl==null){
					window.location.reload();
				}else{
					window.location.href=backurl;
				}
				
			}else{
				$(".error_login").html(data);		
			}
		});
	}

}
function check_login_u(ROOT_PATH){

	var email=$("#login_email2").val();
	var password=$("#login_password2").val();
	var remember_me=$("#remember_me2").attr('checked');
	var backurl=$("#backurl").val();
	
	if(email=="" || email==null){
		$(".error_login").html("Please fill in your email!");	
	}else if(password=="" || password==null){
		$(".error_login").html("Please fill in your password!");	
	}else{
		$(".error_login").html(".");		
		$.get("login.php",{ email: email,password: password,remember_me:remember_me},
		function(data){
			$(".error_login").html(data);
			if(data == "OK"){
				window.location.href=backurl;
			}else{
				$(".error_login").html(data);		
			}
		});
	}

}
function logout(ROOT_PATH){
		$.get('logout.php', function(data){
			if(data == "OK"){
				window.location.href=ROOT_PATH+"index.php";
			}
		});		
}
function change_language(lang,url){
		//alert (lang);
		
		$.get("change_language.inc.php",{lang:lang,url:url},
		function(data){
			$(".error_login").html(data);
			if(data.substring(0,2) == "OK"){
				window.location.href=url;
			}else{
				$(".error_login").html(data);		
			}
		});
}
function trim(s) 
{ 
    var l=0; var r=s.length -1; 
    while(l < s.length && s[l] == ' ') 
    {     l++; } 
    while(r > l && s[r] == ' ') 
    {     r-=1;     } 
    return s.substring(l, r+1); 
} 
function check_register(){
	$(".error").html("");
	var profile_name=trim($("#profile_name").val());
	var email=$("#email").val();
	var password=$("#password").val();
	var password2=$("#password2").val();
	
	if(profile_name==" " || profile_name=="" || profile_name==null){
		$(".error").html("Please fill in your profile name!");	
	}
	else if(email=="" || email==null){
		$(".error").html("Please fill in your email!");	
	}
	else if(checkMail(email)==false){
		$(".error").html("Your email address isn't valid!");			
	}
	else if(password=="" || password==null){
		$(".error").html("Please fill in your password!");
	}
	else if(password.length<4){
		$(".error").html("Your Password Must Be at Least 4 Characters");	
	}			
	else if(password2=="" || password2==null){
		$(".error").html("Please fill in your Verify Password!");	
	}
	else if(password!=password2){
		$(".error").html("Your password and Verify Password must match!");	
	}else{	
		var url = "register.php?profile_name="+profile_name+"&email="+email+"&password="+password;

		$.get(url, function(data){
			if(data == "OK"){
				$("#joinus_process").hide();
				$("#joinus_complete").show();
				$("#joinus_complete").append("<p><input class='button11' onclick='clear_joinus();' type='button' value='OK'/></p>");
			}else{
				$(".error").html(data);		
			}
		});
	}
}	
function checkMail(email) {
	var mail = email;
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	if(mail.search(emailRegEx) == -1)
	{
		return false;
	}else{
		return true;
	}
}	
function show_massage(data){
	$(window).scrollTop(0);
	$("#error_progress_text").html(data);
	$("#error_progress_text").attr("class","error_progress_c");
	$(".error_progress").show();
	setTimeout("clear_error();",2000);	
}
function show_error(data){
	$(window).scrollTop(0);
	$("#error_progress_text").html(data);
	$("#error_progress_text").attr("class","error_progress_e");
	$(".error_progress").show();
	setTimeout("clear_error();",2000);	
}
function clear_error(){
	$('.error_progress').hide();	
}
function change_relate(p_id,p_relate){
	$.get("relate_page.inc.php?p_id="+p_id+"&p_relate="+p_relate, function(data){
		$(".relate_image").html(data);
	});		
}
function change_d_relate(d_id,d_relate){
	//alert(d_id+","+d_relate);
	$(".relate_page > .r_num").css("color","#FF8F1F");
	$(".relate_page > .r_num").addClass("hand");
	$(".relate_page > ."+d_relate).css("color","#CCC");
	$(".relate_page > ."+d_relate).removeClass("hand");	
	$.get("design_relate_page.inc.php?d_id="+d_id+"&d_relate="+d_relate, function(data){
		$(".relate_image").html(data);
	});			
}
function change_d_quick_relate(d_id,d_relate){
	//alert(d_id+","+d_relate);
	$.get("design_quick_relate_page.inc.php?d_id="+d_id+"&d_relate="+d_relate, function(data){
		$(".relate_image").html(data);
	});		
	
}
function add2cart(p_id,size,color){
	if(color=="" || color==null){
		alert("Please select a Color !");
		//show_error("Please select color !");
	}else if(size=="" || size==null){
		alert("Please select a Size !");
	}else{
		$.post("add2cart.inc.php",{ p_id:p_id, size:size, color:color },
		function(data){
			if(data.substring(0,3) == "OK:"){
				show_massage(data.substring(3));
			}else{
				show_error(data);		
			}
			update_cart();
		});	
	}
}
function delete_item(item_id){
	$.post("delete_item.inc.php",{ item_id:item_id},
	function(data){
		if(data.substring(0,3) == "OK:"){
			show_massage(data.substring(3));
		}else{
			show_error(data);		
		}
		update_cart();
		reload();
	});	
}
function delete_credit(item_id){
	$.post("delete_credit.inc.php",{ item_id:item_id},
	function(data){
		if(data.substring(0,3) == "OK:"){
			show_massage(data.substring(3));
		}else{
			show_error(data);		
		}
		reload();
	});	
}
function update_cart(){
	$.get("count_cart.inc.php",
	function(data){
		$(".product_in_cart").html(data);
	});	
}
function checkout(){
	$.get("checkout.inc.php",
	function(data){
		if(data.substring(0,2) == "OK"){
			//window.location.href='https://www.designiti.com/shop/checkout.php';
			window.location.href='checkout.php';
		}else{
			show_error(data);		
		}
	});	
}
/*
function payment_info(){
	$.get("payment_info.inc.php",
	function(data){
		if(data.substring(0,2) == "OK"){
			window.location.href='payment_info.php';
		}else{
			show_error(data);		
		}
	});		
}
*/
function update_order(mode){
	if(mode=="checkout"){$("#checkout").val("1");}
	$('#f_order').submit();	
}

function show_submit_info(){
		show_mask("0.5");	
		hide_loading();
		
		$("#submit_info").css("top","0");
		$("#submit_info").show();	
		//$("#designer_guide").show();	
		//$("#submission_guideline").show();
		
		var h = document.body.clientHeight;	
		h=768;
		$("#submit_info_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#submit_info_body").css("width",(w-0)+"px");
		//$(".scroll-pane").jScrollPane({showArrows:true});
		//$("#submission_guideline").hide();
		

}
function unshow_submit_info(){
		hide_mask("0.5");	
		$("#submit_info").hide();		
}
function show_todo_en(){
		show_mask("0.5");	
		hide_loading();
		
		$("#todo_en").css("top","0");
		$("#todo_en").show();		
		
		var h = document.body.clientHeight;	
		h=768;
		$("#todo_en_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#todo_en_body").css("width",(w-0)+"px");
}
function unshow_todo_en(){
		hide_mask("0.5");	
		$("#todo_en").hide();		
}
function show_todo_th(){
		show_mask("0.5");	
		hide_loading();
		
		$("#todo_th").css("top","0");
		$("#todo_th").show();		
		
		var h = document.body.clientHeight;	
		h=768;
		$("#todo_th_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#todo_th_body").css("width",(w-0)+"px");
}
function unshow_todo_th(){
		hide_mask("0.5");	
		$("#todo_th").hide();		
}
function show_sample_1(){
		show_mask("0.5");	
		hide_loading();
		
		$("#sample_1").css("top","0");
		$("#sample_1").show();
		var h = document.body.clientHeight;	
		$("#sample_1_body").css("height",h+"px");			
		var w = document.body.clientWidth;
		$("#sample_1_body").css("width",(w-0)+"px");
}
function unshow_sample_1(){
		hide_mask("0.5");	
		$("#sample_1").hide();		
}

function show_sample_2(){
		show_mask("0.5");	
		hide_loading();
		
		$("#sample_2").css("top","0");
		$("#sample_2").show();
		var h = document.body.clientHeight;	
		$("#sample_2_body").css("height",h+"px");			
		var w = document.body.clientWidth;
		$("#sample_2_body").css("width",(w-0)+"px");
}
function unshow_sample_2(){
		hide_mask("0.5");	
		$("#sample_2").hide();		
}

function show_sample_3(){
		show_mask("0.5");	
		hide_loading();
		
		$("#sample_3").css("top","0");
		$("#sample_3").show();	
		var h = document.body.clientHeight;	
		$("#sample_3_body").css("height",h+"px");		
		var w = document.body.clientWidth;
		$("#sample_3_body").css("width",(w-0)+"px");
}
function unshow_sample_3(){
		hide_mask("0.5");	
		$("#sample_3").hide();		
}

function view_submission_guideline(){
	$("#designer_guide").hide();
	$("#submission_guideline").show();
}
function view_disigner_guide(){
	$("#submission_guideline").hide();
	$("#designer_guide").show();	
}
function show_printing(){
		
		show_mask("0.5");	
		$("#mask").css("height","650px");
		hide_loading();
		
		$("#printing").show();	
		var h = document.body.clientHeight;	
		h = 640;
		$("#printing_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#printing_body").css("width",(w-0)+"px");
}
function unshow_printing(){
		hide_mask();
		$("#printing").hide();	
}
function show_sizechart(){
		show_mask("0.5");	
		hide_loading();
		
		$("#sizechart").show();	
		var h = document.body.clientHeight;	
		$("#sizechart_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#sizechart_body").css("width",(w-0)+"px");
}
function unshow_sizechart(){
		hide_mask();
		$("#sizechart").hide();	
}

function show_legal_terms(){
		show_mask("0.5");	
		hide_loading();
		$("#legal_terms").css("top","0");
		$("#legal_terms").show();	
		var h = document.body.clientHeight;	
		$("#legal_terms_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#legal_terms_body").css("width",(w-0)+"px");
		
}
function unshow_legal_terms(){
		hide_mask("0.5");	
		$("#legal_terms").hide();		
}
function show_credit_jakrit(){
		show_mask("0.5");	
		hide_loading();
		
		$("#credit").css("top","-250px");
		$("#credit").show();	
		var h = document.body.clientHeight;	
		$("#credit_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#credit_body").css("width",(w-0)+"px");
		
}
function unshow_credit_jakrit(){
		hide_mask("0.5");	
		$("#credit").hide();		
}
function show_prize1(){
		show_mask("0.5");	
		hide_loading();
		
		$("#prize").css("top","50px");
		$("#prize").show();	
		var h = document.body.clientHeight;	
		$("#prize_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#prize_body").css("width",(w-0)+"px");
		
}
function unshow_prize1(){
		hide_mask("0.5");	
		$("#prize").hide();		
}
function show_prize2(){
		show_mask("0.5");	
		hide_loading();
		
		$("#prize2").css("top","50px");
		$("#prize2").show();	
		var h = document.body.clientHeight;	
		$("#prize2_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#prize2_body").css("width",(w-0)+"px");
		
}
function unshow_prize2(){
		hide_mask("0.5");	
		$("#prize2").hide();		
}
function show_chg_profile(){
		show_mask("0.5");	
		hide_loading();
		
		$("#change_profile").css("top","0");
		$("#change_profile").show();	
		//var h = document.body.clientHeight;	
		var h = window.innerHeight;
		$("#change_profile_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#change_profile_body").css("width",(w-0)+"px");
		
}
function unshow_chg_profile(){
		hide_mask("0.5");	
		$("#change_profile").hide();		
}
function show_vote_d(d_id,p_relate,$member_id){
		show_mask("0.5");	
		hide_loading();
		$("#vote_d_content_b").html("");
		$("#vote_d").show();	
		var h = document.body.clientHeight;	
		$("#vote_d_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#vote_d_body").css("width",(w-0)+"px");

		$.get("vote_d_quick.inc.php",{d_id:d_id,p_relate:p_relate},function(data){
			$("#vote_d_content_b").html(data);
			$("#scroll-pane2").jScrollPane({showArrows:true});			
			$(".image_num").fadeTo(0, 0.7);
			if(!$member_id){
				$('.vote_d_score').tipsy({gravity: 'sw',html: true,opacity: 0.8});	
			}
			
		});
		
		
}
function unshow_vote_d(){
		if(intval!=""){
			window.clearInterval(intval)
			intval="";
		}
		hide_mask("0.5");	
		$("#vote_d").hide();		
}
function voting(obj,d_id,score,next_design_id){
		$.post("voting.inc.php",{d_id:d_id,score:score},function(data){
			if(data.substring(0,3) == "OK:"){
				
					window.location.href="vote_design_detail.php?d_id="+d_id;
				
			}else{
				$("#voting_error").html(data.substring(6));		
			}																 
		});	
		
}
function voting_quick(obj,d_id,score,next_design_id,member_id){
		$.post("voting_quick.inc.php",{d_id:d_id,score:score},function(data){
			if(data.substring(0,3) == "OK:"){

				if(data.substring(3,8)=="close" ){
					unshow_vote_d();
				}else{
					show_vote_d(data.substring(3),0,member_id);
				}
			}else{
				$("#voting_error").html(data.substring(6));		
			}																 
		});	
		
}

function check_content_from_type(t,show){
		$.post("check_content_from_type.inc.php",{t:t,show:show},function(data){
			if(data.substring(0,3) == "OK:"){
				window.location.href="vote_design.php?t="+t+"&show="+show;
			}else{
				show_error(data);
			}																 
		});		
}
function check_product_from_type(t,cate){
		$.post("check_product_from_type.inc.php",{t:t,cate:cate},function(data){
			if(data.substring(0,3) == "OK:"){
				window.location.href="catalog.php?t="+t+"&cate="+cate;
			}else{
				show_error(data);
			}																 
		});	
}
function check_product_from_theme(page,theme,cate,t,g){
		$.post("check_product_from_theme.inc.php",{theme:theme,cate:cate,t:t,g:g},function(data){
			if(data.substring(0,3) == "OK:"){
				window.location.href=page+"?theme="+theme+"&cate="+cate+"&t="+t+"&g="+g;
			}else{
				show_error(data);
			}																 
		});	
}
function check_content_from_show(show){
		$.post("check_content_from_show.inc.php",{show:show},function(data){
			if(data.substring(0,3) == "OK:"){
				window.location.href="vote_design.php?show="+show;
			}else{
				show_error(data);
			}																 
		});		
}
function comment_submit(d_id){
		var comment= $("#comment").val();
		//alert(comment+":"+d_id);
		if(comment=="" || comment==null){
			$(".error_comment").html("Please fill in your comment!");	
		}else{		
			show_mask(0.8);
			show_loading();	
			$.post("design_comment.inc.php",{comment:comment,d_id:d_id},function(data){
				$("#loading").hide();
				$("#mask").hide();
				if(data.substring(0,3) == "OK:"){
					$(".error_comment").removeClass("error_progress_e");
					$(".error_comment").addClass("error_progress_c");
					$(".error_comment").html("Complete");	
					reload();
				}else{
					show_error(data);
				}																 
			});	
		}
}
function product_comment_submit(p_id){
		var comment= $("#comment").val();
		//alert(comment+":"+p_id);
		if(comment=="" || comment==null){
			$(".error_comment").html("Please fill in your comment!");	
		}else{		
			$.post("product_comment.inc.php",{comment:comment,p_id:p_id},function(data){
				if(data.substring(0,3) == "OK:"){
					$(".error_comment").removeClass("error_progress_e");
					$(".error_comment").addClass("error_progress_c");
					$(".error_comment").html("Complete");	
					reload();
				}else{
					show_error(data);
				}																 
			});	
		}
}
function update_comment(d_id){
		$("#div_comment").load("design_update_comment.inc.php", {d_id: d_id } );
}
function i_like(d_id,member_id){
		if(member_id=="" || member_id==null){
			show_error("Please login or signup!");	
		}else{		
			$.post("i_like.inc.php",{member_id:member_id,d_id:d_id},function(data){
				if(data.substring(0,3) == "OK:"){
					$("#like_icon").removeClass("like_icon");
					$("#like_icon").addClass("like_icon_selected");
				}else if(data.substring(0,7)=="DELETE:"){
					$("#like_icon").removeClass("like_icon_selected");
					$("#like_icon").addClass("like_icon");
				}else{
					alert(data);	
				}															 
			});	
		}		
}
function i_buy(d_id,member_id){
		if(member_id=="" || member_id==null){
			show_error("Please login or signup!");	
		}else{		
			$.post("i_buy.inc.php",{member_id:member_id,d_id:d_id},function(data){
				if(data.substring(0,3) == "OK:"){
					$("#ibuy_icon").removeClass("ibuy_icon");
					$("#ibuy_icon").addClass("ibuy_icon_selected");
				}else{
					$("#ibuy_icon").removeClass("ibuy_icon_selected");
					$("#ibuy_icon").addClass("ibuy_icon");
				}																 
			});	
		}	
}
function i_watch(d_id,member_id,mode){
		if(member_id=="" || member_id==null){
			show_error("Please login or signup!");	
		}else if(mode==1){		
			$.post("i_watch.inc.php",{member_id:member_id,d_id:d_id},function(data){
				if(data.substring(0,3) == "OK:"){
					$("#watch_icon").removeClass("watch_icon");
					$("#watch_icon").addClass("watch_icon_selected");
				}else{
					$("#watch_icon").removeClass("watch_icon_selected");
					$("#watch_icon").addClass("watch_icon");
				}																 
			});	
		}else if(mode==2){		
			$.post("i_watch.inc.php",{member_id:member_id,d_id:d_id},function(data){
				if(data.substring(0,3) == "OK:"){
					$("#watch_icon").removeClass("watch_icon");
					$("#watch_icon").addClass("watch_icon_selected");
				}else{
					$("#watch_icon").removeClass("watch_icon_selected");
					$("#watch_icon").addClass("watch_icon");
					reload();
				}																 
			});	
		}
}
function toggle_about(){
		$("#about_design_detail").css("overflow","visible");
		$("#about_design_detail").css("height","auto");		
		$("#about_design_detail_more").hide();
}
function toggle(id){
		$("#"+id).toggle();
}
function search_go(){
		var filter = $("#search_filter").val();
		var key = $("#search_input").val();
		//alert("filter"+filter+" key:"+key);
		if(key=="" || key==null){
			show_error("Please enter a word to search!");	
		}else{
			$.post("get_search_count.inc.php",{filter:filter,key:key},function(data){
				if(data.substring(0,3) == "OK:"){
					//window.location.href="vote_design.php?filter="+filter+"&key="+key;
					window.location.href="search.php?filter="+filter+"&key="+key;
				}else{
					show_error("Not found!");
					$("#search_result").html("");
				}																 
			});		
		
		}

		
}
function swapImages(){
		var $active = $('#product_detail_image .active');
		var $next = ($('#product_detail_image .active').next().length > 0) ? $('#product_detail_image .active').next() : $('#product_detail_image img:first');
		$active.fadeOut(function(){
		$active.removeClass('active');
		$next.fadeIn().addClass('active');
		});
}
function show_theme_type(type){
		$(".theme_type_data").hide();
		$("."+type).show();
}
function count_text(text){
	return text.length;
}

function show_unwatch(d_id,p_relate,$member_id){	
		show_mask("0.5");	
		hide_loading();
		$("#vote_d_content_b").html("");
		$("#vote_d").show();	
		var h = document.body.clientHeight;	
		$("#vote_d_body").css("height",h+"px");
		var w = document.body.clientWidth;
		$("#vote_d_body").css("width",(w-0)+"px");
		
		$("#vote_d_body").css("float","left");
		$("#vote_d_body").css("margin-top","-50px");
		$("#vote_d_body").css("margin-left","-200px");

		$.get("vote_d_quick.inc.php",{d_id:d_id,p_relate:p_relate},function(data){
			$("#vote_d_content_b").html(data);
			$("#scroll-pane2").jScrollPane({showArrows:true});			
			$(".image_num").fadeTo(0, 0.7);
			if(!$member_id){
				$('.vote_d_score').tipsy({gravity: 'sw',html: true,opacity: 0.8});	
			}
			
		});

}
function unshow_unwatch(){
		hide_mask("0.5");	
		$("#unwatch").hide();		
}

function newsletter(member_id){
		if(member_id=="" || member_id==null){
			show_error("Please login or signup!");	
		}else{		
			$.post("newsletter.inc.php",{member_id:member_id},function(data){
				if(data.substring(0,3) == "AAA"){
					$(".subscribe").val("UNSUBSCRIBE");
				}else{
					$(".subscribe").val("SUBSCRIBE");
				}																 
			});	
		}
}

function eliminateDuplicates(arr) {
	  var i,
		  len=arr.length,
		  out=[],
		  obj={};
	
	  for (i=0;i<len;i++) {
		obj[arr[i]]=0;
	  }
	  for (i in obj) {
		out.push(i);
	  }
	  return out;
}
