// JavaScript Document
//============================================= function สำหรับ mouseover แล้วเปลี่ยนรูป

		function changePicJava(pic1,pic){//changePicJava(event,'images/icon/shopping_cart_fav_256 (2).png')
		even=pic1.srcElement.id;
		document.getElementById(even).src=pic;
		}

		function resPic(pic1,pic){
		even=pic1.srcElement.id;
		document.getElementById(even).src=pic;
		}
		
		
		//===============function เปลี่ยนสีตัวหนังสือ================
		function changeFontColor(displayid,color){ //mouseover
			$(displayid).style.color=color;
		}
		
		function changeFontColorOut(displayid,color){ //mouseout
			$(displayid).style.color=color;
		}



//================= END FUNCTION ==============//

function overBack(displayid){
	$(displayid).style.backgroundImage='url(images/home/menu-shopping2.jpg)';
}

function outBack(displayid){
	$(displayid).style.backgroundImage='url(images/home/menu-shopping1.jpg)';
}


function check_data(thisid)
{ 
var eng = /^([a-zA-Z0-9])+$/; 

if (!(eng.test($(thisid).value)))
{
$('err').style.display='';
$(thisid).select();
return false;
}
else{
	return true;
}
} 
//==============================================

function windowOpen(linkurl,width,height){
	window.open(linkurl,'Thaishoppingmall','width='+width+',height='+height);
}

//=============POPUP WINDOW==============================
// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/popup-window.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.

// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id          - id of a popup window;
// drag_id     - id of an element within popup window intended for dragging it
// exit_id     - id of an element within popup window intended for hiding it
// position    - positioning type:
//               "element", "element-right", "element-bottom", "mouse",
//               "screen-top-left", "screen-center", "screen-bottom-right"
// x, y        - offset
// position_id - id of an element relative to which popup window will be positioned


// ***** Variables *************************************************************

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;


// ***** popup_mousedown *******************************************************

function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}


// ***** popup_mousedown_window ************************************************

function popup_mousedown_window(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction = document.onselectstart;
  else popup_oldfunction = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}


// ***** popup_mousemove *******************************************************

function popup_mousemove(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  var mouseX  = ie ? window.event.clientX : e.clientX;
  var mouseY  = ie ? window.event.clientY : e.clientY;

  if (!popup_dragging) return;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

// ***** popup_mouseup *********************************************************

function popup_mouseup(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (!popup_dragging) return;

  popup_dragging = false;

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}

// ***** popup_exit ************************************************************

function popup_exit(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  popup_mouseup(e);
  element.style.display = 'none';
  document.getElementById('onloading1').style.display='none';
}


// ***** popup_show ************************************************************

function popup_show(id, drag_id, exit_id, position, x, y, position_id)
{
  var element      = document.getElementById(id);
  var drag_element = document.getElementById(drag_id);
  var exit_element = document.getElementById(exit_id);

  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;

  element.style.position = "absolute";
  element.style.display  = "block";

  if (position == "element" || position == "element-right" || position == "element-bottom")
  {
    var position_element = document.getElementById(position_id);

    for (var p = position_element; p; p = p.offsetParent)
      if (p.style.position != 'absolute')
      {
        x += p.offsetLeft;
        y += p.offsetTop;
      }

    if (position == "element-right" ) x += position_element.clientWidth;
    if (position == "element-bottom") y += position_element.clientHeight;

    element.style.left = x+'px';
    element.style.top  = y+'px';
  }

  if (position == "mouse")
  {
    element.style.left = (document.documentElement.scrollLeft+popup_mouseposX+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
  }

  if (position == "screen-top-left")
  {
    element.style.left = (document.documentElement.scrollLeft+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +y)+'px';
  }

  if (position == "screen-center")
  {
    element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px';
  }

  if (position == "screen-bottom-right")
  {
    element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )  +x)+'px';
    element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)  +y)+'px';
  }

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown_window;

  exit_element.onclick     = popup_exit;
}


// ***** Attach Events *********************************************************

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);
//=====================END POPUPWINDOW=============================
<!--
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];}
}
//-->

