// JavaScript Document
function $(id){	return document.getElementById(id);}
all_inputMsgs[0]='fax1;国家区号';
all_inputMsgs[1]='fax2;省市区号';
all_inputMsgs[2]='fax3;传真号';
all_inputMsgs[3]='fax4;分机号';

all_inputMsgs[4]='tel1;国家区号';
all_inputMsgs[5]='tel2;省市区号';
all_inputMsgs[6]='tel3;电话号';
all_inputMsgs[7]='tel4;分机号';

all_inputMsgs[8]='duserName;媒体用户名';

function dToClick(id){
	var i = 0;
	while($("l"+i)){
		$("l"+i).className="overview_title9";
		i++;
	}
		$("l"+id).className ="overview_title8";
}
function doLogout(){
	ajaxSend("index.php?module=media&act=doLogout","dWel","GET");
}

function doLogin(){
	if(!isNotEmpty($("dusername"))){
		alert("请填写用户名！");
		$("dusername").focus();
		return false;
	}

	if(!isNotEmpty($("dpassword"))){
		alert("请填写密码！");
		$("dpassword").focus();
		return false;
	}
	ajaxSend("index.php?module=media&act=doLogin&dusername="+$("dusername").value+"&dpassword="+$("dpassword").value,"dWel","GET");
}
function check_viewerlogin(f){
	if(!isNotEmpty($("lastName"))){
		alert("请填写您的姓！");
		$("lastName").focus();
		return false;
	}

	if(!isNotEmpty($("firstName"))){
		alert("请填写您的名！");
		$("firstName").focus();
		return false;
	}
	if(!isNotEmpty($("company"))){
		alert("请填写您的公司！");
		$("company").focus();
		return false;
	}
	if(!isNotEmpty($("appointment"))){
		alert("请填写您的职位！");
		$("appointment").focus();
		return false;
	}
	if(!isNotEmpty($("address"))){
		alert("请填写您的公司地址！");
		$("address").focus();
		return false;
	}
	if(!isNotEmpty($("province"))){
		alert("请填写所在省份！");
		$("province").focus();
		return false;
	}
	if(!checkZip($("zip").value)){
		alert("请输入邮政编码前4-6位");
		$("zip").focus();
		return false;
	}

	if(!check_f1('tel')){
		alert("请输入正确的国家区号！");
		$("tel1").focus();
		return false;
	}
	if(!check_f2('tel')){
		alert("请输入正确的区号！");
		$("tel2").focus();
		return false;
	}
	if(!check_f3('tel')){
		alert("请输入正确的电话号！");
		$("tel3").focus();
		return false;
	}
//	if(!check_f4('tel')){
//		alert("请输入正确的分机号！");
//		$("tel4").focus();
//		return false;
//	}
	
	if(!check_f1('fax')){
		alert("请输入正确的国家区号！");
		$("fax1").focus();
		return false;
	}
	if(!check_f2('fax')){
		alert("请输入正确的区号！");
		$("fax2").focus();
		return false;
	}
	if(!check_f3('fax')){
		alert("请输入正确的传真号！");
		$("fax3").focus();
		return false;
	}
//	if(!check_f4('fax')){
//		alert("请输入正确的分机号！");
//		$("fax4").focus();
//		return false;
//	}
	doinputMsg(all_inputMsgs);

	if(!isEmail($("email").value)){
		alert("请输入正确的E-Mail！");
		$("email").focus();
		return false;
	}
	var cMin = 1;
	if(getCheckBoxNum("quality[]") < cMin || getCheckBoxNum("goal[]") < cMin || getCheckBoxNum("interst[]") < cMin || getCheckBoxNum("sum[]") < cMin || getCheckBoxNum("know[]") < cMin){
		alert("您至少需要选择"+cMin+"个选项！");
		return false;
	}
	
	if(!check_oT("quality") || !check_oT("interst")){
		alert("请填写具体理由！");
		return false;
	}
	$("f").submit();
}

function checkOButton(id){
	if($("oB"+id).checked){
		$("oT"+id).readOnly = false;	
	}else{
		$("oT"+id).value = "";
		$("oT"+id).readOnly = true;	
	}
}

