var url = 'script/city.xml';
var xDom = xmlDom(url);
var prov = new Array();
var city = new Array();
var xhttp = new xmlHttp();
var data = {
	'diradm':''
	,'dbname':''
	,'username':''
	,'password':''
	,'repasswd':''
	,'usermail':''
	,'realname':''
	,'usersex':''
	,'province':''
	,'provcity':''
	,'address':''
	,'mobphone':''
	,'telphone':''
	,'usermsn':''
	,'website':''
	,'merchant':''};
var mask = new CMask();
var xWin = new CWindow();
xWin.Rect = new CRect(-1, 150, 350, 170);
xWin.exitWindow = function(){this.hideWindow(); mask.hide();};
xWin.WinForm.onmousedown = function(){return(false);};
xWin.WinFrame.style.background = 'gainsboro';
xWin.Workspace.style.background = 'gainsboro';
xWin.StatusBar.style.background = 'gainsboro';
xWin.Workspace.style.overflow = 'hidden';
xWin.Workspace.contentEditable = 'false';
xWin.Workspace.designMode = 'off';
xWin.Workspace.align = 'center';
xWin.MenusBar.Frame.innerHTML = '';
xWin.createWindow();
xWin.hideWindow();
mask.show();
if(xDom){
	var pros = xDom.getElementsByTagName('province');
	for(var i=0; i<pros.length; i++){
		prov[i] = pros[i].getAttribute('name');
		city[i] = pros[i].getAttribute('cities');
	}
}
site_install();


function provChange(index){
	var frm = $('frm_register');
    var citys = city[index].split(' ');
    frm.provcity.innerHTML = '';
    for(var i=0; i<citys.length; i++){
        frm.provcity.add(new Option(citys[i], citys[i]));
		if(frm.provcity.options[i].value==data.provcity)
			frm.provcity.options[i].selected = true;
    }
}

function data_register(){
	frm = $('frm_register');
	if(!frm) return false;
	data.username = frm.username.value;
	data.password = frm.password.value;
	data.repasswd = frm.repasswd.value;
	data.usermail = frm.usermail.value;
	data.realname = frm.realname.value;
	data.usersex = frm.usersex.value;
	data.province = frm.province.value;
	data.provcity = frm.provcity.value;
	data.address = frm.address.value;
	data.mobphone = frm.mobphone.value;
	data.telphone = frm.telphone.value;
	data.usermsn = frm.usermsn.value;
	data.website = frm.website.value;
	data.merchant = frm.merchant.value;
	return true;
}

function site_install(){
	data_register();
	xWin.Rect.width = 350;
	xWin.Rect.height = 170;
	xWin.TitleBar.Title.innerHTML = '网站初始化设置';
	xWin.MenusBar.Frame.innerHTML = '';
	xWin.MenusBar.appendMenu('[下一步]', function(){site_register();});
	xWin.MenusBar.appendMenu('[退 出]', function(){xWin.exitWindow();});
	var html = '';
	html += '<form id="frm_install">\r\n';
	html += '\t<br>后台目录：<input type="text" name="diradm" value="'+ data.diradm +'">&nbsp;<font color="red">（默认请留空）</font>\r\n';
	html += '\t<br>数据库名：<input type="text" name="dbname" value="'+ data.dbname +'">&nbsp;<font color="red">（默认请留空）</font>\r\n';
	html += '\t<br><br><input type="reset" value="重 置">&nbsp;&nbsp;<input type="button" onclick="site_register()" value="下一步">\r\n';
	html += '</form>\r\n';
	xWin.Workspace.innerHTML = html;
	xWin.resizeWindow();
	xWin.showWindow();
}

