﻿// JavaScript Document

var flag=false;
var msg,Timer;
var WebUrl='http://www.vaculock.com.cn/';
//var imgw,imgh,imgid;
//比例缩小图片
function DrawImage(ImgD,w,h){ 
 var image=new Image(); 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= w/h){ 
   if(image.width>w){
    ImgD.width=w; 
    ImgD.height=(image.height*w)/image.width; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   //ImgD.alt="点击查看详细信息..."; 
  } 
  else{ 
   if(image.height>h){
    ImgD.height=h; 
    ImgD.width=(image.width*h)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   //ImgD.alt="点击查看详细信息..."; 
  } 
 }
}

function checkInput(e)
{
	var i,j,inputs;
	inputs = document.getElementsByTagName("input");
	for(i=0;i<e.length;i++)
	{
		for(j=0;j<inputs.length;j++)
		{
			if(e[i]==inputs[j].name)
				if(inputs[j].value.length==0)
				{
					if(inputs[j].type=="text")inputs[j].focus();
					return false;
				}
		}
	}
	return true;
}


function selectCheckbox(n,o)
{
	/*
	*checkbox选择函数
	*n => checkbox的name值
	*o => 操作符(all,none,rev)
	*/
	var cbList = document.getElementsByName(n);
	var i;
	for(i=0;i<cbList.length;i++)
	{
		if(o=="all")
		{
			cbList[i].checked=true;
		}
		else if(o=="none")
		{
			cbList[i].checked=false;
		}
		else if(o=="rev")
		{
			if(cbList[i].checked==true)
				cbList[i].checked=false;
			else
				cbList[i].checked=true;
		}
	}
}

function submitForm(n,t)
{
	if(t!="")
		if(!confirm(t))
			return false;
	eval(n).submit();
}

function uploadImage(url,from,to)
{
	var width=550;
	var height=260;
	var f = false,t = false;
	if(from!='') f = document.getElementById(from);
	if(to!='') t = document.getElementById(to);
	var result=showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no");
	if(!result)
		if(f&&f.tagName=="INPUT"&&f.value!=""&&t)
		{
			getAttachmentLink(f.value,t.id);
			increaClearBtn(from,to);
		}
}

function getAttachmentLink(id,target)
{
	var html='';
	var t = document.getElementById(target);
	if(t)
	{
		if(id.toString().search(",")!=-1)
		{
			var idarray=id.split(',');
			for(var i=0;i<idarray.length;i++)
				html+='<a href="'+getAttachmentURL(idarray[i])+'" target="_blank" style="color:#FC0000;">'+(i+1)+'<a>,';
			t.innerHTML = '{点击查看:'+html.slice(0,html.length-1)+'}';
		}else{
			t.innerHTML='{<a href="'+getAttachmentURL(id)+'" target="_blank" style="color:#FC0000;">点击查看<a>}';
		}
		t.style.display = "";
	}
}

function increaClearBtn(f,t)
{
	var targetObj = document.getElementById(t);
	targetObj.innerHTML = targetObj.innerHTML + '&nbsp;<a title="删除" href="javascript:void(0);" style="color:#EC0000;border:1px solid #E00; padding:0 2px;" onclick="clearAttachment(\''+f+'\',\''+t+'\');">X</a>';
}

function clearAttachment(i,t)
{
	var inputObj = document.getElementById(i);
	var displayObj = document.getElementById(t);
	inputObj.value = '';
	displayObj.innerHTML = '';
	displayObj.style.display = 'none';
}

function getAttachmentURL(id)
{
	var baseURL = getBaseURL('admin/')+'UploadFiles/';
	var url = "response.asp?t=attachment&g=PostContent&PostID="+id;
	url = baseURL+getResponse(url);
	return url;
}

function getBaseURL(e)
{
	var baseURL = location.host+location.pathname;
	var arr = baseURL.split("/");
	baseURL = 'http://'+baseURL.replace(arr[arr.length-1],'').replace(e,'');
	return baseURL;
}

function getResponse(url)
{
	var xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
	xmlobj.open("POST",url,false); 
	xmlobj.send();
	var strResult = unescape(xmlobj.responseText);
	return strResult;
}

