﻿// JavaScript Document
 //检查选中的类别是否存在子类
        function checkSelect(o)
        {
            var s=o.value.split(',');
            var sid=s[1];
            for(i=1;i<o.length;i++)
            {
                var a=o[i].value.split(',');
                var aid=a[0];
                if(aid==sid)
                {
                    alert("该类别存在子类,无法被选择");
                    o.selectedIndex=o.selectedIndex+1;
                    break;
                }
            }  
        }
//------------------------------修改语言------------------------------
function editLanguage(){
	document.getElementById('siteLanguageList').className="";
}
function cancelEditLanguage(){
	document.getElementById('siteLanguageList').className="hide";
}

//------------------------------显示当前页位置------------------------------
function topMenuThisPage(n){
	var topMenuLi=document.getElementById("topMenu").getElementsByTagName("li");
	for(i=0;i<topMenuLi.length;i++){
		topMenuLi[i].className="";
	}
	topMenuLi[n-1].className="thisPage";
}
function leftMenuThisPage(m,n){
	var leftMenuLi=document.getElementById("left").getElementsByTagName("ul")[m-1].getElementsByTagName("li");
	for(i=0;i<leftMenuLi.length;i++){
		leftMenuLi[i].className="";
	}
	leftMenuLi[n-1].className="thisPage";
}
function mainMenuThisPage(n){
	var mainMenuLi=document.getElementById("mainMenu").getElementsByTagName("li");
	for(i=0;i<mainMenuLi.length;i++){
		mainMenuLi[i].className="";
	}
	mainMenuLi[n-1].className="thisPage";
}
//内容管理显示当前页
function contentMenuThisPage(){
	var leftMenuLi=document.getElementById("left").getElementsByTagName("ul")[0].getElementsByTagName("li");
	var thisLocation=document.location;
	//循环判断当前页链接
	for(i=0;i<leftMenuLi.length;i++){
		var aUrl=leftMenuLi[i].getElementsByTagName("a")[0].href;
		//alert("thisLocation: "+thisLocation);
		//alert("aUrl: "+aUrl);
		if(thisLocation==aUrl){
			leftMenuLi[i].className="thisPage";
		}
		else{
			leftMenuLi[i].className="";
		}
	}
}
//内容管理子标签显示当前页
function contentSubMenuThisPage(){
	var leftMenuLi=document.getElementById("left").getElementsByTagName("ul")[0].getElementsByTagName("li");
	//var minaMenuA=document.getElementById("mainMenu").getElementsByTagName("ul")[0].getElementsByTagName("li")[0].getElementsByTagName("a")[0].href;
	//var thisLocation=minaMenuA;
	var thisLocation="menuId="+menuId;
	//循环判断当前页链接
	for(i=0;i<leftMenuLi.length;i++){
		var aUrl=leftMenuLi[i].getElementsByTagName("a")[0].href;
		aUrlArray=aUrl.split("?");
		//alert("thisLocation: "+thisLocation);
		//alert("aUrl: "+aUrlArray[0]);
		//alert(aUrlArray[1]);
		if(thisLocation==aUrlArray[1]){
			leftMenuLi[i].className="thisPage";
		}
		else{
			leftMenuLi[i].className="";
		}
	}
}

//------------------------------其他函数------------------------------

//添加友情链接 选择类型----友情链接添加页
function radioFriendLink(obj){
    if(obj.checked&&obj.value=="1")
	{
		document.getElementById('tr1').className="hide";
		document.getElementById('tr2').className="show";
	}
	else
	{
		document.getElementById('tr1').className="show";
		document.getElementById('tr2').className="hide";
	}
}
//添加友情链接 选择类型 初始化
function radioFriendLinkLoad(){
	obj=document.getElementById("typeTr").getElementsByTagName("input")[0];
    if(obj.checked&&obj.value=="0")
	{
		document.getElementById('tr1').className="show";
		document.getElementById('tr2').className="hide";
	}
	else
	{
		document.getElementById('tr1').className="hide";
		document.getElementById('tr2').className="show";
	}
}

function UrlFileName(url){
	var aUrl=url;
	aUrl=aUrl.slice(aUrl.lastIndexOf("/")+1,aUrl.length);
	if(aUrl.indexOf("?")!=-1) {
		aUrl=aUrl.slice(0,aUrl.indexOf("?"));
	}
	return aUrl
}

