/* Type */
Object.isNull=function(o){return(null==o||undefined==o);}
var __sp=String.prototype;
__sp.endsWith=function(suffix){
	return(this.substr(this.length-suffix.length)==suffix);
}
__sp.startsWith=function(prefix){return(this.substr(0,prefix.length)==prefix);}
__sp.lTrim=__sp.trimStart=function(){return this.replace(/^\s*/,"");}
__sp.rTrim=__sp.trimEnd=function(){return this.replace(/\s*$/,"");}
__sp.trim=function(){return this.trimStart().trimEnd();}
__sp.format=function(){
	var s=this;
	var aRE=__sp.format.aRegExp;
	var iCount=arguments.length;
	for(var i=0;i<iCount;i++){
		if(!aRE[i]){
			aRE[i]=new RegExp("\\{"+i+"\\}","g");}
		s=s.replace(aRE[i],arguments[i]);
	}
	return(s);
}
__sp.format.aRegExp=[];
String.isEmpty=function(string){return Object.isNull(string)||""==string;}

/* Form */
function showhid()
{
	var me = event.srcElement;
	var c = me.parentElement.parentElement.children[2];
	if( c.style.display == "none")
	{
		c.style.display = "block";
		me.src = "http://pub.anyp.cn/images/blog/up.gif";
	}
	else
	{
		c.style.display = "none";
		me.src = "http://pub.anyp.cn/images/blog/down.gif";
	}
}

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;
		}
		else{
			elements.push(element);
		}		
	}
	
	return elements;
}

