// JavaScript Document

// For 1024 CSS
//if ((screen.width<=800)) {
if ((screen.width<=800)) {
	
	/*alert('Screen size: 1024x768 or larger');*/
	document.write('<link rel="stylesheet" href="css/800.css" type="text/css" />');
	}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function MM_showHideLayers() { //v9.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
	with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}



$(function()
{
  settings = {
		tl: { radius: 2 },
		tr: { radius: 2 },
		bl: { radius: 2 },
		br: { radius: 2 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	}
//  $('.over-in, .over-r, .form-boder, .form-bg, .r-boder').corner(settings);
	$('.over-r, .form-boder, .form-bg, .r-boder').corner(settings);
});

$(function()
{
	settings = {
		tl: { radius: 4 },
		tr: { radius: 4 },
		bl: { radius: 0 },
		br: { radius: 0 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	}
	$('.function-bar').corner(settings);
	/*
	$(".form-boder a").click(function () {
		$(".form-sub").show("fast");
	});
	*/
});


function showsub(showsub)
{
	var tmp_showsub = showsub.split("-");
	$(".categories").each(function(i){
		var varid = $(this).attr("id");
		var tmp_varid = varid.split("-");
		
		if (tmp_varid[0] != tmp_showsub[0])
			$(this).hide();
		
		if($(this).css("display") == "none")
		{
			if (varid.substring(0,showsub.length) == showsub && (tmp_showsub.length+1) == tmp_varid.length)
			{
				$(this).slideDown("fast");
			}
		}
		else
		{
			if (varid.substring(0,showsub.length) == showsub && varid != showsub)
			{
				$(this).hide();
			}
		}					   
	});

	lishowsub = "li" + showsub;
	$(".licategories").each(function(i){
		var varid = $(this).attr("id");
		var tmp_varid = varid.split("-");

		if (tmp_varid[0] != "li" + tmp_showsub[0])
			$(this).hide();

		if($(this).css("display") == "none")
		{
			if (varid.substring(0,lishowsub.length) == lishowsub && (tmp_showsub.length+1) == tmp_varid.length)
			{
				$(this).slideDown("fast");
			}
		}
		else
		{
			if (varid.substring(0,lishowsub.length) == lishowsub && varid != lishowsub)
			{
				$(this).hide();
			}
		}					   
	});

	showsub = "ul" + showsub;
	$(".ulcategories").each(function(i){
		var varid = $(this).attr("id");
		var tmp_varid = varid.split("-");

		if (tmp_varid[0] != "ul" + tmp_showsub[0])
			$(this).hide();

		if($(this).css("display") == "none")
		{
			if (varid.substring(0,showsub.length) == showsub && (tmp_showsub.length+1) == tmp_varid.length)
			{
				$(this).slideDown("fast");
			}
		}
		else
		{
			if (varid.substring(0,showsub.length) == showsub && varid != showsub)
			{
				$(this).hide();
			}
		}					   
	});
}

function chglang(chglang){
	$.post("chglang.php",{
		lang: chglang
	}, function(txt){
		location.reload();
	});
}

$().ready(function() {
	$('#loginFormpassword').keyup(function(e) {
					   
		if(e.keyCode == 13){
			checklogin();
		}
	});
}); 


function checklogin(){
	if ($("#loginFormemail")[0].value != "" && $("#loginFormpassword")[0].value != "")
	{
		$("#loginFormactionflag")[0].value = 'login';
		$("#loginForm").submit();
	}
}


// validation functions
var hasRegExp = (parseInt(navigator.appVersion) >= 4);
function validateEmail(email) {
	if (!hasRegExp) return (email.indexOf('@') > 0);
	var s = email.match(/^(.+)@(.+)$/);
	if (!s) return false;
	if (s[1] != null) if (s[1].match(/^\"?[\w-_\.]*\"?$/) == null) return false;
	if (s[2] != null) return (s[2].match(/^[\w-\.]*\.[A-Za-z]{2,4}$/) != null || s[2].match(/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/) != null);
	return false;
}


function memberlogout(msg, msg2){
	
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: 0
	}, function(txt){
		if (txt > 0)
			msgtxt = msg2;
		else
			msgtxt = msg;
		if (confirm(msgtxt))
		{
			$.post("action_member.php",{
				actionflag: "logout"
			}, function(txt){
				location.href = 'index.php';
			});
		}
		
	});
}

function checkkeyup(ojb)
{
	 ojb.value = parseInt(ojb.value);
	 if (ojb.value == "NaN")
	 	ojb.value = "";
}

$().ready(function(){
				   
	$('#searchkeyword').keyup(function(e) {				   
		if(e.keyCode == 13){
			location.href = 'product_search.php?keyword=' + $.URLEncode(e[0].value);
		}
	});
	
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: 0
	}, function(txt){
		$('#shopping_link').html(txt);
	});
	reloadshoppinglist();
}); 

