
var Utils = new Object();

/*根据元素ID查找元素*/
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }
  return elements;
}

/*根据元素ID取得元素*/
function $E(elemid) {
  return document.getElementById(elemid);
}

/*根据元素ID取得元素的value*/
function $Vo(elemid) {
  return document.getElementById(elemid).value;
}

/*根据元素ID取得元素的innerHTML*/
function $H(elemid) {
  return document.getElementById(elemid).innerHTML;
}

/*url跳转*/
function $url(id,param,target)
{
	var url='';
	if(id&&id=='1'){
		url='/index_personal.jsp?email=';
	}else if(id&&id=='2'){
		url='/index_ring.jsp?email=';
	}else if(id&&id=='3'){
		url='/index_ploy.jsp?email=';
	}
	//alert(url+'\n'+param);
	if(target==''||target=='p'){
		parent.location.href=url+param;
	}else if(target=='w'){
		window.location.href=url+param;
	}
}
/*弹出窗口*/ 
function $open(href){ 
	window.open (href, "newwindow", "height=600, width=600, top=100, left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")

}

/*自适应大小*/ 
function   DrawImage(ImgD,_width,_height){
	if(!_width) _width=120;
	if(!_height) _height=120;
	var flag=false;
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0&&image.height>0){
		flag=true;
		if(image.width/image.height>=_width/_height){//120/120
			if(image.width>_width){   
				ImgD.width=_width;
				ImgD.height=(image.height*_width)/image.width;
			}else{
				ImgD.width=image.width;   
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else{
			if(image.height>_height){   
				ImgD.height=_height;
				ImgD.width=(image.width*_height)/image.height;   
			}else{
				ImgD.width=image.width;   
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}
}  

/*验证数字*/
function isNumber(e){
	var number = "1234567890";
	for(var i=0; i<e.length; i++){
		if (number.indexOf(e.charAt(i))<0) {
			return false;
		}
	}
	return true;
}
function isDomain(e){
	var number = "abcdefghijklmnopqrstuvwxyz1234567890";
	for(var i=0; i<e.length; i++){
		if (number.indexOf(e.charAt(i))<0) {
			return false;
		}
	}
	return true;
}

/*翻页验证*/
function $P(id,totalPage,href,divId){
	var e=document.getElementById(id);
	alert(e.value);
	if ( !isNumber(e.value)) {
		window.alert('页数应为数字!');
		e.focus();
	}else{
	
 		if(e.value > totalPage || e.value < 1){
 			window.alert('页数应在1和'+totalPage+'之间!');
			e.focus();
		}else{
			App.page('{id:"'+divId+'",url:"'+href+e.value+'"}');
		}
	
 	}
}

/*自动调整IFrame高度*/ 
function $W(targObj,id){
 //alert(1);
 //var targWin = targObj.parent.document.all[targObj.name];
 var targWin = targObj.parent.document.getElementById(id);
 if(targWin != null) {
  //var HeightValue = targObj.document.body.scrollHeight;
  var HeightValue = document.body.scrollHeight;
  //if(HeightValue < 600){HeightValue = 900} //不小于600
  //alert(HeightValue);
  	targWin.style.height = HeightValue+400;
 }
 //alert(2);
}
function reheight(id,height2){
	if(height2){
		if(parent&&parent.document.getElementById(id)){
			parent.document.getElementById(id).style.height=height2;
		}
	}else{
		if(parent&&parent.document.getElementById(id)){
			parent.document.getElementById(id).style.height=document.body.scrollHeight;
		}
	}
}
function autoResize(name)
{
try
{
	if(name == 'iframe_ring'){
 		document.all["iframe_ring"].style.height=iframe_ring.document.body.scrollHeight;
 	}
 	if(name == 'iframe_diy'){
 		document.all["iframe_diy"].style.height=iframe_diy.document.body.scrollHeight;
 	}
}
catch(e){}
}


/*Cookie*/
function setCookie(name,value)
{
    var Days = 365;
    var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg)) return unescape(arr[2]);
        else return null;
}
function delCookie(name)
{
    var exp = new Date();
        exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
        if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

/*取字符长度，一个中文字符为两个字节*/
function $len(str){
	return (''+str).replace(/[^\x0000-\xFF00]/gi,'xx').length;
}

/*网页转向*/
function $U(url){
	window.location.href=url;
}
/*解析返回的xml元素，生成对象*/
function parseResponseMessage(documentElement){
     var dataobj = new Object();
     dataobj.messages =[];
	//parse messages
	 var messageroot = documentElement.getElementsByTagName("messages")[0];
     var msgs = messageroot.getElementsByTagName("message");
	 var ln = msgs.length; 
	  
	 if(ln>0)
	 for(var i=0; i<ln; i++){
	     if(msgs[i].firstChild)
	     dataobj.messages[i]= msgs[i].firstChild.nodeValue;
	 }
	 //parse datas
	 var dataroot = documentElement.getElementsByTagName("datas")[0];
	 var ds = dataroot.getElementsByTagName("data");
	 var ln2 = ds.length;
	 if(ln2>0){
		 for(var j=0; j<ln2; j++){
		     var key = ds[j].getAttribute("key");
		     var value = ds[j].firstChild.nodeValue;
             eval("dataobj."+key+"=\""+value+"\";");
		 }
	 }
	 //parse status
	 var status = documentElement.getElementsByTagName("status");
	 if(status && status.length > 0){
		 if(status[0].firstChild){
			dataobj.status = status[0].firstChild.nodeValue;			 
		 }
		else{
			dataobj.status = "";			 
		}
	 }
	 
	 return dataobj;	 
}

  /*检查Email是否合法*/
  function isEmail(s){
        if (s.length<7||s.length > 50){
                return false;
        }
         var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
         var re = new RegExp(regu);
         if (s.search(re) != -1) {
               return true;
         } else {
               return false;
         }
}

  /*检查日期是否合法*/
function isValidDate( year, month, day )
{
   year  = parseInt(year,10);
   month = parseInt(month,10);
   day   = parseInt(day,10);

   if (( month==4) || (month==6) || (month==9) || (month==11) )
   { if (( day < 1) || (day > 30) )
     { alert( "日期在1 - 30之间" );
       return (false);
     }
   }
   else
   { if ( month!=2 )
     { if ( (day < 1) || (day > 31 ))
       {  alert( "日期在1 - 31之间" );
          return (false);
       }
     }
     else
     { // month == 2
       if ( ( year % 100 ) != 0 && (year % 4 == 0) || ( year % 100 ) == 0 && ( year % 400) == 0 )
       { if ( day > 29 )
         {  alert( "日期在1 - 29之间" );
            return (false);
         }
       }
       else
       { if ( day > 28 )
         { alert( "日期在1 - 28之间" );
           return (false);
         }
       }
     }
   }
 return (true);
}



function getElementsByClassName(node, className) {
	var children = node.getElementsByTagName('*');
	var elements = new Array();
	for (var i=0; i<children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

function getNodeID(parent, id) {
	var ln = parent.childNodes.length;
	for (var z=0; z<ln; z++) {
		if (parent.childNodes[z].id == id) return parent.childNodes[z];
	}
	return null;
}


Utils.getChildrenByTagName = function(node, tagName) {
	var ln = node.childNodes.length;
	var arr = [];	
	for (var z=0; z<ln; z++) {
		if (node.childNodes[z].nodeName==tagName) arr.push(node.childNodes[z]);
	}
	return arr;
}


var Browser = new Object();


Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

if (Browser.isMozilla) {
	HTMLElement.prototype.removeNode = function() {
		this.parentNode.removeChild(this);
	}
}

Utils.htmlEncode = function(text) {
	return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

/*
<!--[if IE]>
	<a href onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.netvibes.com');">Make Netvibes your homepage</a>
<![endif]-->
*/

function isEmailValid(e) {
	var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.+@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(var i=0; i<e.length; i++){
		if (ok.indexOf(e.charAt(i))<0) {
			return false;
		}
	}
	if (document.images) {
		var re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		var re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,8}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return -1;
		}
	}
}

function isCellPhoneNoValid(e) {
	var number = "1234567890";
	if(e.length!=11) return false;
	for(var i=0; i<e.length; i++){
		if (number.indexOf(e.charAt(i))<0) {
			return false;
		}
	}
}


var notspace = /\S/;
Utils.cleanWhitespace = function(node){
	for (var x=0; x<node.childNodes.length; x++) {
		var child = node.childNodes[x];
		//if it's a whitespace text node
		if ((child.nodeType == 3) && (!notspace.test(child.nodeValue)))	{
			node.removeChild(node.childNodes[x]);
			//node.childNodes[x].removeNode();
			x--;
		}
		//elements can have text child nodes of their own
		if(child.nodeType == 1) {
			Utils.cleanWhitespace(child);
		}
	}
}


String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g,"");
}


/*popup*/
var oPopup = window.createPopup();   
var popTop=50;   
function popmsg(msgstr){   
var winstr="<table style=\"border: 1 solid #000000\" width=\"241\" height=\"172\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";   
winstr+="<tr><td height=\"150\"><\td><td align=\"center\"><table width=\"90%\" height=\"110\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";   
winstr+="<tr><td valign=\"top\" style=\"font-size:12px; color: #F00000; face: Tahoma\">"+msgstr+"<\td><\tr><\table><\td><\tr><\table>";   
oPopup.document.body.innerHTML = winstr;   
popshow(); 
}   
function popshow(){   
window.status=popTop;   
if(popTop>1720){   
clearTimeout(mytime);   
oPopup.hide();   
return;   
}else if(popTop>1520&&popTop<1720){   
oPopup.show(screen.width-250,screen.height,241,1720-popTop);   
}else if(popTop>1500&&popTop<1520){   
oPopup.show(screen.width-250,screen.height+(popTop-1720),241,172);   
}else if(popTop<180){   
oPopup.show(screen.width-250,screen.height,241,popTop);   
}else if(popTop<220){   
oPopup.show(screen.width-250,screen.height-popTop,241,172);   
}   
popTop+=10000;   
var mytime=setTimeout("popshow();",1);   
}   
popmsg(" ");   