//获取服务器状态
function GetServerInfo()
{
    Ext.onReady(function(){
        Ext.Ajax.request({
            url:"AjaxDesktop.aspx",
            success:function(result){
                fill(result.responseText);
            }           
        });
    });
}

function fill(str)
{
    var obj=document.getElementById("maincontent");
    obj.innerHTML=str;
}

//给所有需要预览图片加预览效果
function showPic(){
	Ext.onReady(function(){
		var smallWin;
		var bigWin;
		//加事件
		var aList=document.getElementById("main").getElementsByTagName("a");
		for(i=0;i<aList.length;i++){
			var aObj = aList[i];
			var aUrl = aObj.href;
			if(aUrl.indexOf("upload")>0){
				aObj.onclick=showWindow;
			}
		}
		function mWin(){
			showWindow();
		}
		//显示预览图片窗口
		function showWindow(){
			var smallImg=new Image();
			smallImg.src=this.href;
			if(smallImg.width>640){
			    smallImg.width=640;
			}
			if(!smallWin){
				smallWin = new Ext.Window({
					el:'pic-window',
					layout:'fit',
					width:400,
					height:300,
					closeAction:'hide',
					plain: true,
					collapsible:true,
					html:'<img id="myImg" />',
					maximizable:true,
					modal:true
				});
			}
			if(smallImg.width!=0){
				smallWin.setSize(smallImg.width+15,smallImg.height+42);
			}
			smallWin.show();
			smallWin.center();
			var myPosition=smallWin.getPosition();
			if(myPosition[0]<0){
				smallWin.setPagePosition(0,myPosition[1]);
			}
			else if(myPosition[1]<0){
				smallWin.setPagePosition(myPosition[0],0);
			}
			document.getElementById("myImg").src=smallImg.href;

			return false;
		}
	});
}

//删除前的提示
function doDelete(str)
{
  if(confirm(str))
  {
   return true;
  }
  else
  {
   return false;
  }
}

//商品扩展属性
function ProductExAttributeTrLoad()
{
var obj=document.getElementById("tdAttributeNum").getElementsByTagName("select")[0];
	var num = obj.options[obj.selectedIndex].value;
	for(i=0;i<11;i++){
		if(i<num){
			document.getElementById('attributeTr'+String(i)).className="";
		}
		else{
			document.getElementById('attributeTr'+String(i)).className="hide";
		}
	}

}
//商品扩展属性
function ProductExAttributeTrShow(obj){
	var num = obj.options[obj.selectedIndex].value;
	for(i=0;i<10;i++){
		if(i<num){
			document.getElementById('attributeTr'+String(i)).className="";
		}
		else{
			document.getElementById('attributeTr'+String(i)).className="hide";
		}
	}
}

//文字水印获取颜色
function GetColor(img_val,input_val)
{
	var PaletteLeft,PaletteTop
	var obj = document.getElementById("colorPalette");
	ColorImg = img_val;
	ColorValue = document.getElementById(input_val);	
	if (obj){
		PaletteLeft = getOffsetLeft(ColorImg)
		PaletteTop = (getOffsetTop(ColorImg)-250)
		if (PaletteTop<0)PaletteTop+=ColorImg.offsetHeight+165;
		if (PaletteLeft+260 > parseInt(document.body.clientWidth)) PaletteLeft = parseInt(event.clientX)-280;
		obj.style.left = PaletteLeft + "px";
		obj.style.top = PaletteTop + "px";
		if (obj.style.visibility=="hidden")
		{
			obj.style.visibility="visible";
		}else {
			obj.style.visibility="hidden";
		}
	}
}
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}
function setColor(color)
{
	if(ColorImg.id=="FontColorShow"&&color=="#") color='#000000';
	if(ColorImg.id=="FontBgColorShow"&&color=="#") color='#FFFFFF';
	if (ColorValue){ColorValue.value = color.substr(1);}
	if (ColorImg && color.length>1){
		ColorImg.src=src='../images/Rect.gif';
		ColorImg.style.backgroundColor = color;
	}else if(color=='#'){ ColorImg.src='../images/rectNoColor.gif';}
	document.getElementById("colorPalette").style.visibility="hidden";
}