function check_recive(){
	if($("recive").checked){
		$("recive").value = "1";
	}else{
		$("recive").value = "0";
	}
}


function check_mediaLogin(){
	var sex = -1;
	var f = document.getElementById("f");
	var i=0;
    for (i=0; i<f.sex.length; i++){
        if (f.sex[i].checked) {
			sex = f.sex[i].value;
		}
	}
    if (sex < 0){
		alert("请选择您的性别！");
		return false;
    }
	if(!isNotEmpty($("lastName"))){
		alert("请填写您的姓！");
		$("lastName").focus();
		return false;
	}

	if(!isNotEmpty($("firstName"))){
		alert("请填写您的名！");
		$("firstName").focus();
		return false;
	}
	if(!isNotEmpty($("username"))){
		alert("请填写用户名！");
		$("username").focus();
		return false;
	}
	if(!isNotEmpty($("password")) || $("password").value != $("password2").value){
		alert("密码为空或两次输入的密码不一致！");
		return false;
	}
	if(!isNotEmpty($("appointment"))){
		alert("请填写您的职位！");
		$("appointment").focus();
		return false;
	}
	if(!isMobile($("mobile").value)){
		alert("请您输入正确的手机号码！");
		$("mobile").focus();
		return false;
	}
	if(!isNotEmpty($("address"))){
		alert("请输入公司地址！");
		$("address").focus();
		return false;
	}
//	if(!isUrl($("website").value)){
//		alert("请您输入正确的网址！");
//		$("website").focus();
//		return false;
//	}
//	if(!checkZip($("zip").value)){
//		alert("请输入邮政编码前4-6位");
//		$("zip").focus();
//		return false;
//	}
	if(!isEmail($("email").value)){
		alert("请输入正确的E-Mail！");
		$("email").focus();
		return false;
	}
	
	
	if(!check_f1('tel')){
		alert("请输入正确的国家区号！");
		$("tel1").focus();
		return false;
	}
	if(!check_f2('tel')){
		alert("请输入正确的区号！");
		$("tel2").focus();
		return false;
	}
	if(!check_f3('tel')){
		alert("请输入正确的电话号！");
		$("tel3").focus();
		return false;
	}
//	if(!check_f4('tel')){
//		alert("请输入正确的分机号！");
//		$("tel4").focus();
//		return false;
//	}
//	
	if(!check_f1('fax')){
		alert("请输入正确的国家区号！");
		$("fax1").focus();
		return false;
	}
	if(!check_f2('fax')){
		alert("请输入正确的区号！");
		$("fax2").focus();
		return false;
	}
	if(!check_f3('fax')){
		alert("请输入正确的传真号！");
		$("fax3").focus();
		return false;
	}
//	if(!check_f4('fax')){
//		alert("请输入正确的分机号！");
//		$("fax4").focus();
//		return false;
//	}
	doinputMsg(all_inputMsgs);
	
	if(!isNotEmpty($("mediaName"))){
		alert("请输入媒体名称！");
		$("mediaName").focus();
		return false;
	}
	if(!isNotEmpty($("mediaType"))){
		alert("请输入媒体名称！");
		$("mediaType").focus();
		return false;
	}
	if(!isNotEmpty($("distribution"))){
		alert("请输入发行方式！");
		$("distribution").focus();
		return false;
	}
	if(!isNotEmpty($("distributionRange"))){
		alert("请输入发行范围！");
		$("distributionRange").focus();
		return false;
	}
	
//	var help = -1;
//	for (i=0; i<f.help.length; i++){
//        if (f.help[i].checked) {
//			help = f.help[i].value;
//		}
//	}
//    if (help < 0){
//		alert("请选择您是否需要签证帮助！");
//		return false;
//    }
	if(!isNotEmpty($("authorCode"))){
		alert("请输入验证码！");
		$("authorCode").focus();
		return false;
	}
	f.submit();
}

