String.prototype.lengthW = function() 
{ 
	return this.replace(/[^\x00-\xff]/g,"**").length; 
} 

String.prototype.trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function checkNum(ctrl, message)
{
	var ret = isNaN(ctrl.value);
	if (ret)
	{
		alert(message);
		ctrl.focus();
		return false;
	}
	return true;
}
function changeSelect(ctrl, str) 
{
	if (str == '')
		return;
	with (ctrl) {
		len = options.length;
		for (i = 0; i < len; i++)
			if (options[i].value == str)
				break;
		if ( i < len )
			selectedIndex = i;
	}
}

function checkFormControl(ctrl, message)
{
	if (ctrl.value == "")
	{
		alert(message);
		ctrl.focus();
		return false;
	}
	return true;
}

function RefreshSelect(ctrl, strList)
{
	ctrl.options.length = 0;
	for (var i = 0; i < strList.length; i += 2)
	{
		ctrl.options[ctrl.options.length] = new Option(strList[i], strList[i + 1]);
	}
}

function RefreshAreaAndPrice()
{
	RefreshArea();
	RefreshPrice()
}

function RefreshArea()
{
	var strHouseAreaList =["不限", "", "50㎡以下", "0-50", "50-70㎡", "50-70" , "70-90㎡" , "70-90" , "90-100㎡" , "90-100" , "100-120㎡" , "100-120" , "120-130㎡" , "120-130" , "130-150㎡" , "130-150" , "150-180㎡" , "150-180" , "180-200㎡" , "180-200" , "200-250㎡" , "200-250" , "250-300㎡" , "250-300" , "300-400㎡" , "300-400" , "400-500㎡" , "400-500" , "500㎡以上" , "500-999999" ];
	var strShopAreaList =["不限", "" , "10㎡以下" , "0-10" , "10-20㎡" , "10-20" , "20-30㎡" , "20-30" , "30-40㎡" , "30-40" , "40-50㎡" , "40-50" , "50-60㎡" , "50-60" , "60-80㎡" , "60-80" , "80-100㎡" , "80-100" , "100-120㎡" , "100-120" , "120-150㎡" , "120-150" , "150-180㎡" , "150-180" , "180-200㎡" , "180-200" , "200-250㎡" , "200-250" , "250-300㎡" , "250-300" , "300-400㎡" , "300-400" , "400-500㎡" , "400-500" , "500-800㎡" , "500-800" , "800-1000㎡" , "800-1000" , "1000㎡以上"	, "1000-999999"];
	var strOfficeAreaList =["不限", "" , "50㎡以下" , "0-50" , "50-70㎡" , "50-70" , "70-90㎡" , "70-90" , "90-100㎡" , "90-100" , "100-120㎡" , "100-120" , "120-130㎡" , "120-130" , "130-150㎡" , "130-150" , "150-180㎡" , "150-180" , "180-200㎡" , "180-200" , "200-250㎡" , "200-250" , "250-300㎡" , "250-300" , "300-400㎡" , "300-400" , "400-500㎡" , "400-500" , "500-800㎡" , "500-800" , "800-1000㎡" , "800-1000" , "1000㎡以上" , "1000-999999" ];

	if (document.all.house_purpose.value >= 1 && document.all.house_purpose.value <=3)
		RefreshSelect(document.all.house_area, strHouseAreaList);
	else if (document.all.house_purpose.value == 4)
		RefreshSelect(document.all.house_area, strShopAreaList);
	else if (document.all.house_purpose.value == 5)
		RefreshSelect(document.all.house_area, strOfficeAreaList);
	else
		RefreshSelect(document.all.house_area, strHouseAreaList);
}

