// JavaScript Document
if(window.HTMLElement && navigator.userAgent.toLowerCase().indexOf("opera")==-1){
  HTMLElement.prototype.contains=function(e){do if(e==this)return true;while(e=e.parentNode);return false;};
  HTMLElement.prototype.__defineGetter__("outerHTML",function()
  {
    var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
    if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
    if(!this.canHaveChildren) return str+" />";
    return str+">"+this.innerHTML+"</"+this.tagName+">";
  });
  HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
  {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    r = r.createContextualFragment(s);
    this.parentNode.replaceChild(r, this);
    return s;
  });
  HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
  {
    switch(this.tagName.toLowerCase())
    {
      case "area": case "base":  case "basefont":
      case "col":  case "frame": case "hr":
      case "img":  case "br":    case "input":
      case "link": case "meta":  case "isindex":
      case "param":return false;
    } return true;
  });
  HTMLElement.prototype.__defineGetter__("currentStyle", function()
  {
    return this.ownerDocument.defaultView.getComputedStyle(this,null);
  });
  HTMLElement.prototype.__defineGetter__("children",function()
  {
    for(var a=[],j=0,n,i=0; i<this.childNodes.length; i++){
    n=this.childNodes[i];if(n.nodeType==1){a[j++]=n;if(n.name){
    if(!a[n.name])a[n.name]=[]; a[n.name][a[n.name].length]=n;}
    if(n.id) a[n.id]=n;}}return a;
  });
  HTMLElement.prototype.insertAdjacentHTML=function(where, html)
  {
    var e=this.ownerDocument.createRange();
    e.setStartBefore(this);
    e=e.createContextualFragment(html);
    switch (where)
    {
      case 'beforeBegin': this.parentNode.insertBefore(e, this);break;
      case 'afterBegin': this.insertBefore(e, this.firstChild); break;
      case 'beforeEnd': this.appendChild(e); break;
      case 'afterEnd':
        if(!this.nextSibling) this.parentNode.appendChild(e);
        else this.parentNode.insertBefore(e, this.nextSibling); break;
    }
  };
        
    HTMLElement.prototype.__defineGetter__("innerText", function (){
            var anyString = "";
            var childS = this.childNodes;
            for(var i=0; i<childS.length; i++)
            {
                if(childS[i].nodeType==1)
                    anyString += childS[i].tagName=="BR" ? '\r\n' : childS[i].innerText;
                else if(childS[i].nodeType==3)
                    anyString += childS[i].nodeValue.trim();
            }
            return anyString;
        }
    ); 

 }
 
 if(!window.attachEvent && window.addEventListener)
{
  window.attachEvent = HTMLElement.prototype.attachEvent=
  document.attachEvent = function(en, func, cancelBubble)
  {
    var cb = cancelBubble ? true : false;
    this.addEventListener(en.toLowerCase().substr(2), func, cb);
  };
  window.detachEvent = HTMLElement.prototype.detachEvent=
  document.detachEvent = function(en, func, cancelBubble)
  {
    var cb = cancelBubble ? true : false;
    this.removeEventListener(en.toLowerCase().substr(2), func, cb);
  };
}




