var imageext = new Array('jpg', 'jpeg', 'gif', 'png');
var flashext = new Array('swf');

function strLen(str) {
	var charset = is_ie ? document.charset : document.characterSet;
	var len = 0;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset.toLowerCase() == "utf-8" ? 3 : 2) : 1;
	}
	return len;
}

function fileext(filename) {
	if(filename == null || filename == '') {
		return '';
	}
	var ext = null;
	var num = filename.lastIndexOf(".");
	if(num != -1) {
		ext = filename.substring(num + 1);
	} else {
		ext = '';
	}
	return ext;
}

function isfileext(filename, extarr) {
	var ext = fileext(filename).toLowerCase();
	for(var i = 0; i < extarr.length; i++) {
		if(extarr[i] == ext){
			return true;
		}
	}
	return false;
}

function fill(setid, parentid, arr, value) {
	setid = document.getElementById(setid);
	if(setid != null) {
		setid.options[0]=new Option('请选择','');
		opt = 0;
		if(parentid == '') {
			for(i=0;i<arr.length;i++) {
				setid.options[i+1]=new Option(arr[i][1],arr[i][0]);
				if(arr[i][1] == value) {
					opt = i+1;
				}
			}
			setid.options[opt].selected=true;
			setid.length=i+1;
		} else {
			parentcode = document.getElementById(parentid).value;
			count=1;
			if(parentcode != '') {
				for(i=0;i<arr.length;i++) {
					if(arr[i][0].toString().substring(0,parentcode.length)==parentcode.substring(0, parentcode.length)) {
						setid.options[count]=new Option(arr[i][1],arr[i][0]);
						if(value != null && arr[i][1] == value) {
							opt = count;
						}
						count=count+1;
					}
				}
			}
			setid.options[opt].selected=true;
			setid.length=count;
		}
	}
}

function validate(theform) {
	if(fieldinfo.length > 0) {
		for(i = 0; i < fieldinfo.length; i++) {
			obj = null;
			if(fieldinfo[i][2] == 'checkbox' && fieldinfo[i][4] == '1') {
				ischoose = false;
				var nodes = document.getElementsByTagName('input');
				if(nodes) {
					for(j = 0; j < nodes.length; j++) {
						var node = nodes[j];
						if (node.name == fieldinfo[i][0]+'[]') {
							if(obj == null) obj = node;
							if(node.checked == true) {
								ischoose = true;
								break;
							}

						}
					}
					if(!ischoose) {
						alert('请您选择一个'+fieldinfo[i][1]);
						obj.focus();
						return false;
					}
				}
			} else {
				ischoose = true;
				obj = document.getElementById(fieldinfo[i][0]);
				if(fieldinfo[i][4] == '1' && obj && strLen(obj.value) < 1) {
					ischoose = false;
					if(fieldinfo[i][2] == 'text' || fieldinfo[i][2] == 'textarea') {
						alert('请您输入'+fieldinfo[i][1]);
					} else if(fieldinfo[i][2] == 'img' || fieldinfo[i][2] == 'flash' || fieldinfo[i][2] == 'file' || fieldinfo[i][2] == 'timestamp') {
						objvalue = document.getElementById(fieldinfo[i][0]+'_value');
						if(obj && strLen(objvalue.value) < 1) {
							alert('您未设置'+fieldinfo[i][1]+',请检查确认');
						} else {
							ischoose = true;
						}
					} else {
						alert("请您选择一个"+fieldinfo[i][1]);
					}
				}
				if(obj && obj.value != '') {
					if(fieldinfo[i][2] == 'text' || (fieldinfo[i][2] == 'textarea' && fieldinfo[i][3] != 0)) {
						if(fieldinfo[i][5] != 'TEXT' && fieldinfo[i][5] != 'MEDIUMTEXT' && fieldinfo[i][5] != 'LONGTEXT' && fieldinfo[i][5] != 'FLOAT' && fieldinfo[i][5] != 'DOUBLE') {
							if (strLen(obj.value) > fieldinfo[i][3]) {
								ischoose = false;
								alert('您输入的'+fieldinfo[i][1]+'长度不符合要求,目前长度为'+strLen(obj.value)+'字符,请保证在'+fieldinfo[i][3]+'字符以内');
							}
						}
					} else if(fieldinfo[i][2] == 'img' || fieldinfo[i][2] == 'flash') {
						if (!isfileext(obj.value, (fieldinfo[i][2] == 'img' ? imageext : flashext))) {
							ischoose = false;
							alert('您输入的'+fieldinfo[i][1]+'格式不正确,请检查确认');
						}
					}
				}
				if(!ischoose) {
					obj.focus();
					return false;
				}
			}
		}
	}

	return true;
}

