// JavaScript Document
var moduleList=Array();
function makeRequest(strUrl, strMethod, strPars, onCmpleteFuncs){
	strPars = strPars + '&ran=' + Math.random();
	if(typeof(strUrl)!='string') return;
	if(onCmpleteFuncs == null) return;
	
	if(typeof(onCmpleteFuncs)!='string')	
		var myajax = new Ajax.Request(strUrl, {method: strMethod, parameters: strPars, onComplete: onCmpleteFuncs});
	else
		var myajax = new Ajax.Updater({success:onCmpleteFuncs, failure:onCmpleteFuncs}, strUrl, {method:strMethod, parameters:strPars});
}
//嵌入HTML代码
function ajax_html(url,div){
	var pars = '';
	makeRequest(url, 'get', pars, div);	
}
//获取广告代码
function getAdsHtml(id,path){
	var url = path+'ajax.php';
	var pars = 'request=getAdsHtml&id='+id+"&path="+path;
	//makeRequest(url, 'post', pars, 'testDiv');
	makeRequest(url, 'get', pars, doGetAdsHtml);		
}
function doGetAdsHtml(obj){
	//alert(obj.responseText);
	document.write(obj.responseText);
}
//选择行业对话框
function selectModule(table,textField,valueField,path,type){
	text=Array();
	value=Array();
	text.length=0;
	value.length=0;
	dialog =_window.Open("[url]"+path+"selectModule.php?table="+table+"&valueField="+valueField+"&textField="+textField+"&type="+type, "选择分类","isModal=yes,button=OK,width=778,height=450,left=170,top=60");
	dialog.OnOK=function(){
		for(var i=0;i<moduleList.length;i++){
			value.push(moduleList[i]['value']);
			text.push(moduleList[i]['keyword']);
		}
		//value=value.substr(1,1) ;
		$(textField).value=text.join("/");
		$(valueField).value=value.join(",");
		//alert(value);
		
		moduleList.length=0;
		dialog.Close();
		//alert(value);
	}
}
//用户选择行业
function clickModule(value,keyword,type){
	sign=true;
	var arr=Array();
	arr['keyword']=keyword;
	arr['value']=value;
	if(type=='checkbox'){
		for(var i=0;i<moduleList.length;i++) {
			if(moduleList[i]['value']==value){
				 moduleList.splice(i,1);
				 sign=false;
				 break;
			}
		}
		if(sign){
			moduleList.push(arr);
		}		
	}else{
		moduleList=Array();
		moduleList.push(arr);
	}

	showSelectedModule();
}
function restoreModuleList(valueField,textField){
	moduleList.length=0;
	var record=Array();
	rvalue=$(valueField).value.split(",");
	rtext=$(textField).value.split("/");
	for(var i=0;i<rvalue.length;i++) {
		if(rvalue[i]!=''){
			var record=Array();
			record['keyword']=rtext[i];
			record['value']=rvalue[i];
			moduleList.push(record);
		}
	}
/*	for(var i=0;i<moduleList.length;i++) {
		alert(moduleList[i]['value']+moduleList[i]['keyword'])	;
	}*/
	
}
//显示已选栏目
function showSelectedModule(){
	str='';
	for(var i=0;i<moduleList.length;i++) {
		str+="<li><input name=\"selectModule[]\" type=\"checkbox\" value=\""+moduleList[i]['value']+"\" checked  onclick=\"top.cancelSelectedModule(this.value)\"/> "+moduleList[i]['keyword']+"</li>\n";
	}	
	var openIframe = eval("_F"+dialog.id);
	openIframe.selectedModule.innerHTML=str;
	form = openIframe.moduleform;
	for (var i=0;i<form.elements.length;i++){
		if(form[i].name=='auto_code'&&checkModuleList(form[i].value)){	
			form[i].checked=true;
		}else{
			if(form[i].name=='auto_code')form[i].checked=false;
		}
	}
	//$('selectedModule').innerHTML=str;
}
//取消已经选择的栏目
function cancelSelectedModule(value){
	for(var i=0;i<moduleList.length;i++) {
		if(moduleList[i]['value']==value){
			 moduleList.splice(i,1);
			 sign=false;
			 break;
		}
	}	
	showSelectedModule();
}
//检测发送会员列表
function checkModuleList(value){
	sign=false;
	for(var i=0;i<moduleList.length;i++) {
		if(moduleList[i]['value']==value){
			 sign=true;
			 break;
		}
	}
	return sign;
}

function person_login(action){
	
	test=document.getElementById("login_form"); 
	if(action==null)
		test.action="do_login.php";
	else test.action=action;
	
	if(document.getElementById("content_user").value==''){
		alert('请输入用户名');
		document.getElementById("content_user").focus();
	}
	else if(document.getElementById("content_pass").value==''){
		alert('请输入密码');
		document.getElementById("content_pass").focus();

	}else if(document.getElementById("number").value==''){
		alert('请输入验证码');
		document.getElementById("number").focus();
	}else{

	
	//alert("个人会员登录，有错误");
		
		test.submit();
	}
	
}
function company_login(action){
	
	test=document.getElementById("login_form"); 
	if(action==null)
		test.action="do_companylogin.php";
	else test.action=action;
	
	if(document.getElementById("content_user").value==''){
		alert('请输入用户名');
		document.getElementById("content_user").focus();
	}
	else if(document.getElementById("content_pass").value==''){
		alert('请输入密码');
		document.getElementById("content_pass").focus();
	}else if(document.getElementById("number").value==''){
		alert('请输入验证码');
		document.getElementById("number").focus();
	}else{
	//alert("企业会员登录，有错误");
	//$('login_form').submit();
	
	test.submit();
	}
}
/*
function selectModule2(table,textField,valueField,path){
	text=Array();
	value=Array();
	text.length=0;
	value.length=0;
	alert("[url]"+path+"selectModule.php?table="+table+"&valueField="+valueField+"&textField="+textField);
	dialog =_window.Open("[url]"+path+"selectModule.php?table="+table+"&valueField="+valueField+"&textField="+textField, "选择分类","isModal=yes,button=OK,width=778,height=450,left=170,top=60");
	dialog.OnOK=function(){
		for(var i=0;i<moduleList.length;i++){
			value.push(moduleList[i]['value']);
			text.push(moduleList[i]['keyword']);
			//text+='/'+moduleList[i]['keyword'];
			//alert(moduleList[i]['keyword']);
		}
		//value=value.substr(1,1) ;
		$(textField).value=text.join("/");
		$(valueField).value=value.join(",");
		//alert(value);
		
		moduleList.length=0;
		dialog.Close();
		//alert(value);
	}
}*/

