Array.prototype.remove = function(dx){
    if(isNaN(dx) || dx>this.length)return false;
    for(var i=0,n=0; i<this.length; i++){
        if(i != dx)
		   this[n++]=this[i];
	}
    this.length -= 1;
}

Array.prototype.removeItem = function(item){
	for (var i=0; i<this.length; i++){
		if (this[i] == item) {
			this.remove(i);
			break;
        }
	}
}

var HashTable = Class.create();
HashTable.prototype={
	initialize: function(){
		this.size = 0;
		this.obj = new Object();
	},
	put: function(key,val){
		this.checknull(key,val);
		if (this.get(key) == null){
			this.obj[key] = val;
			this.size ++;
		}else{
			this.obj[key] = val;
		}
	},
	get: function(key){
		this.checknull(key);
		return this.obj[key];
	},
	hasKey: function(key){
		for(var i=0; i<this.obj.length; i++){
			if(this.obj[i] == key)
				return true;
		}
		return false;
	},
	clear: function(){
		this.obj = null;
		this.obj = new Array();
		this.size = 0; 		
	},
	checknull: function() {
		var ar = $A(arguments);
		ar.each(function(val){
			try{
				if(val == null)
					throw Error("ֵΪ!");
			}catch(e){
				alert("Sorry, an error occurred: " + e.message);
			}
		});
    }
}
function SelectAllOrNoAll(datagridId){
	var dg = $(datagridId);
	for (var i=0; i<dg.rows.length; i++){
		for(var j=0; j<dg.rows[i].cells.length; j++){
			var c = dg.rows[i].cells[j].firstChild;
			if(c.nodeName != "#text" && c.tagName.toLowerCase() == "input" && c.type.toLowerCase() == "checkbox"){
				if(!c.disabled){
					c.click();
					//c.checked = !c.checked; 
				}
			}
			
		}
	}
}

function checkSelected(datagridId,hidId){
	var dg = $(datagridId); 
	var hid = $(hidId);
	var arr = new Array();
	for (var i=0; i<dg.rows.length; i++){
		for(var j=0; j<dg.rows[i].cells.length; j++){
			var c = dg.rows[i].cells[j].firstChild;
			if(c.nodeName != "#text" && c.tagName.toLowerCase() == "input" && c.type.toLowerCase() == "checkbox"){
				if(c.checked)
					arr.push(i);
			}
		}
	}		
	hid.value = arr.join("&");
}

function getValueById(id){
	return $F(id);
}

function setDatagridSelect(dg,select){
	var ss = select.split(" ");
	for (var i=0; i<dg.rows.length; i++){
		for(var j=0; j<dg.rows[i].cells.length; j++){
			var c = dg.rows[i].cells[j].firstChild;
			if(c.nodeName != "#text" && c.tagName.toLowerCase() == "input" && (c.type.toLowerCase() == "checkbox" || c.type.toLowerCase() == "radio")){
				ss.each(function(s){
					if(s == c.value){
						c.checked = true;
						return;
					}	
				});
			}
			
		}
	}
}

function parentselectHandler(){
	if(location.search.indexOf("parentselect") != -1)
	{
		var c = event.srcElement;
		var dg = event.srcElement;
		while(dg.tagName.toLowerCase() != "table")
			dg = dg.parentNode;
		var hid = $("hidDatagridSelect_" + dg.id.split("_")[1]);
		var hidbak = $("hidDatagridSelect_" + dg.id.split("_")[1] + "bak");
		var hiddel = $("hidDatagridSelect_" + dg.id.split("_")[1] + "del");
		var select = hid.value.split(" ");
		if(c.nodeName != "#text" && c.tagName.toLowerCase() == "input" && (c.type.toLowerCase() == "checkbox" || c.type.toLowerCase() == "radio")){
			if(c.type.toLowerCase() == "radio"){
				var rows = $A(dg.rows);
				rows.each(function(row){
					var cells = $A(row.cells);
					cells.each(function(cell){
						var c1 = cell.firstChild;
						if(c1.nodeName != "#text" && c1.tagName.toLowerCase() == "input" && c1.type.toLowerCase() == "radio"){
							if(c1.value != c.value){
								c1.checked = false;
								if(select.indexOf(c1.value) != -1)select.removeItem(c1.value);
							}
								
						}
					});
				});
			}
			if(select.indexOf(c.value) != -1 && !c.checked)
				select.removeItem(c.value);
			if(select.indexOf(c.value) == -1 && c.checked)
				select.push(c.value);
		}
		hid.value = select.join(" ");		//¹ѡId
		var selectbak = hidbak.value.split(" ");
		var selectdel = new Array();
		selectbak.each(function(s){
			if(select.indexOf(s) == -1)
				selectdel.push(s);
		});
		hiddel.value = selectdel.join(" ");
	}
}

function InputVerify(iInput)
{
	if((iInput>47)&&(iInput<58)||(iInput==8)||(iInput==45))
	{
		return true;
	}
	else
		return false;
}
function txt_onkeypressed()
{
	if(!InputVerify(event.keyCode))
	{
		event.keyCode = 0;
	}
}

function checkPageIndex(txtpageSize,txtpageIndex,hidtotalpage,hidtotaldatanum)
{
	var pageindex,pagesize,totalpage,totaldatanum;
	if(txtpageIndex.value == "")
	{
		alert("The jump page is empty");
		return false;
	}
	pageindex = parseInt(txtpageIndex.value);
	totalpage = parseInt(hidtotalpage.value);
	totaldatanum = parseInt(hidtotaldatanum.value);
	if(totaldatanum == 0)
		return;
	if(pageindex < 1 || pageindex > totalpage)
	{
		alert("The range must be in 1-" + totalpage);
		return false;
	}
	if(txtpageSize.value == "")
	{
		alert("The per page is empty");
		return false;
	}
	pagesize = parseInt(txtpageSize.value);
	while(pagesize * (pageindex - 1) >= totaldatanum)
	{
		pageindex --;
	}
	txtpageIndex.value = pageindex;
}

function checkPageIndex1(max,txtjump)
{
	if(txtjump.value == "")
	{
		alert("The jump page is empty");
		return false;
	}
	if(txtjump.value > max)
	{
		alert("The range must be in 1-" + max);
		return false
	}
	return true;
}

function getvoteitem(votetable)
{
	var select = new Array();
	for(var i=1; i<votetable.rows.length - 1; i++)
	{
		var e = votetable.rows[i].cells[0].firstChild;
		if(e.tagName.toLowerCase() == "input" && e.type.toLowerCase() == "radio")
		{
			if(e.checked)
			{
				return e.value;
			}
		}
		else if(e.tagName.toLowerCase() == "input" && e.type.toLowerCase() == "checkbox")
		{
			if(e.checked)
				select.push(e.value);		
		}
	}
	return select.join(",");
}

function ansycvote(voteitemids,servicepath)
{
	if(voteitemids == "")return;
	var h1 = {
		voteitemids : voteitemids
		};
		var h = $H(h1);	
		var pars = h.toQueryString();
		var url = servicepath;
		var myAjax = new Ajax.Request(
			url, 
		{
			method: 'get', 
			parameters: pars
		});
}
