// JavaScript Document
function fnshowListFilter(id,data){
	var id
	var data
	
	//alert(data)																	
		//$('#AjaxList').hide();
		queryStr="id="+id+"&data="+data;
					
		//alert(queryStr)
		$.ajax({
		type: "POST",
		url: "../lib/product/showlist-filter.php",
		cache: false,
		data: queryStr,
		success: function(response){
		setTimeout("finishShowListFilter('showHideListLoad"+id+"','showHideList"+id+"', '"+escape(response)+"')", 0);
		}
		});
}
function finishShowListFilter(loadid,divid, response) {
		  
	$('#'+loadid).hide();
	//$('#AjaxList').show();
						  
	$('#'+divid).html(unescape(response));
	$('#'+divid).show();
}
function fnshowList(id,data){
	var id
	var data
	
	//alert(data)																	
		//$('#AjaxList').hide();
		queryStr="id="+id+"&data="+data;
					
		//alert(queryStr)
		$.ajax({
		type: "POST",
		url: "../lib/product/showlist.php",
		cache: false,
		data: queryStr,
		success: function(response){
		setTimeout("finishShowList('showHideListLoad"+id+"','showHideList"+id+"', '"+escape(response)+"')", 0);
		}
		});
}
function finishShowList(loadid,divid, response) {
		  
	$('#'+loadid).hide();
	//$('#AjaxList').show();
						  
	$('#'+divid).html(unescape(response));
	$('#'+divid).show();
}

function showList(id,data,page){
//alert(data)
if(id==0){
	var show=document.getElementById('cat'+id).style.display;
	if(show=='' || show=='block'){
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwRight.gif')";
		//document.getElementById('cat'+id).style.display='none';
		$("#cat"+id).slideUp(500);
	}else{
		$("#cat"+id).slideDown(500);
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwDown.gif')";
		document.getElementById('cat'+id).style.display='block';
	}
}else{
	
	var show=document.getElementById('showHideList'+id).style.display;
	if(show=='' || show=='block'){
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwRight.gif')";
		//document.getElementById('showHideList'+id).style.display='none';
		$("#showHideList"+id).slideUp(500);
		
		$("#showHideListLoad"+id).hide();
	}else{
		
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwDown.gif')";
		//document.getElementById('showHideList'+id).style.display='block';
		$("#showHideList"+id).slideUp(500);
		$("#showHideListLoad"+id).show();

			if(page=='index'){
			fnshowList(id,data)
			}else{
			fnshowListFilter(id,data)		
			}
	}	
		
}

}

function showListOnce(id){
	var show=document.getElementById('cat'+id).style.display;
	if(show=='' || show=='block'){
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwRight.gif')";
		//document.getElementById('cat'+id).style.display='none';
		$("#cat"+id).slideUp(500);
	}else{
		$("#cat"+id).slideDown(500);
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwDown.gif')";
		document.getElementById('cat'+id).style.display='block';
	}

}


/////////////////////
function showHideList (id){
var id
if(document.getElementById('other'+id).style.display=='block'){
	document.getElementById('other'+id).style.display = "none";
	document.getElementById('liother'+id).style.backgroundImage = "url(../engine/global/crumbArrw.gif)";
}else{
	document.getElementById('other'+id).style.display = "block";
	document.getElementById('liother'+id).style.backgroundImage = "url(../engine/global/arrwMore.gif)";
}



}

function showdetail(id){
	var show=document.getElementById('cat'+id).style.display;
	if(show=='' || show=='block'){
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwRight.gif')";
		//document.getElementById('cat'+id).style.display='none';
		$("#cat"+id).slideUp(500);
	}else{
		$("#cat"+id).slideDown(500);
		document.getElementById('Group'+id).style.backgroundImage="url('../engine/global/arrwDown.gif')";
		document.getElementById('cat'+id).style.display='block';
	}
	
}

