﻿//图片按比例缩放

var flag=false;
function JeffImage(ImgD,iwidth,iheight){
	//参数(图片,允许的宽度,允许的高度)
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else{
			if(image.height>iheight){
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}
}

function createLayer(layerId, top, left, layerHtml) {	
	var lyelm = document.getElementById(layerId);
	if(lyelm) {
		lyelm.parentNode.removeChild(lyelm);
	}
	lyelm = document.createElement('DIV');
	lyelm.id= layerId;
	lyelm.style.position = 'absolute';
	lyelm.style.top = top + 'px';
	lyelm.style.left = left + 'px';
	lyelm.innerHTML = layerHtml;
	return document.body.appendChild(lyelm);
}

function removeLayer(obj) {
	if(obj) {
		if (obj.parentNode)
		{
			obj.parentNode.removeChild(obj);
		}
		
	}
}

function getAbsTop(obj) {
	var mytop=obj.offsetTop;
	while(obj=obj.offsetParent) {
		mytop+=obj.offsetTop; 
	}
	return mytop;
}

function getAbsLeft(obj) {	
	var myleft=obj.offsetLeft;
	while(obj=obj.offsetParent){
		myleft+=obj.offsetLeft;
	}
	return myleft;
}

function popwin(windowname,h,w,url,isresize){
	var intTop = 0;
	var intLeft = 0;

	if(typeof(isresize) == 'undefined'){
			isresize='1';
	}
	if (parseInt(h) == 8888 ){
	//如果高度为8888,那么全屏显示
		w=window.screen.availWidth-10;
		h=window.screen.availHeight-20;
	}else{//分辨率为800×600，从中间呈现
		intTop = (window.screen.availHeight-parseInt(h))/2;
		intLeft = (window.screen.availWidth-parseInt(w))/2;

		if (intTop < 30)
			intTop = 0;

		if (intLeft < 30)
			intLeft = 0;
	}
  var windowconfig = "titlebar=1,status=no,scrollbars=no,top="+ intTop +",left="+ intLeft  +",resizable="+isresize+",width=" + w + ",height=" + h;
  
  var subwin=window.open(url, windowname, windowconfig);
	if (subwin){
		subwin.focus();
		return ;
	}
}

function requestAjax(url, jsid) {
	var jselm = document.getElementById(jsid);
	var loadjs;
	var jsparent;
	if(jselm) {
		jsparent = jselm.parentNode;
		jsparent.removeChild(jselm);
	}
	loadjs = document.createElement('script');
	loadjs.language = 'javascript';
	loadjs.id= jsid;
	loadjs.src = url;
	document.body.appendChild(loadjs);

}
function gopage(n) {
	var f = document.forms['sysrequery'];
	if (f) {
		var p = f.formCurrentPageNumber;
		if (p) {
			p.value = n;
		}
		f.submit();
	}
}

function turnpage(n) {
	var f = document.forms['sysrequery'];
	if (f) {
		var p = f.formCurrentPageNumber;
		if (p) {
			p.value = parseInt(p.value) + parseInt(n);
		}
		f.submit();
	}
}
function overlevel(id){
	if (self.document.getElementById("starlevelvalue"))
	{
		if (self.document.getElementById("starlevelvalue").value>0)
		{
			return ;
		}
	}
	var aryid = id.split('_');
	var commentId = aryid[0];
	var picId = aryid[1];
	var elementId;
	var i=0;
	for(i=1;i<=picId;i++){
		elementId=commentId+'_'+i+"";
		self.document.getElementById(elementId).src="/images/ico/star_green.jpg";
	}
}

function outlevel(id){
	if (self.document.getElementById("starlevelvalue"))
	{
		if (self.document.getElementById("starlevelvalue").value>0)
		{
			return ;
		}
	}
	var aryid = id.split('_');
	var commentId = aryid[0];
	var elementId;
	var i=0;
	for(i=1;i<=5;i++){
		elementId=commentId+'_'+i+"";
		self.document.getElementById(elementId).src="/images/ico/star_grey.jpg";
	}
}

String.prototype.getQueryString = function(name)
{
　　var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
　　var r = this.substr(this.indexOf("\?")+1).match(reg);
　　if (r!=null) return unescape(r[2]); return '';
}


function viewpic(pic) {
	window.open('/html/preview.html?pic=' + escape(pic));
}


function ReadCookie (CookieName) {
  var CookieString = document.cookie;

  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0; 
  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {

	 CookiePieces = CookieSet[x].split ('=');

	 if (CookiePieces[0].substring (0,1) == ' ') {
		CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);}

	 if (CookiePieces[0] == CookieName) {
		ReturnValue = CookiePieces[1];}

  }
  return ReturnValue;
}

function showCurCart()
{
	var productcount= unescape(ReadCookie('cartcount'));
	if (productcount=='')
	{
		productcount='0';
	}
	document.getElementById("cartsnav").innerHTML = '<li><a href="/bizproc/member/default.asp" target="_blank;">购物车中有'+productcount+'件商品</a></li>';
}

function viewoption(optname,optvalue) {
	window.open('/template/design/' + optname+ '.html?code=' + optvalue);
}
function readyit(obj) {
	if (obj.value == '-请输入订单编号-')
	{
		obj.value = '';
	}
}