//=======================Check Form Register==========================
function checkRegister(){
	if (document.getElementById('user1').value==''){
		alert('Please!! Insert Username');
		document.getElementById('user1').focus();
		return false;
	}else if(document.getElementById('pass1').value==''){
		alert('Please!! Insert Password');
		document.getElementById('pass1').focus();
		return false;
	}else if(document.getElementById('cpass').value != document.getElementById('pass1').value){
		alert('Chack Password');
		document.getElementById('pass1').focus();
		return false;
	}else if(document.getElementById('name').value==''){
		alert('Please!! Insert Name');
		document.getElementById('name').focus();
		return false;
	}else if(document.getElementById('know').value==''){
		alert('Please!! Insert Where');
		document.getElementById('know').focus();
		return false;
			}else if(document.getElementById('email').value==''){
		alert('Please!! Insert E-mail');
		document.getElementById('email').focus();
		return false;
			}else{
				var val="?user="+document.getElementById('user1').value+"&pass="+document.getElementById('pass1').value+"&name="+document.getElementById('name').value+"&email="+document.getElementById('email').value+"&tel="+document.getElementById('tel').value+"&day="+document.getElementById('day').value+"&month="+document.getElementById('month').value+"&year="+document.getElementById('year').value+"&know="+document.getElementById('know').value+"&add=add";
				var linkurl2="register2db.php"+val;
					ran=Math.random();
						 if (linkurl2.indexOf('?',0)==-1){
							var url=linkurl2+"?ran="+ran;
						 }else{
							var url=linkurl2+"&ran="+ran;
						 }
					new Ajax.Request(url,
									 {method : "GET",
									 onComplete:function senda(sq){
										// $(displayid2).style.display='none';
										 sendGet('completeregister.html');
									 }
									 }
									 );
			}
		
}

function checkRegister2(){
	if (document.getElementById('user1').value==''){
		alert('Please!! Insert Username');
		document.getElementById('user1').focus();
		return false;
	}else if(document.getElementById('pass1').value==''){
		alert('Please!! Insert Password');
		document.getElementById('pass1').focus();
		return false;
	}else if(document.getElementById('cpass').value != document.getElementById('pass1').value){
		alert('Chack Password');
		document.getElementById('pass1').focus();
		return false;
	}else if(document.getElementById('name').value==''){
		alert('Please!! Insert Name');
		document.getElementById('name').focus();
		return false;
		}else if(document.getElementById('know').value==''){
		alert('Please!! Insert Where');
		document.getElementById('know').focus();
		return false;
			}else if(document.getElementById('email').value==''){
		alert('Please!! Insert E-mail');
		document.getElementById('email').focus();
		return false;
			}else{
				var val="?user="+document.getElementById('user1').value+"&pass="+document.getElementById('pass1').value+"&name="+document.getElementById('name').value+"&email="+document.getElementById('email').value+"&tel="+document.getElementById('tel').value+"&day="+document.getElementById('day').value+"&month="+document.getElementById('month').value+"&year="+document.getElementById('year').value+"&know="+document.getElementById('know').value+"&add=add";
				var linkurl2="register2db.php"+val;
					ran=Math.random();
						 if (linkurl2.indexOf('?',0)==-1){
							var url=linkurl2+"?ran="+ran;
						 }else{
							var url=linkurl2+"&ran="+ran;
						 }
					$.get(url,function(data){
										// $(displayid2).style.display='none';
										 sendGett2('completeregister.html');
									 }
									 );
			}
		
}

function sendGet(linkurl){
	document.getElementById('pleasewait').innerHTML="<center><img src='images/loading.gif'><br><br><span style='font-size:small;color:#c5b172'>Register Complete</span><br></center>";
	setTimeout("sendGet2('"+linkurl+"')",2000);
}
	
function sendGet2(linkurl){
	ran=Math.random();
		 if (linkurl.indexOf('?',0)==-1){
			var url=linkurl+"?ran="+ran;
		 }else{
			var url=linkurl+"&ran="+ran;
		 }
	new Ajax.Request(url,
					 {method : "GET",
					 onComplete:function sendGet4(sq){
						// $(displayid2).style.display='none';
						 $('formlogin').innerHTML=sq.responseText; 
					 }
					 }
					 );
}

function sendGett2(linkurl){
	document.getElementById('pleasewait').innerHTML="<center><img src='images/loading.gif'><br><br><span style='font-size:small;color:#c5b172'>Register Complete</span><br></center>";
	setTimeout("sendGett('"+linkurl+"')",2000);
}
	
function sendGett(linkurl){
	ran=Math.random();
		 if (linkurl.indexOf('?',0)==-1){
			var url=linkurl+"?ran="+ran;
		 }else{
			var url=linkurl+"&ran="+ran;
		 }
$.get(url,function(data){
						 $('#formlogin').empty().append(data);
					 }
					 
					 );
}
//=========================END===================================

function makevisible(cur,which){
strength=(which==0)? 0.7 : 1

if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

function changeRunPage(linkurl,npage,displayid){ //changeRunPage(Link ที่จะนำไปประมวลผล,เลขหน้าถัดไป,id ของพื้นที่ๆจะแสดงผล)
				//$('#'+displayid).innerHTML="<br><center><img src='images/loading.gif'><br><br>Please Wait...</center><br>";
				ran=Math.random();
				 if (linkurl.indexOf('?',0)==-1){
				 var url=linkurl+"?page="+npage+"&ran="+ran;
			}else{
				var url=linkurl+"&page="+npage+"&ran="+ran;
			}/*
				$.get(url,function(data){
									 $('#'+displayid).empty().append(data);
								 }
								 );*/
				location.href=url;
		}