function RefreshPrice()
{
	var strBuyHousePriceList =["不限", "", "10万以下", "0-10", "10-15万元", "10-15", "15-20万元", "15-20", "20-25万元", "20-25", "25-30万元", "25-30", "30-35万元", "30-35", "35-40万元", "35-40", "40-45万元", "40-45", "45-50万元", "45-50", "50-55万元", "50-55", "55-60万元", "55-60", "60-65万元", "60-65", "65-70万元", "65-70", "70-80万元", "70-80", "80-100万元", "80-100", "100万元以", "100-999999"];
	var strBuyShopPriceList =["不限", "", "10万以下",  "0-10", "10-15万元", "10-15", "15-20万元", "15-20", "20-25万元", "20-25", "25-30万元", "25-30", "30-35万元", "30-35", "35-40万元", "35-40", "40-45万元", "40-45", "45-50万元", "45-50", "50-55万元", "50-55", "55-60万元", "55-60", "60-65万元", "60-65", "65-70万元", "65-70", "70-80万元", "70-80", "80-100万元", "80-100", "100-200万元","100-200", "200-300万元","200-300", "300-400万元","300-400", "400万元以上","400-999999"];
	var strBuyOfficePriceList =["不限", "", "30万以下", "0-30", "30-40万元", "30-40", "40-50万元", "40-50", "50-60万元", "50-60" , "60-70万元", "60-70" , "70-80万元", "70-80" , "80-100万元", "80-100" , "100-120万元", "100-120" , "120-150万元", "120-150" , "150-180万元", "150-180" , "180-200万元", "180-200" , "200-300万元", "200-300" , "300-400万元", "300-400" , "400-500万元", "400-500" , "500万元以上", "500-999999" ];
	var strRentPriceList =["不限", "", "200以下", "0-200" , "200-300元", "200-300" , "300-400元", "300-400" , "400-500元", "400-500" , "500-600元", "500-600" , "600-800元", "600-800" , "800-1000元", "800-1000" , "1000-1200元", "1000-1200" , "1200-1500元", "1200-1500" , "1500-1800元", "1500-1800" , "1800-2000元", "1800-2000" , "2000-2500元", "2000-2500" , "2500-3000元", "2500-3000" , "3000-4000元", "3000-4000" , "4000-5000元", "4000-5000" , "5000元以上", "5000-999999"]; 

	if (document.all.trade_type.value == 1 || document.all.trade_type.value == 3)
	{
		if (document.all.house_purpose.value >= 1 && document.all.house_purpose.value <=3)
			RefreshSelect(document.all.price, strBuyHousePriceList);
		else if (document.all.house_purpose.value == 4)
			RefreshSelect(document.all.price, strBuyShopPriceList);
		else if (document.all.house_purpose.value == 5)
			RefreshSelect(document.all.price, strBuyOfficePriceList);
		else
			RefreshSelect(document.all.price, strBuyHousePriceList);
	}
	else
		RefreshSelect(document.all.price, strRentPriceList);
}

function limitTextArea(ctrl, maxlength)
{
	if (ctrl.value.lengthW() > maxlength)
	{
		alert("输入的长度太长，请重新修改！");
		ctrl.focus();
		return false;
	}
	return true;
}

/* 图片上传函数
 例子:图片名字为house_pic1

1.在HTML里面添加如下部分
<TABLE name="tbl_house_pic1" id="tbl_house_pic1" cellnum=0><TR></TR></TABLE>
        <input id="house_pic1" type="hidden" name="house_pic1" />
    <a href="javascript:uploadpic('../', 'house_pic1', 2)">上传(可以多幅)</a>
	
	
2.在onload的时候调用
   load_piclist('../', '<%=rs("house_pic1")%>', 'house_pic1');
   将数据库中的图片列表加载到tbl_house_pic1表格中

3.在checkForm中调用
   save_piclist('house_pic1');
   将tbl_house_pic1表格中的图片列表写到 hidden的house_pic1控件中，再上传到服务器动态页面
 */
