﻿// JavaScript Document
var rootPath = '';

function CloseWindow(bNoneTip) {
	if (bNoneTip) {
		window.open('', '_self');
		window.close();
	} else
		window.close();
}

//字符串Trim
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/g, "");
}
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/g, "");
}

//XML类
function XML() {
	var me = this;
	
	this.newXMLHTTP = function () {
		var array = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];

		for (var i=0; i<array.length; i++) {
			try {
				return new ActiveXObject(array[i]);
				break;
			} catch (e) {}
		}
		try {
			return new XMLHttpRequest();
		} catch(e) {}

		return null; 
	}
	
	//读取XML文件
	this.loadXML = function (url) {
		try {
			var x = me.newXMLHTTP();
			x.open('get', url, false);
			x.send(null);
			return x.responseXML;
		} catch(e) {
			return null;
		}
	}

	this.transformNode = function (xml, xsl) {
		if (xml==null || xsl==null) return null;
		if (typeof(xml)=='string') xml = me.loadXML(xml);
		if (typeof(xsl)=='string') xsl = me.loadXML(xsl);
		if (xml==null || xsl==null) return null;
		
		try {
			if(navigator.appName!='Microsoft Internet Explorer') {
				var xslProc = new XSLTProcessor();
				xslProc.importStylesheet(xsl);
				var o = xslProc.transformToDocument(xml);
				var oXmlSerializer = new XMLSerializer();
				return oXmlSerializer.serializeToString(o);
			} else {
				return xml.transformNode(xsl);
			}
		} catch(e) {
			return null;
		}
	}
}


//拍卖出价
var doBidProductStats = true, bidBoxCT1 = 0;

function doBid(e, pID) {
	var obj = document.getElementById('doBidBox')
	if (obj==null) return;
	
	var x = new XML().loadXML(rootPath + '/ggData.asmx/getProductVenditionState?oid=' + pID);
	if(x!=null) {
		try {
			var bStart = x.documentElement.childNodes[0].nodeValue;
			if (bStart.toLowerCase().trim() == 'true') {
				var vobj = document.getElementById('doBidMain');
				vobj.innerHTML = '此商品拍卖已经结束，请您选择其它正在进行中的商品。';
				doBidProductStats = false;
			}
		} catch(ex) {
		}
	}
	
	obj.style.display = 'block';
	obj.style.zindex = 100;
	obj.style.left = (Math.round((document.documentElement.offsetWidth - obj.offsetWidth) / 2) + document.documentElement.scrollLeft) + 'px';
	obj.style.top = (document.documentElement.scrollTop + 150) + 'px';
	window.onscroll = function() {
		ScrollBid(obj);
	}
}

function ScrollBid(obj) {
	obj.style.top = (document.documentElement.scrollTop + obj.offsetTop - bidBoxCT1) + 'px';
	bidBoxCT1 = document.documentElement.scrollTop;
}

function doBidCancel() {
	var obj = document.getElementById('doBidBox');
	if (obj==null) return;
	if (doBidProductStats) {
		if(!confirm('您确定要放弃出价吗？\n\n请您确认。')) return;
	}
	obj.style.display = 'none';
	window.onscroll = null;
}

function doBidInit(){
	var mover = document.getElementById('doBidMover');
	if (!mover.setCapture) return;
	var x, y, bd = false, box = document.getElementById('doBidBox');
	mover.onmousedown = function() {
		mover.setCapture();
		x = event.offsetX;
		y = event.offsetY;
		bd = true;
	}
	mover.onmousemove = function() {
		if(bd) {
			with(box.style) {
				posLeft = document.documentElement.scrollLeft + event.x - x;
				posTop = document.documentElement.scrollTop + event.y - y;
			}
		}
	}
	mover.onmouseup = function() {
		bd = false;
		mover.releaseCapture();
	}
}