function addtocart(pid)
{
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: pid
	}, function(txt){
		if (txt == 0)
		{
			location.href = 'login.php?pid='+pid;
		}
		else
		{
			$('#shopping_link').html(txt);

			$('#shopping-over').fadeIn('show').oneTime(5000, "hide", function() {
					$('#shopping-over').fadeOut('show');
			  });

			reloadshoppinglist();
//			location.href = 'shopping_cart.php';
		}
	});
}

function addtocart1(pid)
{
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: pid
	}, function(txt){
		if (txt == 0)
		{
			location.href = 'login.php?pid='+pid;
		}
		else
		{
			$('#shopping_link').html(txt);
/*
			$('#shopping-over').fadeIn('show').oneTime(5000, "hide", function() {
					$('#shopping-over').fadeOut('show');
			  });
*/
			reloadshoppinglist();
			location.href = 'shopping_cart.php?url='+encodeURI(document.location.href);
		}
	});
}

function addtocartmore(pid, qty)
{
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: pid,
		qty: qty
	}, function(txt){
		if (txt == 0)
		{
			location.href = 'login.php?pid='+pid;
		}
		else
		{
			$('#shopping_link').html(txt);
			
			$('#shopping-over').fadeIn('show').oneTime(5000, "hide", function() {
					$('#shopping-over').fadeOut('show');
			  });
			
			reloadshoppinglist();
			//location.href = 'shopping_cart.php';
		}
	});
}

function addtocartmore1(pid, qty)
{
	$.post("action_order.php",{
		actionflag: "addtocart",
		pid: pid,
		qty: qty
	}, function(txt){
		if (txt == 0)
		{
			location.href = 'login.php?pid='+pid;
		}
		else
		{
			$('#shopping_link').html(txt);
			/*
			$('#shopping-over').fadeIn('show').oneTime(5000, "hide", function() {
					$('#shopping-over').fadeOut('show');
			  });
			*/
			reloadshoppinglist();
			location.href = 'shopping_cart.php?url='+encodeURI(document.location.href);
		}
	});
}

function showmorechoice(id)
{
	$.post("action_product.php",{
		actionflag: "getstyle",
		pid: id
	}, function(txt){
		$('#more-choice-pop').html(txt);	
		$('#more-choice-pop').fadeIn('show');
	});	

}

function showmorechoice1(id)
{
	$.post("action_product.php",{
		actionflag: "getstyle",
		pid: id,
		addtype: 1
	}, function(txt){
		$('#more-choice-pop').html(txt);	
		$('#more-choice-pop').fadeIn('show');
	});	

}

function styleaddtocart1()
{
	$("input:text.pstylebox").each( 
		function(){ 
			if ($(this)[0].value > 0)
			{
				var id = $(this).attr("id").split("_")[1];
				var qty = $('#qty_'+id)[0].value;
				if (qty > 0)
				{
					addtocartmore1(id, $(this)[0].value)
				}
			}
		} 
	);
	$('#more-choice-pop').fadeOut('show');
}

function styleaddtocart()
{
	$("input:text.pstylebox").each( 
		function(){ 
			if ($(this)[0].value > 0)
			{
				var id = $(this).attr("id").split("_")[1];
				var qty = $('#qty_'+id)[0].value;
				if (qty > 0)
				{
					addtocartmore(id, $(this)[0].value)
				}
			}
		} 
	);
	$('#more-choice-pop').fadeOut('show');
}

function reloadshoppinglist()
{
	$.post("action_order.php",{
		actionflag: "cartlist"
	}, function(txt){
		$('#shopping_over_list').html(txt);
	});
}

function checksearchsubmit()
{
	$("#search").submit();
}

function callcompany()
{
	if ($('#company-over').html() == "")
	{
		$.post("action_function.php",{
			actionflag: "company"
		}, function(txt){
			$('#company-over').html(txt);	
		});	
	}
	$('#company-over').fadeIn('show');	
}

function callsearch()
{
	if ($('#search-over').html() == "")
	{
		$.post("action_function.php",{
			actionflag: "search"
		}, function(txt){
			$('#search-over').html(txt);	
		});	
	}
	$('#search-over').fadeIn('show');
}
