/*
	验证表单 	Ver 0.1Beta
	Create by lam @080415
*/
function $(id){return document.getElementById(id);}
var arr_pass = new Array();
var form_onload = function(){
	var object = new Array();
	var object_tagName = ["input","textarea"];
	
	var num = 0;

	this.onload = function(form_id){
		for(var i=0;i<object_tagName.length;i++){
			var object_tag = $(form_id).getElementsByTagName(object_tagName[i]);		
			for(var j=0;j<object_tag.length;j++){
			if(object_tag[j].getAttribute("rel")=="chk"){
				object.push(object_tag[j]);				
					arr_pass.push(false);						
					object_tag[j].setAttribute("rel_id",num);
					num++;
				}
			}
		}
		for(var i=0;i<object.length;i++){
			object[i].setAttribute("chk_pass",false);
			object[i].onblur= function(){			
				this.removeAttribute("has_overPress");
				if(this.getAttribute("request_id")!=null){				
					var id = this.getAttribute("request_id");
					if(this.value == "") {
						$(id).style.display ="inline";
						no(this);
					}
					else {
						$(id).style.display ="none";
						yes(this);
					}
					
					var chk_fun = new Array();
					chk_fun = eval(this.getAttribute("chk_fun"));
					if(chk_fun != null){					
						for(var j=0;j<chk_fun.length;j++){
							if(eval(chk_fun[j][0]+"(this)")) {
								$(chk_fun[j][1]).style.display ="none";
								yes(this);
							}
							else {
								$(chk_fun[j][1]).style.display ="inline";
								no(this);
							}
						}
					}
				}
			}
			object[i].onfocus = function(){
				this.removeAttribute("has_overPress");
				var overClassName = this.getAttribute("overClassName");
				var outClassName = this.getAttribute("outClassName");
				if(overClassName != null){				
					for(var i=0;i<object.length;i++){
						object[i].className = outClassName;
					}
					this.className = overClassName;
					this.setAttribute("has_overPress",true);
				}
			}
			object[i].onmouseover = function(){
				var overClassName = this.getAttribute("overClassName");
				if(overClassName != null) this.className = overClassName;
			}
			object[i].onmouseout = function(){
				if( !this.getAttribute("has_overPress") ){
					var outClassName = this.getAttribute("outClassName");
					if(outClassName != null) this.className = outClassName;
				}
			}		
		}
	}
	
	
	// email
	function isEmail(obj){
		var strEmail = obj.value;
		if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
			yes(obj);
			return true;
		}
		else {
			no(obj);
			return false;
		}
	}
	function confrim(obj){
		if(obj.value == $("ursname").value&& obj.value !="") {
			yes(obj);
			return true;
		}
		else {
			no(obj);
			return false;
		}
	}
	function isIDCard(obj){
		var id = obj.value;
		if (id.search(/^(([\d]{15})|([\d]{18}))$/) !=-1){
			yes(obj);
			return true;
		}
		else {
			no(obj);
			return false;
		}
	}
	function yes(obj){arr_pass[obj.getAttribute("rel_id")]=true;}
	function no(obj){arr_pass[obj.getAttribute("rel_id")]=false;}
	this.chk_pass = function(){
		var result = true;	
		for(var i=0;i<arr_pass.length;i++){
			object[i].onfocus();
			object[i].onblur();			
			if(arr_pass[i]==false) result = false;
		}
		return result;
	}
}

var chk = new form_onload();
var newWindow = null;
function windowOpen(loadpos)
{		
	if(chk.chk_pass()){
		if (loadpos != '')
		{
			newWindow_ = window.open(loadpos,"votesystem","toolbar,resizable,scrollbars,dependent,width=400,height=280");
			newWindow.focus();
		}
		else 
		{
			newWindow = window.open(loadpos,"votesystem","toolbar,resizable,scrollbars,dependent,width=400,height=280");
			newWindow.focus();
			document.vote_form.submit();
		}
		document.vote_form.reset();
	}
	else alert("提交失败，请正确填写！");
}