/* Ajax */
function Ajax(){}
Ajax.prototype = {
	err_404		: "Page not found!",
	err_500		: "Application error!",
	
	Execute		: function(url, callback, eventCtl, statusCtl){
		this.eventCtl = eventCtl;
		this.statusCtl = statusCtl;
		
		if( this.eventCtl != undefined ){
			this.eventCtl.disabled = true;
		}
		if( this.statusCtl!= undefined){
			this.statusCtl.innerText = "Processing...";
			this.statusCtl.className = "processInfo";
		}
		this.Open(url,"GET","",callback);
	},
	
	Open : function(url,method,data,onsucc,onerror,resultFormat){
		var req = this.GetRequest();
		this.succCallback = onsucc;
		this.errCallback = onerror?onerror:this.ShowError;
		this.resultFormat = resultFormat?resultFormat:"text";
		if( req == null){
			this.errCallback("Not Support Ajax!");
			return;
		}
		else{
			this.request = req;
		}
		
		var loader = this;
        this.request.onreadystatechange = function(){loader.StateChange();};
		if( method == "POST"){
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		req.open(method,url,true);
		req.send(data);
	},
			
	StateChange : function(){
		var req = this.request;
		if( req.readyState == 4){
			if( req.status == 200){
				if( this.resultFormat == "xml"){
					this.succCallback(req.responseXML);
				}
				else{
					var resText = req.responseText;
					if( !resText.startsWith("result:")){
						this.succCallback(1, resText);
					}
					else{
						if( this.statusCtl!= undefined){
							if( resText.substring( 7, 8) == "0"){
								this.statusCtl.className="okinfo";
							}
							else{
								this.statusCtl.className = "errinfo";
							}
							this.statusCtl.innerHTML = resText.substring( resText.indexOf("|") + 1, resText.length);
						}
						this.succCallback(resText.substring( 7, resText.indexOf("|")), resText.substring( resText.indexOf("|") + 1, resText.length));	
					}				
					
					if( this.eventCtl!= undefined){
						this.eventCtl.disabled = false;
					}
				}
			}
		}
		else{
		}
	},

	GetRequest : function(){
		var req = null;
		if( window.XMLHttpRequest){
			req = new XMLHttpRequest();
			if(req.overrideMimeType){
                 req.overrideMimeType("text/xml");
            }
            
		}
		else{
			if(window.ActiveXObject){
				try{
					req = new ActiveXObject("Msxml3.XMLHTTP");
				}
				catch(e){
					try{
						req = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e){
						try{
							req = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch(e){
						}
					}
				}				
			}
		}
		
		return req;
	},
	
	ShowError : function(err){
		window.alert(err);
	}
}


function justifyRegion()
{
    /*try
    {
	    var otable = document.getElementById("divRegions");
	    if(!otable || !otable.childNodes[0]) return;
	    var otbody = otable.childNodes[0];
	    if( otbody.childNodes.length <=1) return;
	    var rows = otbody.childNodes;
	    if( rows[0].childNodes[0].rowSpan == 1) return;
	    var maxheight = rows[0].childNodes[0].clientHeight;
	    var height = 0;
	    for( i = 1;i< rows.length;i++)
	    {
		    if( rows[i].childNodes.length == 0) break;
		    var h1 = 0;
		    var h2;
		    var cells = rows[i].childNodes
		    for(j=0;j<cells.length;j++)
		    {
			    h2 = 0;
			    for( k=0;k<cells[j].childNodes.length;k++)
			    {
				    h2 += cells[j].childNodes[k].scrollHeight;
			    }
			    if( h2 > h1) h1 = h2;
		    }
		    height += h1;
	    }
	    if( maxheight > height )
	    {
		    rows[0].childNodes[0].rowSpan = rows[0].childNodes[0].rowSpan + 1;
		    var otr = document.createElement("tr");
		    otbody.appendChild(otr);
		    var otd = document.createElement("td");
		    otbody.childNodes[otbody.childNodes.length-1].appendChild(otd);
		    var obj = otbody.childNodes[otbody.childNodes.length-1].childNodes[0];
		    obj.innerHTML = "&nbsp;";
		    obj.colSpan = otbody.childNodes[0].childNodes[1].colSpan;
		    obj.style.height = (maxheight-height) + "px";
	    }
	}catch(e){}*/
}

function resizeImg(img,maxw,maxh)
{
    var tempImg = document.createElement("img"); 
    tempImg.onload = function(){imageLoad(this);}
    tempImg.friend = img;
    tempImg.src = img.src; 
    tempImg.maxw = maxw;
    tempImg.maxh = maxh;    
}

function imageLoad(tempImg)
{
    var img = tempImg.friend;
    if( !tempImg.maxw)tempImg.maxw = 150;
    if( !tempImg.maxh)tempImg.maxh = 150;
    if( img.maxw)tempImg.maxw = img.maxw;
    if( img.maxh)tempImg.maxh = img.maxh;
    var flScale = Math.min( 1, Math.min( (tempImg.maxw / tempImg.width), (tempImg.maxh / tempImg.height) ) ); 
    
    img.style.width = Math.round( tempImg.width * flScale) + "px"; 
    img.style.height = Math.round( tempImg.height * flScale) + "px"; 
}
function openChat(comid){window.open('http://chat.anyp.com/chatroom.aspx?roomid='+comid,'chat'+comid,'width=960,height=550,resizable=no,scroll=no,menubar=no');}

function getCommentSum(sourceid,type)
{
    var aj = new Ajax(); 
    var url =  "/ajax/getCommentSum.aspx?id=" + sourceid + "&type=" + type + "&rd=" + Math.random();
    aj.Execute(url,setCommentSum);
}
function setCommentSum(status,count)
{
    if(status == 0 && document.getElementById("lblAjaxCommentSum"))
    {
        document.getElementById("lblAjaxCommentSum").innerHTML = count;
    }   
}
function getClickSum(sourceid,type)
{
    var aj = new Ajax(); 
    var url = "/ajax/getClickSum.aspx?id=" + sourceid + "&type=" + type + "&rd=" + Math.random();;
    aj.Execute(url,setClickSum);
}
function setClickSum(status,count)
{
    if(status == 0 && document.getElementById("lblAjaxClickSum"))
    {
        document.getElementById("lblAjaxClickSum").innerHTML = count;
    }   
}
function getCookie(name) //cookies
{ 
    var   search   =   name   +   "= " 
    if(document.cookie.length   >   0)   
    { 
        offset   =   document.cookie.indexOf(search) 
        if(offset   !=   -1)   
        { 
            offset   +=   search.length 
            end   =   document.cookie.indexOf( "; ",   offset) 
            if(end   ==   -1)   end   =   document.cookie.length 
            return   unescape(document.cookie.substring(offset,   end)) 
        } 
        else  return   "";
    }
    return   "";
}
function getArticleContent(articleid)
{
    var aj = new Ajax(); 
    var url = "/ajax/getArticleContent.aspx?id=" + articleid + "&rd=" + Math.random();
    aj.Execute(url,setArticleContent);
}
function setArticleContent(status,html)
{
    if(status == 0 && document.getElementById("lblAjaxArticleContent"))
    {
        document.getElementById("lblAjaxArticleContent").innerHTML = html;
    }
    else if(status == 5)
    {
        alert(html);
    }
    else if(status == 4)
    {
        document.body.style.display = "none";
        if( confirm(html)) 
            document.location.href='/login2.aspx?backurl='+document.URL; 
        else 
            window.close();
    }
}

function overdate(msg)
{
    if( getCookies("overdue") == "")
    {
        setCookies("overdue", "1");
        alert(msg);
    }
}

function setCookies(name,value)
{
	document.cookie = name + "=" + escape (value) + ";";
}
function getCookies(name)
{
    var acookie=document.cookie.split("; ");
    for(var i=0;i<acookie.length;i++)
    {
        var arr=acookie[i].split("=");
        if(name==arr[0])
        {
            if(arr.length>1)
                return unescape(arr[1]);
            else
                return "";
        }
    }
    return "";
}

if(top.location != document.location){
    document.location.href = "about:blank";
}
