/*
Array.prototype.pop=function(){
     if(this.length!=0)this.length--;
     return this;
     }
*/

String.prototype.trim = function()
{
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}

String.prototype.len=function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
}

String.prototype.replaceAll  = function(s1,s2){    
return this.replace(new RegExp(s1,"gm"),s2);    
}

/*
function   GetQueryValue(sorStr,panStr)     
  {     
  var   vStr="";     
  if   (sorStr==null   ||   sorStr==""   ||   panStr==null   ||   panStr=="")   return   vStr;     
  sorStr   =   sorStr.toLowerCase();   
  panStr   +=   "=";     
  var   itmp=sorStr.indexOf(panStr);     
  if   (itmp<0){return   vStr;}     
  sorStr   =   sorStr.substr(itmp   +   panStr.length);     
  itmp=sorStr.indexOf("&");     
  if   (itmp<0)   
  {   
  return   sorStr;     
  }     
  else     
          {   
  sorStr=sorStr.substr(0,itmp);     
  return   sorStr;   
  }     
  }   
    
    
  //   获得url字符串   
  var   strGetQuery   =   document.location.search;   
  //   获得csdnstyle   参数的值   
  var   stylevalue   =   GetQueryValue(strGetQuery,'csdnstyle')  
  
  */

function doOK(){
	if(window.opener != null){
		var strURL = window.opener.location.href;
		window.opener.navigate(strURL);
		window.close();
	}
	else
		window.close();
}

function doClose(){
	window.close();
}

function doRefreshOpener(){
	if(window.opener != null){
		window.opener.location.replace(window.opener.location);
	}
}

function doRefresh(){
	window.navigate(window.location.href);
}

function doBack(){
	history.back(-1);
}

function newWindow(winWidth, winHeight, winScroll, winUrl, winName){
	var iLeft = (screen.width  - winWidth)/2;
	var iTop  = (screen.height - winHeight)/2;
	var strFeatures = "resizable=yes,scrollbars=" + winScroll + ",left=" + iLeft + ",top=" + iTop + ",width=" + winWidth.toString() + ",height=" + winHeight.toString();
	window.open(winUrl, winName, strFeatures);
}

function newDialog(winWidth, winHeight, winUrl){
	var strFeatures = "dialogHeight: " + winHeight + "px; dialogWidth: " + winWidth + "px;center: yes; help: no;resizable: no; status: no; scroll: no;";
	return window.showModalDialog(winUrl,this,strFeatures);
}

function newModelessWindow(winWidth, winHeight, winScroll, winUrl, winName){
	/*
	var strFeatures = "dialogHeight: " + winHeight + "px; dialogWidth: " + winWidth + "px;center: yes; help: no;resizable: yes; status: no; scroll: " + winScroll;
	window.showModelessDialog(winUrl,this,strFeatures);
	*/
	window.open(winUrl);
}

function isLong(str,l){ //判断字符串str字节数是否超出长度l
  var valueLen = 0;
  if (str != "")
  {
    for (i = 0; i < str.length; i ++)
    {
      var code = escape(str.charAt(i));
      if ((code.length >= 4) && (code < '%uFF60' || code > '%uFF9F'))
      {
        valueLen += 2;
      }
      else
      {
        valueLen ++;
      }
    }
  }
  return (valueLen>l?true:false)
}

