﻿/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,sitename,price,gname){

	//if (height > 0){
	//	currentimageheight = height;
	//}
	var ImgObj=new Image();
	ImgObj.src=imagename;
	currentimageheight = ImgObj.height;

	document.onmousemove=followmouse;
	newHTML = '<head><META content="text/html; charset=utf-8" http-equiv="Content-Type"></head>';
	newHTML = newHTML + '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<center><table><tr><td><font size=1 color=666666>圖片來源：' + sitename + '</font><br>';
	newHTML = newHTML + '<font size=1 color=666666>商品價格：NT$ ' + price + '</font><br>';
	newHTML = newHTML + '<font size=1 color=666666>商品名稱：' + gname + '</font></td></tr></table>';
	
    
	//newHTML = newHTML + 'Rating: ' + cameraHTML + '<br/>';
	//newHTML = newHTML + description + '<br/>';
			
	newHTML = newHTML + '<img onerror="this.src=\'images/NO_PHOTO.gif\'" src="' + imagename + '" border="0"><P>';

	newHTML = newHTML +'<font size=1 color=666666>註：商品實際價格、名稱、圖片，以來源網站為準</font></center>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}


function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 125)){
			ycoord += e.pageY - Math.max(0,(125+currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight+125)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(125+currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
  
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function ok_box(choice){
    //str1 = document.form1.q.value; 
    str1="";
    j=0;
    for (i=0; i<document.Form1.keycnt.value; i++) {
      if (document.form1.choose[i].checked==true) {
        document.form1.choose[i].nextSibling.style.color='red';
        j++;
        if (j>1)
          str1 = str1 + " " + document.form1.choose[i].value;
        else
          str1 = str1 + document.form1.choose[i].value;
      }
      else {
        document.form1.choose[i].nextSibling.style.color='black';
      }
      
    }
    document.form1.q.value = str1;
 }
 
 function ok_sbs(){
    strsbs="";
    for (i=0; i<10; i++) {
      if (document.form2.sbs[i].checked==true){
          strsbs = strsbs + "&sbs=" + document.form2.sbs[i].value;
      }
    }
    document.form2.chsbs.value = strsbs;
 }
 function bt_relay(flag){
   if (document.getElementById("RelationGoodsGrid").style.display == 'block' || document.getElementById("RelationGoodsGrid").style.display == '') {
      document.getElementById("RelationGoodsGrid").style.display='none';
      document.getElementById("relgoodsflag").value='︾';
   }
   else {
      document.getElementById("RelationGoodsGrid").style.display='block'; 
      document.getElementById("relgoodsflag").value='︽';            
   }
 }
 
function findpricedata() {
  re = /\D/; 
  if ((re.test(document.form1.minp.value)) || (re.test(document.form1.maxp.value))) { 
    document.form1.minp.value="";
    document.form1.maxp.value="";
  }else{
    document.form1.submit();
  }
}

function submitdata() {
  document.Form1.minp.value = "";
  document.Form1.maxp.value = "";    
  document.form1.submit();    
}

function datachange(list)
{
   document.form1.submit();
}

function pricedatachange(list)
{
  var s = document.Form1.gp.value;
  var a = s.split(','); 
  if (a[0] == "none") {
    document.Form1.minp.value = "";
  }
  else {
    document.Form1.minp.value = a[0];
  }
  if (a[1] == "none") {
    document.Form1.maxp.value = "";
  }
  else {
    document.Form1.maxp.value = a[1];
  }
  document.form1.submit();    
}


function textdisapear(){
  document.form1.q.value = "" ;
  document.form1.q.focus();
}

function textdisplay(){
  document.form1.q.value = document.form1.hiddenq.value ;
}



