﻿//JavaScript Document

//Confirm Before Delete
function deleteAll(objForm,confirmWord)
{
  if(!confirm(confirmWord))
  { return false;
  } else if(objForm)
  {
   objForm.action ="";
   objForm.frmAction.value = "delete";
   objForm.submit();
  }
}

//Check All Items
function checkAll(tagName,refCheckbox)
{
   var a = document.getElementsByTagName("input");
   for (var i=0; i<a.length; i++)
   {
      if (a[i].type == "checkbox" && a[i].name==tagName)
	  a[i].checked = refCheckbox.checked;
   }
}

//retrim Html Context To Text Context
function Rstr(strContent,intLength)
{
	var aDiv = document.createElement("div");
	//aDiv.setAttribute("id","aTempDiv");
	//document.appendChild(aDiv);
	aDiv.setAttribute("innerHTML",strContent);
	//aTempDiv.innerHTML = strContent;
	var newContent = aTempDiv.innerText.substring(0,intLength-3)+"...";
	aDiv = null;
	//document.removeChild(aDiv);
	return(newContent);
}

//Auto Load Css Or Link File
/*
Parameters:
path : Path Of The Included File
type : js or css  ,in lower case
title : Title of the new include File

Java Sctipt File List

1. calendar.js
Usage : <input type="text" name="test1" onClick="ShowCalendar(this.name);"> <input type="button" value="show" onClick="ShowCalendar('test1');">

2. checkform.js
Usage: See detials on its own page
*/
function $import(path,type,title){
 var s,i;
 if(type=="js"){
  var ss=document.getElementsByTagName("script");
  for(i=0;i<ss.length;i++){
   if(ss[i].src && ss[i].src.indexOf(path)!=-1)return;
  }
  s=document.createElement("script");
  s.type="text/javascript";
  s.src=path;
 }else if(type=="css"){
  var ls=document.getElementsByTagName("link");
  for(i=0;i<ls.length;i++){
   if(ls[i].href && ls[i].href.indexOf(path)!=-1)return;
  }
  s=document.createElement("link");
  s.rel="alternate stylesheet";
  s.type="text/css";
  s.href=path;
  s.title=title;
  s.disabled=false;
 }
 else return;
 var head=document.getElementsByTagName("head")[0];
 head.appendChild(s);
}

function getXMLDocument() {
    var xDoc = null;
    if (document.implementation && document.implementation.createDocument) {
        xDoc = document.implementation.createDocument("", "", null);
    } else {
        if ((typeof ActiveXObject) != "undefined") {
            var msXmlAx = null;
            try {
                msXmlAx = new ActiveXObject("Msxml2.DOMDocument");
            }
            catch (e) {
                msXmlAx = new ActiveXObject("Msxml.DOMDocument");
            }
            xDoc = msXmlAx;
        }
    }
    if (xDoc == null || typeof xDoc.load == "undefined") {
        xDoc = null;
    }
    return xDoc;
}