function showTabDetail(img,id){
	var show=document.getElementById(id).style.display;
	if(show=='' || show=='block'){
		document.getElementById(img).style.backgroundImage="url('../engine/global/arrwRight.gif')";
		document.getElementById(img).style.backgroundPosition='left 8px';
		document.getElementById(img).style.paddingBottom='20px';
		document.getElementById(img).style.borderBottom='1px #e5e5e5 solid';
		document.getElementById(id).style.display='none';
		$('#'+id).hide();
	}else{
		document.getElementById(img).style.backgroundImage="url('../engine/global/arrwDown.gif')";
		document.getElementById(img).style.paddingBottom='0px';
		document.getElementById(img).style.borderBottom='none';
		$('#'+id).show();
		document.getElementById(id).style.display='block';
	}
	
}
function showSend2Friend(id){
	var show;
	var len;
	var arrX;
	var x;
	if(!id){
		id='Send';
		x='';
	}else{
		arrX=id.split('end');
		x=arrX[1];
	}
	show=document.getElementById(id).style.display;
	
	if(show=='' || show=='block'){
		$('#'+id).slideUp(500);
		//document.getElementById(id).style.display='none';
		//document.getElementById('SendForm').style.display='none';
	}else{
		$('#dEmailSendResult'+x).hide();
		$('#dEmailSendForm'+x).show();
		$('#'+id).slideDown(500);
		document.getElementById('FriendEmail'+x).value='';
		document.getElementById('message'+x).value='';
		document.getElementById('YourEmail'+x).value='';
		//document.getElementById(id).style.display='block';
	}
}
function fnSend2Friend(){
	var femail=$('#FriendEmail').val();
	var txt=$('#message').val();
	var yemail=$('#YourEmail').val();
	if(femail=='' || txt=='' || yemail==''){
			alert("กรุณากรอกข้อมูลให้ครบถ้วน");
	}else{
		if(femail.indexOf('@')==-1 || femail.indexOf('.')==-1 || yemail.indexOf('@')==-1 || yemail.indexOf('.')==-1){
				alert("กรุณากรอกข้อมูลให้ถูกต้อง");
		}else{
			$('#Send').hide();
			$('#loading').show();
			//f_username=$('#f_username').val();
			//f_password=$('#f_password').val();
			queryStr="femail="+femail+"&txt="+txt+"&yemail="+yemail+"&urlRef="+document.URL;	
				//alert(queryStr);
				$.ajax({
							   type: "POST",
							   url: "../lib/send-friend-mail.php",
							   cache: false,
							   data: queryStr,
							   success: function(response){
								 setTimeout("finishSend2Friend('Send', '"+escape(response)+"')", 300);
							   }
				});
		}
	}
}
function finishSend2Friend(id,response) {
	//alert('aa')
	  $('#dEmailSendForm').hide();
	  $('#loading').hide();
	  $('#dEmailSendResult').html(unescape(response));
	  $('#dEmailSendResult').show();
	  $('#'+id).fadeIn();
	  setTimeout("$('#Send').slideUp(1300)", 1000);
}
/*function finishLogin(id) {
	  $('#loading').hide();
	  $('#'+id).html('<div align="center" style="margin-top:80px;height:185px;">ส่งเมล์ถึงเพื่อนคุณเรียบร้อยแล้ว<br><br> <a href="#1" onclick="showSend2Friend();">[x] ปิด</a></center>');
	  $('#'+id).fadeIn();
}*/