var openwin=function(){
	var me=this;
	me.para={win:window,width:300,height:300,reobj:"",type:"value",title:"Open Window Test"};
	this.set=function(){
		var property,Arg=arguments[0];
		if(typeof(Arg)=="object"){
			for (property in Arg) {
				me.para[property] = Arg[property];
			}
		}
		else{
			return;
		}
	};
	this.open=function(url){
		url=(url.indexOf("?")!=-1)?url+"&":url+"?";
		var aw=parseInt((screen.availWidth/2)-(me.para.width/2));
		var ah=parseInt((screen.availHeight/2)-(me.para.height/2));
		if (document.all){
			var retValues=window.showModalDialog(url+"title="+me.para.title,me.para.win, "dialogWidth:"+me.para.width+"px; dialogHeight:"+me.para.height+"px; dialogLeft:"+aw+"px; dialogTop:"+ah+"px; status:no; directories:no; menubar:no; scrollbars:no; Resizable:no; location:no;toolbar:no;");
			if (me.para.type=="value"){
				document.getElementById(me.para.reobj).value=retValues;
			}
			else{
				if (me.para.type=="html" || me.para.type=="text"){
					document.getElementById(me.para.reobj).innerHTML=retValues;
				}
				else{
					try{
						eval(me.para.reobj+"('"+retValues+"')");
					}
					catch(e){
						alert(e.description);
					}
				}
			}
			retValues=null;
			//IE End
		}
		else{
			window.open(url+"return="+me.para.reobj+"&type="+me.para.type+"&title="+me.para.title, me.para.win, "top="+aw+",left="+ah+",scrollbars=no,dialog=yes,modal=yes,width="+me.para.width+",height="+me.para.height+",resizable=no,location=no,menubar=no,toolbar=no,status=no");
		}
		aw=null;
		ah=null;
	};
};



function MinPhotoSize(actual, maxvalue) {
	return Math.min(actual, maxvalue) + "px";
}

function findobj(n, d) {
	var p, i, x;
	if(!d) d = document;
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(x != d[n] && d.all) x = d.all[n];
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findobj(n, d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	return x;
}


function expandoptions(id) {
	var a = document.getElementById(id);
	if(a.style.display=='')
	{
		a.style.display='none';
	}
	else
	{
		a.style.display='';
	}
}

function cloneObj(oClone, oParent, count) {
	if(oParent.childNodes.length < count) {
		var newNode = oClone.cloneNode(true);
		oParent.appendChild(newNode);
		
		return newNode;
	} 
	return false;	
}

function delObj(oParent, count) { 
	if(oParent.childNodes.length > count) {
		oParent.removeChild(oParent.lastChild);
		return true;
	}
	return false;
}

function cloneObj_1(oClone, oParent, i, count, msgtext) {
	var tempcount = 1;
	for(k=0;k<oParent['childNodes'].length;k++){
		if (oParent['childNodes'][k].tagName){
			if (oParent['childNodes'][k].id == oClone.id){
				tempcount ++;
			}
		}
	}

	if(tempcount <= count) {
		for(;i>0;i--) {
			newNode = oClone.cloneNode(true);
			oParent.appendChild(newNode);
		}
	} else {
		alert(msgtext);
	}
}

function clonePoll(maxpoll){
	var newNode = cloneObj($('divPollItem'), $('polloptions') ,parseInt(maxpoll)+1);
	if(!newNode){
		alert('投票项不能多于 ' + maxpoll + ' 个');
	}
	var inputs = findtags(newNode, 'input');
	var attach;
	for(i in inputs) {
	    inputs[i].value="";
		if(inputs[i].name == 'pollitemid') {
			
			inputs[i].id = "pollitemid";
		}
	}
}

function delOjb_1(oParent, count, msgtext) {
	var tempcount = 0;
	for(k=0;k<oParent['childNodes'].length;k++){
		if (oParent['childNodes'][k].tagName){
				tempcount ++;
		}
	}
	
	if(tempcount > count) {
		oParent.removeChild(oParent.lastChild);
	} else {
		alert(msgtext);
	}
}


function initCountDownRedirector(){
	var x	= document.getElementById("TimeCountNum");
	if(!x) return;
	var t	= x.innerHTML;
	window.setTimeout("countDownRedirector()",1000);
}
function countDownRedirector(){
	var x	= document.getElementById("TimeCountNum");
	if(!x) return;
	var t	= x.innerHTML;
	if(t > 0 ){
		t--;
		x.innerHTML = t;
		window.setTimeout("countDownRedirector()",1000);
	}else{
		window.location	= x.title;
		//window.location.replace(x.title)
	}
}