var arrScriptTag = document.getElementsByTagName("script");
var PROTOTYPE_INCLUDED = false;
for ( var i=0; i<arrScriptTag.length; i++ ){
	var tag = arrScriptTag[i];
	if ( tag.getAttribute("src").indexOf("prototype.js")!=-1 ){
		PROTOTYPE_INCLUDED = true;
		break;
	}
}
//alert(PROTOTYPE_INCLUDED);
if ( !PROTOTYPE_INCLUDED ){
	var n = document.createElement("script");
	n.setAttribute("src","/js/prototype.js");
	n.setAttribute("type","text/javascript");
	document.getElementsByTagName("head")[0].appendChild(n);
}
/*
function checkCustomForm(){
	var problemObj;
	var problemMessage;
	var checkResult = true;
	alert("1");
	var str = document.getElementById("cbcdc_90").className; 
	alert(str);
//	var strs = document.getElementById("cbcdc_90").getAttribute("class"); 
//	alert(strs);
	$$('input[type="text"][class~="numeric"]').each(
		function(o){
			alert("2");
			if (!isNumeric(o.value)){
				alert("3");
				problemObj=o;checkResult=false;
				problemMessage="此处应该填写数字类型.";
			}
		}
	);
	$$('input[type="text"][class~="notnull"]').each(
		function(o){
			alert("4");
			if (!isNotNull(o.value)){
				alert("5");
				problemObj=o;
				checkResult=false;
				problemMessage="此处不能为空.";
			}
		}
	);
	if ( checkResult ){
	}else{
		alert(problemMessage);
		problemObj.focus();
		problemObj.select();
	}
	return checkResult;
}
*/

/**********update by pk 20100422 开始**********/
function checkCustomForm(oform){
	var formobj=document.getElementById(oform);  //得到表单对象 
    var iarray=document.getElementsByTagName("input");
    var arrayTextarea = document.getElementsByTagName("textarea");
    if(!checkElement(iarray)) {
    	return false;
    }
    if(!checkElement(arrayTextarea)) {
    	return false;
    }
    return true;
 }
 
function checkElement(iarray) {
    var checkResult = true;
	//var r = true;
	
	var problemObj;
	var problemMessage;
    for(var i=0;i<iarray.length;i++)   
    {   

        var check=iarray[i].getAttribute("name");
        if(check!=""){
        
        var strs = document.getElementById(check).getAttribute("className");
        switch(strs){   
            case "charcount":  
            {  
                  checkResult=CharCount_fun(iarray[i]);   
            break;
            }   
            case "notnull ":
            {   
                  checkResult=NullRange_fun(iarray[i]);
                  if(!checkResult){
                  		problemObj=iarray[i];
                  		problemMessage="此处不能为空.";
                  }   
            		break;
            }   
            case "numeric ":  
            {
             checkResult=NumRange_fun(iarray[i]);
                  if(!checkResult){
                  		problemObj=iarray[i];
                  		problemMessage="此处应该填写数字类型.";
                  }   
            		break; 
            }
            case "numeric notnull ":   
            { 
                  checkResult=Common_fun(iarray[i]); 
                  if(!checkResult){
                  		problemObj=iarray[i];
                  		problemMessage="此处应该填写非空数字类型.";
                  }
            	break;  
            }
            case "emailcheck":   
            {     
                  checkResult=EmailCheck_fun(iarray[i]); 
                  if(!checkResult){
                  		problemObj=iarray[i];
                  		problemMessage="请输入正确邮箱格式,如：XXXX@XX.COM 等邮箱帐号...";
                  }
            	break;  
            }
            case "telephonenumcheck":   
            {    
                 checkResult=TelephoneNumCheck_fun(iarray[i]); 
                  if(!checkResult){
                  		problemObj=iarray[i];
                  		problemMessage="请输入有效联系号码，如：027-8765**21或11位手机号等...";
                  }
            	break;  
            }
            default:   
            {
                  checkResult=true;
 
            break;
            }   
        }  
		if ( checkResult ){

		}else{
			alert(problemMessage);
			problemObj.focus();
			problemObj.select();
		}
		
		//r = r&&checkResult;

        }
        if(!checkResult){
        	return checkResult; 
        }          
    }
    
    return true;
 
}
/**********update by pk 20100422 结束**********/

function isNumeric(v){
	return !isNaN(v);
}
function isNotNull(v){
	var reg = /[\S]+/;
	return reg.test(v);
}

function NullRange_fun(o){
	if (!isNotNull(o.value)){
				return false;
	}else{
		return true;
	}
}
function NumRange_fun(o){
	if (!isNumeric(o.value)){
				return false;
	}else{
		return true;
	}
}
function Common_fun(o){
	if ((!isNumeric(o.value))||(!isNotNull(o.value))){
				return false;
	}else{
		return true;
	}
}

//edit by cheng 
function EmailCheck_fun(v){
 var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
  if(!reg.test(v.value)){
        return false;
    }else{
        return true;
    }
}

function TelephoneNumCheck_fun(v){
	var reg1 =/^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$$/;
	var phoneCheck1 = /^[0-9]{8}$/;
	var phoneCheck2 = /^(13[0-9]{9})$/;        
	var phoneCheck3 = /^(15[0-9]{9})$/;
	var phoneCheck4 = /^(18[0-9]{9})$/;
	var phoneCheck5 = /^([0-9]{4}-[0-9]{8})$/;
	var phoneCheck6 = /^([0-9]{3}-[0-9]{8})$/;
	var phoneCheck7 = /^([0-9]{4}-[0-9]{7})$/;
	var phoneCheck8 = /^[0-9]{7}$/;
	var Phone =v.value;
	if(!(reg1.test(Phone)||phoneCheck1.test(Phone)||phoneCheck2.test(Phone)||phoneCheck3.test(Phone)||phoneCheck4.test(Phone)||phoneCheck5.test(Phone)
			||phoneCheck6.test(Phone)||phoneCheck7.test(Phone)||phoneCheck8.test(Phone)) ){
		return false;
    }else{
        return true;
    }
}

function reloadcode(){
    var con =document.location.href;
    var contextPath= con.split("/")[3];
    //刷新验证码函数
    var verify = document.getElementById('safecode');
    verify.setAttribute('src', '/'+contextPath+'/getAuthorImage.reg?' + Math.random());
}