/* send job */
function fnSendJob2Friend(id){
	var femail=$('#FriendEmail'+id).val();
	var txt=$('#message'+id).val();
	var yemail=$('#YourEmail'+id).val();
	if(femail=='' || txt=='' || yemail==''){
			alert("กรุณากรอกข้อมูลให้ครบถ้วน");
	}else{
		if(femail.indexOf('@')==-1 || femail.indexOf('.')==-1 || yemail.indexOf('@')==-1 || yemail.indexOf('.')==-1){
				alert("กรุณากรอกข้อมูลให้ถูกต้อง");
		}else{
			$('#Send'+id).hide();
			$('#loading'+id).show();
			//f_username=$('#f_username').val();
			//f_password=$('#f_password').val();
			queryStr="femail="+femail+"&txt="+txt+"&yemail="+yemail+"&urlRef="+document.URL+"?j="+id;	
				//alert(queryStr);
				$.ajax({
							   type: "POST",
							   url: "../lib/send-job-mail.php",
							   cache: false,
							   data: queryStr,
							   success: function(response){
								 setTimeout("finishSendJob2Friend('"+id+"', '"+escape(response)+"')", 300);
							   }
				});
		}
	}
}
function finishSendJob2Friend(id,response) {
	//alert('aa')
	  $('#dEmailSendForm'+id).hide();
	  $('#loading'+id).hide();
	  $('#dEmailSendResult'+id).html(unescape(response));
	  $('#dEmailSendResult'+id).show();
	  $('#Send'+id).fadeIn();
	  var x='#Send'+id;
	  setTimeout("$('"+x+"').slideUp(500)", 1000);
}
/* end send job */

function showCalculate(){
	var show=document.getElementById('divCalculate').style.display;
	if(show=='' || show=='block'){
		$('#divCalculate').slideUp(300);
		$('#btnCalculate').hide();
		$('#btnCalculateResult').hide();
	}else{
		$('#divCalculateResult').hide();
		ClearCalculate();
		$('#TbdSizeCalculate').show();
		$('#btnCalculate').hide();
		$('#divCalculate').slideDown(300);
		$('#btnCalculate').fadeIn(300);
		document.getElementById('divCalculate').style.display='block';	
	}
}

function fnaddProduct(id){
var id
	queryStr="id="+id;	
//alert(queryStr)
	$.ajax({
		type: "POST",
		url: "../lib/addfav.php",
		cache: false,
		data: queryStr,
			success: function(response){
			setTimeout("finishMyFav('txtFav', '"+escape(response)+"')", 1);
			}
		});

}
function finishMyFav(id, response) {
  $('#'+id).html(unescape(response));
  //$('#'+id).show();
}

function setLogin(id){
	var divshow=document.getElementById(id).display;
	if(divshow==''){
		$('#'+id).slideUp(300);
		document.getElementById(id).display='none';
	}else{
		$('#'+id).slideDown(300);
		document.getElementById(id).display='';
		
	}
}


function CKformFav() { 
  var message = "";
  if(document.myFormLogin.f_username.value=='') message+="- กรุณากรอกชื่อผู้ใช้\n";
  else{
	  if(document.myFormLogin.f_username.value.indexOf('@')==-1 || document.myFormLogin.f_username.value.indexOf('.')==-1){
		   message+="- กรุณาตรวจสอบชื่อผู้ใช้\n";
	  }
  }
  if(document.myFormLogin.f_password.value=='') message+="- กรุณากรอกรหัสผ่าน\n";
  if(message.length > 0){
	alert("กรุณาตรวจข้อมูลต่อไปนี้\n\n"+message);
	return false;
  }else{
  	f_username=$('#f_username').val();
	f_password=$('#f_password').val();
	add_product=$('#add_product').val();
	fnLogin('frmLogin',f_username,f_password,add_product);
  }
}

function fnLogin(id,f_username,f_password,add_product){
	//f_username=$('#f_username').val();
	//f_password=$('#f_password').val();
	queryStr="f_username="+f_username+"&f_password="+f_password+"&add_product="+add_product+"&return_url="+document.URL;	
		//alert(queryStr);
		$.ajax({
					   type: "POST",
					   url: "../lib/ck_login.php",
					   cache: false,
					   data: queryStr,
					   success: function(response){
						 setTimeout("finishLogin('"+id+"', '"+escape(response)+"')", 300);
					   }
		});
}
function finishLogin(id, response) {
	if(unescape(response)=="ไม่พบชื่อผู้ใช้ในระบบ" || unescape(response)=="รหัสผ่านไม่ถูกต้อง")
		alert(unescape(response));
	else
	  //$('#'+id).html(unescape(response));
	   window.location.reload();
}