function check_lastName(){
//	if(!isNotEmpty($("lastName"))){
//		$("lastName"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入您的姓！";
//	}else{
//		$("lastName"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}

function check_firstName(){
//	if(!isNotEmpty($("firstName"))){
//		$("firstName"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入您的名！";
//	}else{
//		$("firstName"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}

function check_username(){
	if($("username").value != ""){
	ajaxSend("index.php?module=media&act2=check_username&username="+$("username").value,"username_notice","GET");
	}
}

function check_password(){
	if($("password").value != "")
		$("password"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
}
function check_password2(){
	if($("password").value != "" && $("password2").value != ""){
		if($("password").value != $("password2").value){
			$("password2"+"_notice").innerHTML = "<img src=\"images/error.gif\">";
		}else{
			$("password2"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
		}
	 }
}

function check_appointment(){
//	if(!isNotEmpty($("appointment"))){
//		$("appointment"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入职位！";
//	}else{
//		$("appointment"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}


function check_mobile(){
//	if(!isMobile($("mobile").value)){
//		$("mobile"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入正确的手机号码！";
//	}else{
//		$("mobile"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}

function check_address(){
//	if(!isNotEmpty($("address"))){
//		$("address"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入公司地址！";
//	}else{
//		$("address"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_website(){
//	if(!isUrl($("website").value)){
//		$("website"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入正确的网址！";
//	}else{
//		$("website"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_zip(){
//	if(!checkZip($("zip").value)){
//		$("zip"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入邮政编码前4-6位";
//	}else{
//		$("zip"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_email(){
//	if(!isEmail($("email").value)){
//		$("email"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入正确的E-Mail！";
//	}else{
//		$("email"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}

function check_num(id){
//	if(!check_f1(id) || !check_f2(id) || !check_f3(id))
//			$(id+"_notice").innerHTML = "<img src=\"images/error.gif\">";
//		else
//			$(id+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
}

function check_f1(id){
	return $(id+"1").value.match(/^[0-9]{2,3}$/) ? true : false;
}

function check_f2(id){
	return $(id+"2").value.match(/^[0-9]{2,4}$/) ? true : false;
}
function check_f3(id){
	return $(id+"3").value.match(/^[0-9]+$/) ? true : false;
}
function check_f4(id){
	return $(id+"4").value.match(/^[0-9]+$/) ? true : false;
}


function check_mediaName(){
//	if(!isNotEmpty($("mediaName"))){
//		$("mediaName"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入媒体名称！";
//	}else{
//		$("mediaName"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_mediaType(){
//	if(!isNotEmpty($("mediaType"))){
//		$("mediaType"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入媒体类别！";
//	}else{
//		$("mediaType"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_distribution(){
//	if(!isNotEmpty($("distribution"))){
//		$("distribution"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入发行方式！";
//	}else{
//		$("distribution"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_distributionRange(){
//	if(!isNotEmpty($("distributionRange"))){
//		$("distributionRange"+"_notice").innerHTML = "<img src=\"images/error.gif\"> 请输入发行范围！";
//	}else{
//		$("distributionRange"+"_notice").innerHTML = "<img src=\"images/valid.gif\">";
//	}
}
function check_authcode(){
	ajaxSend("index.php?module=media&act2=check_authcode&acode="+$("authorCode").value,"authcode_notice","GET");
}


function getCheckBoxNum(name){
	var c = document.getElementsByName(name);
	var n = 0;
	for(i=0;i<c.length;i++){
		if(c[i].checked)
			n++;
	}
	return n;
}

function checkZip(s){
	var r = /^[0-9]{4,6}$/;
	return s.match(r) ? true : false;
}
	
function isMobile(s){
	var mreg = /^(((13[0-9]{1})|159|(15[0-9]{1}))+\d{8})$/;
	return s.match(mreg) ? true : false;
}

function isEmail(s){
	var r = /^(.+)@(.+)$/;
	return s.match(r) ? true : false;
}

function isUrl(s){
	var regExp = /(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i;
	return s.match(regExp) ? true : false;
}

function check_oT(id){
	if($("oB"+id).checked && $("oT"+id).value == ""){
		return false;
	}else{
		return true;
	}
}


function doinputMsg(all_inputMsgs) {
	for(i=0;i<all_inputMsgs.length;i++) {
		obj=all_inputMsgs[i].split(';');
		objid = obj[0];
		if($id(objid) && $id(objid).value==findvalue(objid,all_inputMsgs)){		
			$id(objid).value="";
		}
	}

}