warning = function (e,w,h)
{
	var msg = new CMSMsgBox();
	msg.Width = w || 300;
	msg.Height = h || 80;
	msg.Mask = true;
	msg.Skin = 'loading';
	msg.DblClick = false;
	msg.Value = '<div style="margin:9px;">提示：</div><div style="margin:9px;padding:6px;">'+e+'<li><a href="javascript:history.back();">返回上一页</a></li></div>';
	msg.show();
}

function postSubmit(e)
{
	if(!checkInput(arguments))
		alert("请填写完所有“必填”项目")
	else
		Submit_form();
	return false;
}

function checkAllBox(e)
{
	if(e.checked==true)
		selectCheckbox(e.value,'all');
	else
		selectCheckbox(e.value,'none');
}

function uploadMoreImage(url,from,to,num)
{
	var width=550;
	var height=260;
	var f = false,t = false;
	if(from!='') f = document.getElementById(from);
	if(to!='') t = document.getElementById(to);
	var current = f.value;
	var oLength = current.length;
	var nLength = current.replace(/,/g,"");
	nLength = nLength.length;
	var result=showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no");
	if(!result)
	{
		if(oLength-nLength>=3)
			alert("最多只能添加"+num+"张图片");
		else{
			if(current!=f.value)
			{
				if(current!='')
					current+=","+f.value;
				else
					current=f.value;
				f.value = current;
				if(f&&f.tagName=="INPUT"&&f.value!=""&&t)
				{
					getAttachmentLink(f.value,t.id);
					increaClearBtn(from,to);
				}
			}
		}
	}
}

commentInfo = function(pid,w,h)
{
	var msg = new CMSMsgBox();
	msg.Width = w || 500;
	msg.Height = h || 480;
	msg.Mask = true;
	msg.Title = '详细信息:';
	msg.AfterClose = function(){location.reload();}
	msg.Value = '<iframe width="96%" style="margin:auto;" height="96%" scrolling="auto" name="innerView" frameborder="0" src="'+pid+'"></iframe>';
	msg.show();
}


function DrawContentImage(targDiv,w,h)
{
	var imgw=w || 400;
	var imgh=h || 300;
	var imgid;
	var Imgs = document.getElementById(targDiv).getElementsByTagName("img");
	for(var i=0;i<Imgs.length;i++)
	{
		imgid=Imgs[i];
		Imgs[i].onload = function(){DrawImage(imgid,imgw,imgh);};
	}
}

function Msg_Box(val,title,w,h,fun,show)
{
	msg = new CMSMsgBox();
	msg.Width = w || 500;
	msg.Height = h || 260;
	msg.Mask = true;
	msg.Title = title || '详细信息:';
	msg.AfterClose = fun || function(){location.reload();}
	msg.Value = val;
	msg.OverFlow = 'visible';
	if(show)msg.show();
}

changeOrder = function(id,e)
{
	var oo = e||'';
	var innerhtml = '<iframe width="96%" style="margin:auto;" height="96%" scrolling="none" name="innerView" frameborder="0" '
	innerhtml += ' src="changeorder.asp?id='+id+'&orderno='+oo+'"></iframe>';
	Msg_Box(innerhtml,'修改排序',220,155,null,true);
}

selectCity = function()
{
	var innerValue = '<table width="98%" border="0" cellspacing="1" cellpadding="5"><tr><td align="center">';
	innerValue += '<img src="'+WebUrl+'admin/Image/loading.gif" width="39" height="39" /><br />数据加载中...</td></tr></table>';
	Msg_Box(innerValue,'选择城市',520,180,function(){return;},true)
	gotCity('Province');
}

gotCity = function(tab,pid)
{
	if(tab=='')return;
	var url = WebUrl+'admin/response.asp?t=city';
	url += '&g='+tab+'&pid=';
	url += pid||'';
	var result = getResponse(url);
	msg.setValue(result);
}

putCity = function(city)
{
	if(city=='')return;
	document.getElementById('city').value = city;
	msg.close();
}