var fieldinfo = new Array(
new Array('subject', '物业名称', 'text', '80', '1', 'CHAR'),
new Array('catid', '楼盘分类', 'select', '6', '1', 'SMALLINT'),
new Array('subjectimage', '效果图', 'img', '80', '0', 'CHAR'),
new Array('loupanzx_wuyelb', '物业类型', 'checkbox', '15', '0', 'VARCHAR'),
new Array('loupanzx_lx', '建筑类型', 'checkbox', '12', '0', 'VARCHAR'),
new Array('loupanzx_zx', '装修情况', 'checkbox', '9', '0', 'VARCHAR'),
new Array('loupanzx_province', '省份', 'text', '20', '0', 'VARCHAR'),
new Array('loupanzx_city', '城市（默认为北京）', 'text', '10', '0', 'VARCHAR'),
new Array('loupanzx_allchengqu', '城区(全国)', 'text', '15', '0', 'VARCHAR'),
new Array('loupanzx_weizhi', '项目位置', 'text', '60', '1', 'VARCHAR'),
new Array('loupanzx_junjia', '均价', 'text', '0', '1', 'FLOAT'),
new Array('loupanzx_dizhi', '详细地址', 'text', '200', '0', 'VARCHAR'),
new Array('xp_dianhua', '售楼电话', 'text', '50', '1', 'VARCHAR'),
new Array('loupanzx_wyf', '物业费', 'text', '0', '1', 'FLOAT'),
new Array('loupanzx_rjl', '容积率', 'text', '0', '1', 'FLOAT'),
new Array('loupanzx_lhl', '绿化率', 'text', '0', '1', 'FLOAT'),
new Array('loupanzx_url', '楼盘网址(必须加http://)', 'text', '50', '0', 'VARCHAR'),
new Array('loupanzx_jianzhumj', '建筑面积(单位:万平米)', 'text', '6', '1', 'VARCHAR'),
new Array('loupanzx_shoufu', '按揭首付', 'text', '2', '0', 'SMALLINT'),
new Array('loupanzx_video', '视频链接', 'text', '150', '0', 'VARCHAR'),
new Array('loupanzx_zhoubianpt', '周边配套', 'textarea', '0', '0', 'LONGTEXT'),
new Array('loupanzx_xiangguanxx', '相关信息(包括交通和其他信息)', 'textarea', '0', '0', 'LONGTEXT'),
new Array('loupanzx_xg2', '效果图03', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_xg', '效果图01', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_xg1', '效果图02', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_xg3', '效果图04', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_jt', '交通图', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_wj', '外景图01', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_wj1', '外景图02', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_wj2', '外景图03', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_wj3', '外景图04', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_yb01', '样板间01', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_yb02', '样板间02', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_yb03', '样板间03', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_yb04', '样板间04', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_hxt0', '户型图', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_hxt1', '户型图1', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_hxt2', '户型图2', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_hxt3', '户型图3', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_hxt4', '户型图4', 'img', '150', '0', 'VARCHAR'),
new Array('loupanzx_wuye', '物业公司', 'text', '50', '0', 'VARCHAR'),
new Array('loupanzx_kfs', '开发商', 'text', '80', '1', 'VARCHAR'),
new Array('loupanzx_xkz', '预售许可证', 'text', '80', '0', 'VARCHAR'),
new Array('xp_lianxiren', '联系人', 'text', '50', '0', 'VARCHAR')
);