function readCookie(doc, name)
{
	if(doc == null) doc = window.document;
	var cookieValue = "";
	var search = name + "=";
	if(doc.cookie.length > 0)
	{ 
		offset = doc.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = doc.cookie.indexOf(";", offset);
			if (end == -1) end = doc.cookie.length;
				cookieValue = unescape(doc.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function writeCookie(doc, name, value, expiresSeconds)
{
	if(doc == null) doc = window.document;
	var expire = "";
	if(expiresSeconds != null)
	{
		expire = new Date((new Date()).getTime() + expiresSeconds * 1000);
		expire = "; expires=" + expire.toGMTString();
	}
	
	//doc.cookie = name + "=" + escape(value) + expire;
	


	doc.cookie = name + "=" + escape(value) + expire + ";path=" + "/" + ";domain=" + "doshoot.com"// + "; secure";

}


function doCheckAll(checkboxName, checked)
{
	var checkboxList = document.getElementsByTagName("input");
	for (var i=0; i<checkboxList.length; i++)
	{
		if (checkboxList[i].name == checkboxName)
			checkboxList[i].checked = checked;
	}
}

function doCheckboxNavigate(alertMessage, checkboxName, strUrl){
	var IDs = "";
	var UrlIndex = "http";
	var UrlNum = strUrl.indexOf(UrlIndex);
	var UrlSub = strUrl.substring(UrlNum);//截取删除时返回的URL	
	var url = strUrl.substring(0,UrlNum) + escape(UrlSub);//部分加密
	
	var checkboxList = document.getElementsByName(checkboxName);

	var hasSelection = false; // 是否勾选	
	for(var i=0 ; i < checkboxList.length; i++)
	{
		if(checkboxList[i].checked)
		{
			hasSelection = true;
			break
		}
	}
	if(!hasSelection){
		window.alert("请从列表中勾选项目，再点击操作按钮！");
		return;
	}
	
	if(window.confirm(alertMessage)){
		for(var i=0 ; i < checkboxList.length; i++)
		{
			if(checkboxList[i].checked)
			{
				IDs += checkboxList[i].value + ',';
			}
		}
		var urlToGo = "";
		if(url.indexOf("&") >= 0){
			urlToGo = url + "&IDs=" + IDs
		}
		else{
			if(url.indexOf("?") >= 0){
				urlToGo = url + "IDs" + IDs
			}
			else{
				urlToGo = url + "?IDs" + IDs
			}
		}
		window.navigate(urlToGo);
	}
}


			
function imageResize(_width,outName) //自动将所有大图片变成固定宽度
{
	var iIndex=0;
	var nImgCount=0;
	var _obj=document;
		
	nImgCount=_obj.images.length;
	for(i=0;i<nImgCount;i++)
	{				   
		if(_obj.images[i].width>_width && _obj.images[i].name != outName)
		{     
			_obj.images[i].height=_width*_obj.images[i].height/_obj.images[i].width
			_obj.images[i].width=_width;
			_obj.images[i].style.cursor = "hand";
			var html = _obj.images[i].outerHTML;
			html = html.substr(0, html.length-1);
			html += " ";
			html += "onclick=\"newWindow('" + _obj.images[i].src + "');\"";
			html += ">";
			_obj.images[i].outerHTML=html;
		}
	}
}			

function newWindow(url)
{
	window.open(url);
}



// 创建分页信息
function GetPagedInfos(){

	var strHtm = '';
	strHtm += '<a href="'+myPaged_strPageUrl+'1'+'">首页</a> ';
	strHtm += '<a href="'+myPaged_strPageUrl + myPaged_iCurrentPageIndex +'">上一页</a> ';
	var iCurrentPage = myPaged_iCurrentPageIndex+1;
	
	for(var i=4;i>0;i--)
	{
		if(iCurrentPage-i<=0)
		{
			strHtm += "";
		}
		else
		{
			var PageCurrent = iCurrentPage-i;			
			strHtm += "<a href=\"" + myPaged_strPageUrl + "" + PageCurrent + "\">" + PageCurrent+ "</A>&nbsp";
		}
		
	}
	
	for(var i=iCurrentPage;i<iCurrentPage+5;i++)	
	{
		if(i>myPaged_iPageCount)
		{
			strHtm += "";
		}
		else
		{
			if(i==iCurrentPage)
			{
				strHtm += "<span class=\"pre_next_hl\">"+iCurrentPage+"</span>&nbsp;";
			}
			else
			{
				if(i==iCurrentPage+5)
				{
					strHtm+="<a href=\"" + myPaged_strPageUrl + "" + i + "\">"+i+"</a>";
				}
				else
				{
					strHtm+="<a href=\"" + myPaged_strPageUrl + "" + i + "\">"+i+"</a>&nbsp;";
				}
			}
		}
				
	}
	
	
	/*
	
	for(var i=1; i<=myPaged_iPageCount; i++){
		if(myPaged_iCurrentPageIndex + 1 == i)
			strHtm += '<span class="pre_next_hl">'+i+'</span> ';
		else
			strHtm += '<a href="'+myPaged_strPageUrl+i+'">'+i+'</a> ';
	}
	
	*/
	strHtm += '<a href="'+myPaged_strPageUrl + (myPaged_iCurrentPageIndex+2) +'">下一页</a> ';
	strHtm += '<a href="'+myPaged_strPageUrl + myPaged_iPageCount +'">尾页</a> ';
	s
	trHtm += "&nbsp;共 " + myPaged_iPageCount + " 页&nbsp;&nbsp;&nbsp;";
	return strHtm;
}

//图片按比例缩放 
	var flag=false; 
	function DrawImage(ImgD,iwidth,iheight)
	{
		var image=new Image(); 
		//var iwidth = 800;  //定义允许图片宽度 
		//var iheight = 550;  //定义允许图片高度 
		image.src=ImgD.src; 
		if(image.width>0 && image.height>0)
		{ 
			flag=true; 
			if(image.width/image.height>= iwidth/iheight)
			{ 
				if(image.width>iwidth)
				{   
					ImgD.width=iwidth; 
					ImgD.height=(image.height*iwidth)/image.width; 
				}
				else
				{ 
					ImgD.width=image.width;   
					ImgD.height=image.height; 
				} 
				//ImgD.alt=image.width+"×"+image.height; 
			} 
			else
			{ 
				if(image.height>iheight)
				{   
					ImgD.height=iheight; 
					ImgD.width=(image.width*iheight)/image.height;   
				}
				else
				{ 
					ImgD.width=image.width;   
					ImgD.height=image.height; 
				} 
				//ImgD.alt=image.width+"×"+image.height; 
			} 
		}
	}

function DrawImage(ImgD)
	{
		var image=new Image(); 
		var iwidth = screen.width-24;  
		var iheight = screen.height-80; 
		image.src=ImgD.src; 
		if(image.width>0 && image.height>0)
		{ 
			if(image.width/image.height>= iwidth/iheight)
			{ 
				if(image.width>iwidth)
				{   
					ImgD.width=iwidth; 
					ImgD.height=(image.height*iwidth)/image.width; 
				}
				else
				{ 
					ImgD.width=image.width;   
					ImgD.height=image.height; 
				} 
			} 
			else
			{ 
				if(image.height>iheight)
				{   
					ImgD.height=iheight; 
					ImgD.width=(image.width*iheight)/image.height;   
				}
				else
				{ 
					ImgD.width=image.width;   
					ImgD.height=image.height; 
				} 
			} 
		}
	}
	
function DrawThumbnailImage(ImgD, iWidth_Middle, iHeight_Middle)
	{
		var image=new Image(); 
		var iwidth = screen.width-24;  
		var iheight = screen.height-80; 
		image.src=ImgD.src; 
		if(iWidth_Middle/iHeight_Middle >= iwidth/iheight)
		{ 
			if(iWidth_Middle > iwidth)
			{   
				ImgD.width=iwidth; 
				ImgD.height=(iHeight_Middle * iwidth)/iWidth_Middle; 
			}
			else
			{ 
				ImgD.width = iWidth_Middle;   
				ImgD.height = iHeight_Middle; 
			} 
		} 
		else
		{ 
			if(iHeight_Middle > iheight)
			{   
				ImgD.height = iheight; 
				ImgD.width = (iWidth_Middle * iheight)/iHeight_Middle;   
			}
			else
			{ 
				ImgD.width = iWidth_Middle;   
				ImgD.height = iHeight_Middle; 
			} 
		}
	}

function dodel(msg,url,refurl)
{
	if(confirm(msg))
	{
		window.location = url + "&PageUrl=" + escape(refurl);
	}
}



function floatdiv(objid,fwidth,fheight,url)
{
	var floatdiv=document.getElementById(objid);
	if(url != "")
		floatdiv.src		= url;
	floatdiv.style.display	= "block";
	floatdiv.style.position	= "absolute";	
	floatdiv.style.left		= (document.documentElement.scrollLeft + fwidth)+'px';
	floatdiv.style.top		= (document.documentElement.scrollTop + fheight)+'px';
	floatdiv.style.zIndex	= "9999";	
}

//最近浏览过的图片
function mov()
{	 
	var chatDiv = null;
	if(document.getElementById("nearview") == null)		
		chatDiv=document.createElement('div');
	else
		chatDiv = document.getElementById("nearview");
		
	chatDiv.id				= "nearview";
	chatDiv.style.position	= "absolute";
	chatDiv.innerHTML		= '<a href="javascript:void(0);" onclick=floatdiv("nearrecord",50,200,"");><img src="/images/fd.gif"></a>';
	chatDiv.style.left		= (document.documentElement.scrollLeft)+'px';
	chatDiv.style.top		= (document.documentElement.scrollTop + 200)+'px';
	chatDiv.style.zIndex	= "9999";
		
	if(document.getElementById("nearview") == null)
		document.body.appendChild(chatDiv);	
	
	//setTimeout("mov()",10);
}

//window.onscroll = mov;
//if (window.attachEvent)	window.attachEvent("onload", mov); 

//if (window.attachEvent)	window.attachEvent("onload", loadpage); 
function loadpage()
{
	var iwidth		= window.screen.width-41 + "px";
	var itd_wwidth	= window.screen.width-269 + "px";
	var ih3width	= window.screen.width-64 + "px";
	var itd_cwidth	= window.screen.width-497 + "px";
	var iimg_cwidth	= window.screen.width-280 + "px";
	if(document.getElementById("head") != null)
		document.getElementById("head").style.width = iwidth;
	if(document.getElementById("nav") != null)
		document.getElementById("nav").style.width = iwidth;
	if(document.getElementById("foot") != null)
		document.getElementById("foot").style.width = iwidth;
		if(document.getElementById("width_h3") != null)
		document.getElementById("width_h3").style.width = ih3width;
	if(document.getElementById("td_w") != null)
		document.getElementById("td_w").style.width = itd_wwidth;
	if(document.getElementById("td_c") != null)
		document.getElementById("td_c").style.width = itd_cwidth;
		
	if(document.getElementById("user_img") != null)
		document.getElementById("user_img").style.width = iimg_cwidth;

		
}

//if (window.attachEvent)	window.attachEvent("onload", loadquestionpage); 
function loadquestionpage()
{
	var width_41    = window.screen.width-41 + "px";
	var width_271   = window.screen.width-271 + "px";
	var width_501   = window.screen.width-501 + "px";
	var width_261   = window.screen.width-261 + "px";
	if(document.getElementById("wrap") != null)
		document.getElementById("wrap").style.width = width_41;
	if(document.getElementById("con") != null)
		document.getElementById("con").style.width = width_271;
	if(document.getElementById("con_c") != null)
		document.getElementById("con_c").style.width = width_501;
	if(document.getElementById("framequestion") != null)
		document.getElementById("framequestion").width = width_271;
	if(document.getElementById("frameschedule") != null)
		document.getElementById("frameschedule").width = width_271;
	if(document.getElementById("frameshootplace") != null)
		document.getElementById("frameshootplace").width = width_271;
	if(document.getElementById("frameequipement") != null)
		document.getElementById("frameequipement").width = width_271;	
		
}		

function searchform()
{
	if(document.getElementById("SearchKeyword").value.trim() == "")
	{
		alert("请输入搜索关键字");
		document.getElementById("SearchKeyword").focus();
		return false;
	}
	
	return true;
}

function changelists(url)
{
	var listvalue = document.getElementById("changelist").value;
	window.location = url + "&Star=" + listvalue;
}

function changetemplate(templateid)
{
	writeCookie(null,"SystemTemplateID",templateid,60*60*24*365*10);
	
	var csspath = "http://www.doshoot.com/css/Template/sitestyle_"+templateid+".css";
	
	document.getElementById("SystemTemplateCSS").href = csspath;
	if(document.getElementById("framesquestion"))
		document.frames("framesquestion").document.getElementById("SystemTemplateCSS").href = csspath;
	if(document.getElementById("frameschedule"))
		document.frames("frameschedule").document.getElementById("SystemTemplateCSS").href = csspath;
	if(document.getElementById("frameequipement"))
		document.frames("frameequipement").document.getElementById("SystemTemplateCSS").href = csspath;
	if(document.getElementById("frameuserinfo"))
		document.frames("frameuserinfo").document.getElementById("SystemTemplateCSS").href = csspath;
	if(document.getElementById("framequestion"))
		document.frames("framequestion").document.getElementById("SystemTemplateCSS").href = csspath;
	
	
	document.getElementById("class_a_0").className = "";
	document.getElementById("class_a_1").className = "";
	document.getElementById("class_a_"+templateid+"").className = "un";
	
}


function changeforumtemplate(template)
{
	writeCookie(null,"ForumTemplateID",template, 60*60*24*365*10);
	
	var forumcss = "/css/bar.css";
	
	if (template == "bar")
	{
		document.getElementById("barcss").href = "";
		document.getElementById("changeforumstyle").href = "javascript:changeforumtemplate('forum');";
		document.getElementById("changeforumstyle").innerHTML = "[切换到论坛模式]"
	}
	else
	{
		document.getElementById("barcss").href = forumcss;
		document.getElementById("changeforumstyle").href = "javascript:changeforumtemplate('bar');";
		document.getElementById("changeforumstyle").innerHTML = "[切换到贴吧模式]";
	}
}