// CopyRight 2011 
// By : Chutinai Boosarakham
// E-mail : check_cs@hotmail.com
// URL : www.web-sbuy.com
$(function(){
	$('.listTn').live('click', function(){ 	$ob = $(this); if($('.chkT', this).is(':checked')){ $ob.addClass('listTn2'); }else{ $ob.removeClass('listTn2');$('#cAll').attr('checked', false); }
		var chk=0; $.each($('.chkT'), function(ind, el){ if(el.checked==false){chk++;} });  if(chk>0){$('#cAll').attr('checked', false);}else{$('#cAll').attr('checked', true);} });	
	$('#cAll').live('click', function(){ if($(this).is(':checked')){ $('.chkT').attr('checked', true); $('.chkT').parent().addClass('listTn2'); }else{ $('.chkT').attr('checked', false);$('.chkT').parent().removeClass('listTn2'); } });
	$('#keywd').live('keypress keyup', function(e){ var key = (e.keyCode ? e.keyCode : e.which);  if(key==13 ){ /* Enter*/ sendSearch(); }});		
});
function sendSearch(){  // products-page-op-[gid,tid]-keywd.html
	var URL = 'products-1'; // default page 1
	var keyWd = $.trim($('#keywd').val()).replace(/[\′\‘\’\“\”\'\"\(\)\\,.:;~?<\->«»=*%$#^@&|!¡¢£¤¥¦§¨{}\[\]×…©®–ƒ—µ¶™]/g,'').replace(/(&nbsp;|&quot;|&amp;|&lt;|&gt;|&copy;|&micro;|&lsquo;|&rsquo;|&ldquo;|&rdquo;|&acute;)/g,'').replace(/[\+\/ ]/gi,'_').replace(/_+/g, "_");
	if($('#gid').val()==''){ URL += '-3-'; }else{
		if($('#cAll').is(':checked')){ URL += '-1-'+$('#gid').val()+''; }else{
			var tid1 = tid2 = ''; var ovflow=0; var maxA = 45;
			$('.chkT').each(function(){ if($(this).is(':checked')){ ovflow++; if(ovflow<=maxA){ tid1 += $(this).val()+'_'; } }else{ tid2 += $(this).val()+'_'; } });
			if(ovflow<=maxA){ if(ovflow==0){ /* checked all false */ URL += '-1-'+$('#gid').val()+''; }else{ tid1 = tid1.substr(0, tid1.length-1); URL += '-2-'+tid1+''; }
			}else{ tid2 = tid2.substr(0, tid2.length-1); URL += '-2-'+$('#gid').val()+'_'+tid2+'-xor';	 }
		}
	}
	if($('#keywd').val()!=''){ URL+= '-'+(keyWd)+''; } window.location.href = ''+URL+'.html';
}
function chnpro(page){
	window.location.href = 'products-'+page+'-'+$('#trlg2').val()+'-'+$('#trlg3').val()+(($('#trlg4').val()!='')?'-'+$('#trlg4').val():'')+(($('#trlg5').val()!='')?'-'+$('#trlg5').val():'')+'.html';	
}
function popSearch(){  
var $this = $('#bOvSearch');
$this.spOverlay({ width : '780px', top : '1px', onDrag : {handle:'.h3Head', revert:true, containment:''}, modal : false,
	before : function(){
		if($this.html()==''){ stLoad('show', 'Loading...', 100); }else{ $('#boxSearchCover').fadeIn('fast'); }
		$.get("search-b-x-app.html",{},function( data ){
			  stLoad('hide', 'Loading...', 100); $('#'+$this.attr('id')+' .boxOvLay').html(""+data+"");
			  if($.browser.msie){
				  if(parseInt($.browser.version,10)<=8){
					$('#'+$this.attr('id')+' .boxOvLay').prepend("<div class=\"zD1\"></div><div class=\"zD2\"></div>");
					$('#boxSearch').css({'margin-left':'10px', width: ($('#'+$this.attr('id')+' .boxOvLay').width()-20)+'px'});
				  }
				 if( parseInt($(window).height(), 10) < 650 ){  $('#boxSearch').height('610px'); }							
			  }else{ // chrome, safari, opera
				 if( parseInt(window.screen.availHeight, 10) >760 ){  $('#boxSearch').height('750px'); }					  
			  }
			  $('#boxSearchCover').fadeOut(500);			
		});
	}
});	
}