function pictureFilter(strContent, strUploadPath, strStorePath) {
	return(strContent.replace(/\{#Xml_Path#\}/ig, Xml_Path));
}

function createXMLHttpRequest() {
	var xmlHttp = null;
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else {
		var msxml = new Array("Msxml2.XMLHTTP.5.0", 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP');
		for(var n = 0; n < msxml.length; n++) {
			try {
				xmlHttp = new ActiveXObject(msxml[n]);
				break;
			} catch(e) {
				xmlHttp = null;
			}
		}
	}
	return(xmlHttp);
}

function fetchUrl(strUrl)
{
	var rtnVal = null;
	try {
		objXmlHttp = createXMLHttpRequest();
		objXmlHttp.open("GET", strUrl, false);
		objXmlHttp.onreadystatechange = function() {
			if(objXmlHttp.readyState == 4) {
				if(objXmlHttp.status == 200) {
					rtnVal = objXmlHttp.responseXML;
					objXmlHttp = null;
				}
			}
		};
		objXmlHttp.send(null);
		return(rtnVal);
	} catch(e) {
		return(rtnVal);
	}
}

function formPicture(strSource,intWidth,intHeight)
{
	if(strSource == null || strSource.length == 0)
	{
		return("");
	}
	if(strSource.substring(strSource.length-3,strSource.length).toLowerCase() == "swf")
	{
		var strSwfString = "";
		strSwfString +="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+intWidth+"\" height=\""+intHeight+"\" >\r\n";
		strSwfString +="<param name=\"movie\" value=\""+strSource+"\" />\r\n";
		strSwfString +="<param name=\"quality\" value=\"high\" />\r\n";
		strSwfString +="<param name=\"wmode\" value=\"transparent\" />\r\n";
		strSwfString +="<embed src=\""+strSource+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+intWidth+"\" height=\""+intHeight+"\" ></embed>\r\n";
		strSwfString +="</object>\r\n";
		return(strSwfString);
	}
	else
	{
		return("<img src=\""+strSource+"\" width=\""+intWidth+"\" height=\""+intHeight+"\" border=\"0\" />");
	}
}


//生成Input Dom对象
function createInput(strType, strName, strCssName, strValue) {
	//strType = 类型("text", "button", "submit")
	//strName = 名称&ID
	//strCssName = 使用的样式表名称
	//strValue = 默认值(对于button和submit为按钮显示文字)
	var objInput = document.createElement("INPUT");
	if(typeof(strType) == "undefined") {
		objInput.setAttribute("type", "text");
	} else {
		objInput.setAttribute("type", strType);
	}
	if(typeof(strName) != "undefined" && typeof(strName) == "string")objInput.setAttribute("name", strName);
	if(typeof(strName) != "undefined" && typeof(strName) == "string")objInput.setAttribute("id", strName);
	if(typeof(strCssName) != "undefined" && typeof(strCssName) == "string")objInput.setAttribute("className", strCssName);
	if(typeof(strValue) != "undefined" && typeof(strValue) == "string")objInput.setAttribute("value", strValue);
	return objInput;
}

//生成TR Dom对象

/*TR和TD必须作为TBody的childElement插入*/
function createTr(strCssName) {
	//strCssName = 样式表名称
	var objEl = document.createElement("TR");
	if(typeof(strCssName) != "undefined" && typeof(strCssName) == "string") objEl.setAttribute("className", strCssName);
	return objEl;
}

//生成TD Dom对象
function createTd(strAlign, strText) {
	//strAlign = 对齐方式
	//strText = 内部显示文字，支持HTML标签的插入
	var objEl = document.createElement("TD");
	if(typeof(strAlign) != "undefined" && typeof(strAlign) == "string") objEl.setAttribute("align", strAlign);
	if(typeof(strText) != "undefined" && typeof(strText) == "string") objEl.setAttribute("innerHTML", strText);
	return objEl;
}

function fillInput(objInputObject,strCheckValue)
{
	var objTargetInput = null;
	if(typeof(objInputObject) == "object" && (objInputObject.getAttribute("tagName").toLowerCase() == "input" || objInputObject.getAttribute("tagName").toLowerCase() == "select"))
	{
		objTargetInput = objInputObject;
	}
	else
	{
		objTargetInput = document.getElementById(objInputObject);
		if(!typeof(objTargetInput) == "object" || (objTargetInput.getAttribute("tagName").toLowerCase() != "input" && objTargetInput.getAttribute("tagName").toLowerCase() != "select"))
		{
			return;
		}
	}
	if(!strCheckValue)
	{
		strCheckValue = "";
	}
	var arrCheckValue = strCheckValue.split(",")

	var strType = objTargetInput.getAttribute("type");
	if(objTargetInput.getAttribute("tagName").toLowerCase() == "select")
	{
		for(var i=0;i<objTargetInput.options.length;i++)
		{
			for(var j=0;j<arrCheckValue.length;j++)
			{
				if(objTargetInput.options[i].getAttribute("value") == arrCheckValue[j])
				{
					objTargetInput.options[i].setAttribute("selected","true");
				}
			}
		}
	}
	else if(objTargetInput.getAttribute("tagName").toLowerCase() == "input")
	{
		switch(strType.toLowerCase())
		{
			case "radio":
				var objRadioInputs = document.getElementsByName(objInputObject);
				for(var i=0;i<objRadioInputs.length;i++)
				{
					for(var j=0;j<arrCheckValue.length;j++)
					{
						if(objRadioInputs[i].getAttribute("value") == arrCheckValue[j])
						{
							objRadioInputs[i].setAttribute("checked","true");
						}
					}
				}
				break;
			case "checkbox":
				var objCheckboxInputs = document.getElementsByName(objInputObject);
				for(var i=0;i<objCheckboxInputs.length;i++)
				{
					for(var j=0;j<arrCheckValue.length;j++)
					{
						if(objCheckboxInputs[i].getAttribute("value") == arrCheckValue[j])
						{
							objCheckboxInputs[i].setAttribute("checked","true");
						}
					}
				}
				break;
		}
	}
}

function sMarquee(strInstansName) {
	/**
	 *Super Maquree, 滚动图片, 字幕
	 *@object sMaquree(strInstansName, varSlide[, [strDirection,] [intWidth,] [intHeight,] [intScrollSpeed,] [intPause,] [intDelay,] [intMode,] [strBgColor]])
	 *
	 *@array setContent 设定滚动内容
	 *@string setDirection 设定滚动方向
	 *@variable setWidth 设定滚动区域宽度
	 *@variable setHeight 设定滚动区域高度
	 *@integer setScrollSpeed 设定滚动速度
	 *@integer setPause 设定移动间隔
	 *@integer setDelay 设定每页滚动间隔
	 *@integer setMode  滚动模式 0=页面模式, 1=行模式
	 *@string setBgColor 设定滚动区域背景颜色
	 *@void move() 开始滚动
	*/
	if(typeof(strInstansName) == "undefined") return false;

	var arrSlide = arguments[1];
	var intContextLength = arrSlide.length;
	if(intContextLength == 0) return false;

	var arrDefault = ["", "", "up", "100%", "100", "5", "6400", "50", "0"]
	var arrArgs = ["", "", "direction", "scrollwidth", "scrollheight", "scrollspeed", "pausebetweenimages", "delay", "mode"];
	var blnComplete = true;

	for(var i = 2; i <= 8; i++) {
		if(typeof(arguments[i]) == "undefined") {
			blnComplete = false;
			if(i == 2) {
				eval(arrArgs[i] + " = \"" + arrDefault[i] + "\";");
			} else {
				eval(arrArgs[i] + " = " + arrDefault[i] + ";");
			}
		} else {
			if(i == 2) {
				eval(arrArgs[i] + " = \"" + arguments[i] + "\";");
			} else {
				eval(arrArgs[i] + " = " + arguments[i] + ";");
			}
		}
	}

	var bgColor = arguments[9];
	if(typeof(bgColor) == "undefined") bgColor = "";

	var rnd = function() {
		rnd.seed = (rnd.seed * 9301 + 49297) % 233280;
		return rnd.seed / (233280.0);
	};

	rnd.today = new Date();
	rnd.seed = rnd.today.getTime();

	var rand = function(number) {
		return Math.ceil(rnd() * number);
	};

	var clearPx = function(strPos) {
		return(parseInt(strPos.substr(0, strPos.length - 2)));
	};

	var divLoop = 0;

	var pageMove = function() {
		var tdiv0 = document.getElementById(strDivName + "_inner1");
		var tdiv1 = document.getElementById(strDivName + "_inner2");
		var posLimit;
		switch(direction.toLowerCase()) {
			case "up":
			case "down":
				posLimit = iTop;
				break;
			case "left":
			case "right":
				posLimit = iLeft;
				break;
		}

		if(eval("clearPx(tdiv" + divLoop + ".style." + strMark[2] + ") " + strMark[0] + " " + (posLimit * -1))) {
			eval("tdiv0.style." + strMark[2] + " = (clearPx(tdiv0.style." + strMark[2] + ")" + strMark[1] + scrollspeed + ") + \"px\"");
			eval("tdiv1.style." + strMark[2] + " = (clearPx(tdiv1.style." + strMark[2] + ")" + strMark[1] + scrollspeed + ") + \"px\"");
			setTimeout(strInstansName + ".move()", delay);
			return;
		}

		eval("tdiv" + divLoop + ".style." + strMark[2] + " = " + posLimit + " + \"px\"");
		if(divLoop > 0) divLoop--; else divLoop++;
		setTimeout(strInstansName + ".move();", pausebetweenimages);
	};

	var lineMove = function() {
		var tdiv = document.getElementById(strDivName + "_inner1");
		var posLimit;
		switch(direction.toLowerCase()) {
			case "up":
			case "down":
				posLimit = iTop;
				break;
			case "left":
			case "right":
				posLimit = iLeft;
				break;
		}

		if(eval("clearPx(tdiv.style." + strMark[2] + ") " + strMark[0] + " " + (posLimit * -1))) {
			eval("tdiv.style." + strMark[2] + " = (clearPx(tdiv.style." + strMark[2] + ")" + strMark[1] + scrollspeed + ") + \"px\"");
			setTimeout(strInstansName + ".move()", delay);
			return;
		}

		eval("tdiv.style." + strMark[2] + " = " + posLimit + " + \"px\"");
		setTimeout(strInstansName + ".move();", pausebetweenimages);
	};

	this.setDirection = function(strDirection) {
		direction = strDirection;
	};

	this.setScrollWidth = function(varWidth) {
		scrollwidth = varWidth;
	};

	this.setScrollHeight = function(varHeight) {
		scrollheight = varHeight;
	};

	this.setMode = function(intMode) {
		mode = intMode;
	};

	this.setScrollSpeed = function(intSpeed) {
		scrollspeed = intSpeed;
	};

	this.setPause = function(intPause) {
		pausebetweenimages = intPause;
	};

	this.setDelay = function(intDelay) {
		delay = intDelay;
	};

	this.setContent = function(arrCnt) {
		if(typeof(arrCnt) == "object") {
			arrSlide = arrCnt;
		} else {
			arrSlide = ["", ""];
		}
	};

	this.setBgColor = function(strBgColor) {
		if((/#[0-9a-fA-F]{3}|[0-9a-fA-F]{6}/).test(strBgColor))
			bgColor = strBgColor;
		else
			bgColor = "";
	};

	this.move = function() {
		if(mode == 0) pageMove(); else lineMove();
	};

	var strDivName = "demo" + rand(100);

	var iTop, iLeft, strMark;

	document.writeln('<div style="position:relative;width:'+scrollwidth+'px;height:'+ scrollheight +'px;overflow:hiden;background-color:' + bgColor + '">');
	document.writeln('<div id="' + strDivName + '" style="position:absolute;width:'+scrollwidth+';clip:rect(0 '+scrollwidth+' '+scrollheight+' 0);left:0;top:0">');
	switch(direction.toLowerCase()) {
		case "up":
			iTop = scrollheight;
			iLeft = 0;
			strMark = [">", "-", "top"];
			break;
		case "down":
			iTop = scrollheight * -1;
			iLeft = 0;
			strMark = ["<", "+", "top"];
			break;
		case "left":
			iTop = 0;
			iLeft = scrollwidth;
			strAttribute = "left";
			strMark = [">", "-", "left"];
			break;
		case "right":
			iTop = 0;
			iLeft = scrollwidth * -1;
			strAttribute = "left";
			strMark = ["<", "+", "left"];
			break;
		default :
			document.writeln('</div>');
			document.writeln('</div>');
			return;
	}

	if(mode == 1) {
		document.writeln('<div id="' + strDivName + '_inner1" style="position:absolute;width:'+ scrollwidth +'px;left:' + iLeft + 'px;top:' + iTop + 'px;">' + arrSlide[0] + '</div>');
	} else if(mode == 0) {
		document.writeln('<div id="' + strDivName + '_inner1" style="position:absolute;width:'+ scrollwidth +'px;left:0px;top:0px;">' + arrSlide[0] + '</div>');
		document.writeln('<div id="' + strDivName + '_inner2" style="position:absolute;width:' + scrollwidth + 'px;left:' + iLeft+ 'px;top:' + iTop + 'px;">' + arrSlide[1] + '</div>');
	}

	document.writeln('</div>');
	document.writeln('</div>');

	if(blnComplete) this.move();
}

function orderconfirm(productid) {
	var iWidth = 640;
	var iHeight = 480;
	var mLeft = parseInt((window.screen.availWidth - iWidth) / 2);
	var mTop = parseInt((window.screen.availHeight - iHeight) / 2);

	var strParameters = "left=" + mLeft + ", top=" + mTop + ", width=" + iWidth + ", height=" + iHeight;
	strParameters += ", menubar=no, status=0, scrollbars=yes, resizable=yes, toolbar=0";
	var strURL = Site_Url + "/productshow/product_order.asp";
	if(productid) strURL += "?pid=" + productid;
	window.open(strURL, "_blank", strParameters);
}