function site_register(){
	var frm = $('frm_install');
	data.diradm = frm.diradm.value;
	data.dbname = frm.dbname.value;
	xWin.Rect.width = 400;
	xWin.Rect.height = 420;
	xWin.TitleBar.Title.innerHTML = '售后服务注册';
	xWin.MenusBar.Frame.innerHTML = '';
	xWin.MenusBar.appendMenu('[上一步]', function(){site_install();});
	xWin.MenusBar.appendMenu('[完 成]', function(){site_datsend();});
	xWin.MenusBar.appendMenu('[退 出]', function(){xWin.exitWindow();});
	var html = '';
	html += '<form id="frm_register" style="padding-left:30px;text-align:left">\r\n';
	html += '\t<font color="red">注册以后可以进行在线升级，下载模板，以及其他增值服务等</font>\r\n';
	html += '\t<br>用户名称：<input type="text" name="username" value="'+ data.username +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>用户密码：<input type="password" name="password" value="'+ data.password +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>确认密码：<input type="password" name="repasswd" value="'+ data.repasswd +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>&nbsp;&nbsp;E-Mail：<input type="text" name="usermail" value="'+ data.usermail +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>真实姓名：<input type="text" name="realname" value="'+ data.realname +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>&nbsp;&nbsp;性&nbsp;&nbsp;别：<select name="usersex">\r\n';
	html += '\t\t<option value="男">男</option><option value="女" '+(data.usersex=='女'?'selected':'')+'>女</option>\r\n';
	html += '\t</select>&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>省市地区：<select name="province" onchange="provChange(this.selectedIndex)">\r\n';
    html += '\t\t</select>&nbsp;<select name="provcity"></select>  &nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>通信地址：<input type="text" name="address" size="30" value="'+ data.address +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>&nbsp;&nbsp;手&nbsp;&nbsp;机：<input type="text" name="mobphone" value="'+ data.mobphone +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>联系电话：<input type="text" name="telphone" value="'+ data.telphone +'">\r\n';
	html += '\t<br>聊天工具：<input type="text" name="usermsn" value="'+ data.usermsn +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>网站地址：<input type="text" name="website" value="'+ data.website +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br>商家编号：<input type="text" name="merchant" value="'+ data.merchant +'">&nbsp;<font color="red">*</font>\r\n';
	html += '\t<br><br><input type="button" value="上一步" onclick="site_install();" style="margin-left:70px;">';
	html += '&nbsp;&nbsp;<input type="reset" value="重 置">&nbsp;&nbsp;<input type="button" onclick="site_datsend()" value="完 成">\r\n';
	html += '</form>\r\n';
	xWin.Workspace.innerHTML = html;
	xWin.resizeWindow();
	xWin.showWindow();
	frm = $('frm_register');
    for(var i=0; i<prov.length; i++){
        frm.province.add(new Option(prov[i], prov[i]));
		if(frm.province.options[i].value==data.province){
			frm.province.options[i].selected = true;
				provChange(i);
		}
	}
}

function site_datsend(){
	data_register();
	if(data.username==''){
		alert('用户名称不能为空！');
	}else if(checkuser(data.username)){
		alert('该用户名已被注册！');
	}else if(data.password==''){
		alert('用户密码不能为空！');
	}else if(data.repasswd!=data.password){
		alert('用户确认密码错误！');
	}else if(data.usermail==''){
		alert('E-mail不能为空！');
	}else if(data.realname==''){
		alert('真实姓名不能为空！');
	}else if(data.usersex==''){
		alert('用户性别不能为空！');
	}else if(data.provcity==''){
		alert('省市地区不能为空！');
	}else if(data.address==''){
		alert('通信地址不能为空！');
	}else if(data.mobphone==''){
		alert('以后手机不能为空！');
	}else if(data.usermsn==''){
		alert('聊天工具不能为空！');
	}else if(data.website==''){
		alert('网站地址不能为空！');
	}else if(data.merchant==''){
		alert('商家编号不能为空！');
	}else{
		var url = 'install.asp?action=register';
		var pars = '';
		for(key in data)
			pars += key+ '='+ escape(data[key]) + '&';
		pars += 'random='+Math.random();
		var txt = xhttp.request(url, pars, 'post', false);
		//alert(unescape(txt));
		if(txt=='true'){
			alert('注册成功！');
			xWin.exitWindow();
		}else{
			alert('注册失败！');
		}
	}
	return false;
}

function checkuser(uname){
	var url = 'install.asp';
	var pars = 'action=checkuser&username='+uname+'&random='+Math.random();
	var txt = xhttp.request(url, pars, 'get', false);
	txt = unescape(txt);
	if(txt.indexOf('恭喜您')>0)
		return false;
	else  return true;
}