// 上传图片，参数：
// path：网站根目录相对于当前目录的路径，如 "../"或者""
// image_name： input控件的名字，如"house_pic1"
// max_num：最大图片数
function uploadpic(path, image_name, max_num)
{
	var table = document.getElementById("tbl_" + image_name);
	var r1 = table.rows[0];
	if (r1.cells.length >= max_num)
	{
		alert("您已经上传了" + max_num + "个图片，请先删除旧的图片再上传！");
		return;
	}

  	var arr = showModalDialog(path + "pic_up.asp", "", "dialogWidth:26.5em; dialogHeight:10em; status:0;help:0");
	if (arr == null)
  		return;
  
	var ss;
	ss=arr.split("*");
	a=ss[0];
	a = a.replace(/uploadfile\/(\w+)\/(gif|jpg|png|bmp)\//,"uploadfile/$2/");
	b=ss[1];
	c=ss[2];
	d=ss[3];
	e=ss[4];
	f=ss[5];
	
	var c1 = r1.insertCell(-1);
	c1.index = table.cellnum++;
	c1.picname = a;
	c1.picalt = b;
	a = path + a;
	var str = "<a title=点击图片看全图 target='_blank' href='"+a+"'><img src='"+a+"' alt='"+b+"' border=0 width=60 height=60></a>";
	str += "<BR><a class='from' href='#' onclick='javascript:delete_cell();'>删除</a>";
	c1.innerHTML=str;
}

function load_piclist(path, piclist, image_name)
{
	var pics;
	pics = piclist.split("|");
	var table = document.getElementById("tbl_" + image_name);
	var r1 = table.rows[0];
	var c1;
	var ss;
	var a;
	var b;
	var str;
	for (i = 0; i < pics.length; i++)
	{
		if (pics[i] == "")
			continue;
		ss = pics[i].split("*");
		a = ss[0];
		b = ss[1];
		if (b == null) b = '';
		c1 = r1.insertCell(table.cellnum);
		c1.index = table.cellnum++;
		c1.picname = a;
		c1.picalt = b;
		a = path + a;
		str = "<a title=点击图片看全图 target='_blank' href='"+a+"'><img src='"+a+"' alt='"+b+"' border=0 width=60 height=60></a>";
		str += "<BR><a onclick='javascript:delete_cell();'>删除</a>";
		c1.innerHTML = str;
	}
}

function save_piclist(image_name)
{
	var table = document.getElementById("tbl_" + image_name);
	var txt_ctrl = document.getElementById(image_name);
	var r1 = table.rows[0];
	var str;
	var picpath;
	txt_ctrl.value = "";
	for (i = 0; i < r1.cells.length; i++)
	{
		picpath=r1.cells[i].picname;
		picpath=picpath.toLowerCase().substr(picpath.toLowerCase().indexOf("uploadfile"));//图片路径调整，为了适应合并后系统的调整070429
		str = picpath;
		if (r1.cells[i].picalt != "")
			str = str + "*" + r1.cells[i].picalt;
		if (txt_ctrl.value.length == 0)
			txt_ctrl.value = str;
		else
			txt_ctrl.value = txt_ctrl.value + "|" + str;
	}
}

function delete_cell()
{
	var cell = event.srcElement;
	if (cell.tagName.toLowerCase() != "td")
		cell = cell.parentElement;
	var row = cell.parentElement;
	for (i = 0; i < row.cells.length; i++)
   	{
   		if (row.cells[i].index == cell.index)
   		{
   			row.deleteCell(i);
   			break;
   		}
	}
}
// 图片上传部分结束

//修改maclog
function modify_item(item_x,id){
//alert('ok'+ item_x+","+id);
var con_v=showModalDialog("modify_maclog.asp?id=" + id + "&item=" + item_x ,"","dialogWidth:13em;dialogHeight:4em;help:no;resizable:no;scroll:no;status:no;");
var div_id = (item_x+id).trim();
if (con_v != undefined){
document.getElementById(div_id).innerHTML = con_v;
}
else
{
alert('很遗憾，修改未成功！')
}
}
