﻿//设置viewport
function setViewPort(DocWidth){ 	
	var m_screen= window.screen.width;
	var m_viewport="<meta id=\"viewport\" name=\"viewport\" content=\"target-densitydpi=device-dpi,width="+DocWidth;
	var ZoomSize=m_screen / DocWidth;
	if(m_screen>DocWidth)
	{
		m_viewport+=",initial-scale="+ZoomSize+",minimun-scale=1,maximum-scale="+(m_screen / DocWidth);
	}else{
		m_viewport+=",initial-scale="+ZoomSize+",minimun-scale="+ZoomSize+",maximum-scale=1";
	}
	m_viewport+=",user-scalable=yes\" />";
	document.write(m_viewport);
}
//询问后转址h
function BugsTop(aID)
{	
	try{
		window.top.document.getElementById(aID).src="about:blank";		
	}catch(e){}	
}

function C2L(ShowTxt,ToUrl)
{
	if(confirm(ShowTxt)){
		window.location=ToUrl;
	}
}

//IFRAME 高
function SetCwinHeight(iFname)
{
	var cwin=document.getElementById(iFname);
	if (document.getElementById)
	{
	if (cwin && !window.opera)
	{
		if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
		cwin.height = cwin.contentDocument.body.offsetHeight; 
		else if(cwin.Document && cwin.Document.body.scrollHeight)
		cwin.height = cwin.Document.body.scrollHeight;
		}
	}
}


String.prototype.stripAllHTML = function() {
	var reTag = /<(?:.|\s)*?>/g; return this.replace(reTag,"").replace(/(^\s*)|(\s*$)/g,"").replace(/[\r\n]/g, "");
}


/*Post*/
function AjaxPostClick(iUrl,showName,data)
{
	AjaxClickFull("",iUrl,showName,"",data);
}

function AjaxClick(iUrl,showName)
{
	AjaxClickFull("",iUrl,showName,"","");
}
function AjaxClickFull(showAlertText,iUrl,showName,showLoading,data)
{
	AjaxClickIt(showAlertText,iUrl,showName,showLoading,"",data);
}
function AjaxClickIt(BeforePostAlert,iUrl,ShowObjID,LoadingObjID,PostingAlertText,postData)
{	

	if(BeforePostAlert.length>0)
	{
		if(!confirm(BeforePostAlert))
		return;
	}
	var isSetValue=false;
	if(ShowObjID.indexOf("value.")==0)
	{
		ShowObjID=ShowObjID.substring(6);
		isSetValue=true;
	}
	if(!isSetValue)
	{
		try{document.getElementById(ShowObjID).innerHTML=PostingAlertText;}catch(e){}	
	}
	if(LoadingObjID!="")
	{
		try{
			document.getElementById(LoadingObjID).style.display="block";
			if(!isSetValue)
			{
				document.getElementById(LoadingObjID).style.display="none";
			}
			
		}catch(e){}
	}
	
	try{
		var postUrl=iUrl+"&A="+Math.random();		
		if(iUrl.indexOf("?")<0)
		{
			postUrl=iUrl;
		}
		var subAjax=newAjax();
		
		subAjax.onreadystatechange=function(){
		if(subAjax.readyState==4){
			if(subAjax.status == 200)
			{				
				var iResult=subAjax.responseText;
				try{
					if(!isSetValue)
					{
						document.getElementById(ShowObjID).innerHTML=iResult;
					}else{
						document.getElementById(ShowObjID).value=iResult;
					}
				}catch(e){
					//alert(showName+".Error")
					alert(iResult);
				}
				
				if(LoadingObjID!="")
				{
					try{
						document.getElementById(LoadingObjID).style.display="none";
						if(!isSetValue)
						{
							document.getElementById(ShowObjID).style.display="";
						}
						
					}catch(e){}
				}			
			}
		 }	
	   }	
	   
	   
		subAjax.open("POST",postUrl,true);
		subAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");    
		//subAjax.setRequestHeader("Connection", "close");
		//alert("postData(131):"+postUrl+",postData:"+postData);
		//subAjax.send(null);
		subAjax.send(postData);
		
	}catch(e){
		alert("AjaxClick Error!\\n"+e);
	}	
}
function IframeSubmit(iUrl,FormName)
{	
	var iForm;
	try{
	var iForm=document.getElementById(FormName);
	}catch(e){
		alert(FormName+" Error");
		return;
	}
	var ifName="IFrame_"+FormName;
	try{	
	iForm.action=iUrl;
	iForm.target=ifName;
	iForm.submit();
	}catch(e){
		alert(e);
	}
}


function AjaxSubmit(iUrl,FormName)
{
	AjaxSubmitFull(iUrl,FormName,"");
}

function AjaxSubmitFull(iUrl,FormName,OutRstName)
{
	try{
		var postUrl=iUrl+"&A="+Math.random();
		document.getElementById(FormName).submit();
			return;
		var parameters=getRequestBody(FormName);
		
		var subAjax=newAjax();
		
		subAjax.onreadystatechange=function(){
		if(subAjax.readyState==4){
			if(subAjax.status == 200)
			{
				var dataL1=subAjax.responseText;
				var showType=1;
				if(dataL1.length>5)
				{
					if(dataL1.substring(0,6)=="ERROR:")
					{
						dataL1=dataL1.substring(6);								
						showType=2;					
					}
				}
				if(showType==1)
				{
					try{
						if(OutRstName=="")
						{
							OutRstName="AjaxForm_"+FormName;
						}
						var SubmitFormBody=document.getElementById(OutRstName);
						SubmitFormBody.innerHTML=dataL1;					
					}catch(e){
						alert("AjaxForm_"+FormName+" Not Exist!");
					}
				}else if(showType==2)
				{
					alert(dataL1);	
				}
				
				try{
					document.getElementById("FORM_DOACTION_ACT").disabled=false;
				}catch(e){}
								
			}
		}
	}	
	subAjax.open("POST",postUrl,true);
	subAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    subAjax.setRequestHeader("Content-length", parameters.length);
    subAjax.setRequestHeader("Connection", "close");
	
    subAjax.send(parameters);
	}catch(e){
		alert("AjaxSubmit Error!\\n"+e);
	}
}

function getRequestBody(oFormName){
	var oForm;
	try{
		oForm=document.getElementById(oFormName);
	}catch(e){
		alert("Error Get Form");
		return "";
	}
	var sParams="";
	
	for(var i=0;i<oForm.elements.length;i++)
	{		
		var  itemK=oForm.elements[i];
		
		if ( itemK.name!='' ) 
        {
			//alert(itemK.type);
          if ( itemK.type == 'select-one' ) 
          {
			  try{
				  if(itemK.selectedIndex>=0)
				  {
					  itemValue = itemK.options[itemK.selectedIndex].value;
				  }
             
			  }catch(e){
				 //alert(e);
			}
			 //alert(itemK.name+","+itemValue);
          }else if( itemK.type=='checkbox' || itemK.type=='radio') 
          {
          	if ( itemK.checked == false ){continue;}
            itemValue = itemK.value;
            }else if ( itemK.type == 'button' 
			|| itemK.type == 'submit' 
			|| itemK.type == 'reset' || itemK.type == 'image')
			 {// ignore this type
					continue;
			 }else{
                    itemValue = itemK.value;
              }                    
			
			 sParams += "&"+ encodeURIComponent(itemK.name) + '=' + encodeURIComponent(itemValue);			 
        }	
	}
	if(sParams.length>0)
	{
		sParams=sParams.substring(1);		
	}
	return sParams;
}

function addSels(SelName,nvlist,IsClear,selectValue)
{		
	if(IsClear=="clear")
	{
		clearSel(SelName);
	}
	
	if(nvlist.length==0)
	return;	
	
	var A=nvlist.split("|");
	
	if(A.length % 2 !=0)
	{
		clearSel(SelName);
		return;
	}
	
	var Sel=document.getElementById(SelName);
	var item;
	//alert(A.length);
	for(var i=0;i<A.length;i+=2)
	{		
		try{
			var oOption = document.createElement("option");
			oOption.appendChild(document.createTextNode(A[i+1]));
		
			if (arguments.length >= 3) 
			{
				oOption.setAttribute("value", A[i]);
			}			
			Sel.appendChild(oOption);
			
			if(selectValue==A[i])
			{
				Sel[Sel.length-1].selected=true;				
			}
		}catch(e){
			alert(e);
			break;
		}		
	}
	//alert(Sel.length);
}


function addSel(SelName,n,v)
{	
	try{
		var oOption = document.createElement("option");
		oOption.appendChild(document.createTextNode(n));
		
		if (arguments.length >= 3) 
		{
			oOption.setAttribute("value", v);			
		}		
		document.getElementById(SelName).appendChild(oOption);	
					
	}catch(e){
		alert(e);		
	}	
}
function clearSel(SelName)
{
	try{	
	var selTarget=document.getElementById(SelName);
	if(selTarget.selectedIndex > -1) 
	{//说明选中
		for(var i=0;i<selTarget.options.length;i++)
		{
			if(selTarget.options[i].selected)
			{
				selTarget.remove(i);				
				i = i - 1;//注意这一行
			}
		}
	}	
	}catch(e){alert(e)}	
}

function play_flv(flv_flash_name,tW,tH)
{
	var flash_a='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"   WIDTH='
	+tW
	+' HEIGHT='
	+tH
	+'>'
	+'<embed src="/Templet/Media/play_flv.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" '
	+'type="application/x-shockwave-flash" width="'
	+tW
	+'" height="'
	+tH
	+'" wmode="transparent" ></embed>'
	+'<param name=WMODE value=Transparent>'	
	+'<PARAM NAME=movie VALUE="/Templet/Media/play_flv.swf"></OBJECT>'
	
	document.write(flash_a);
}


function formActionWD(f,fAction){
	//try{
		controlWindow=window.open(fAction
		,"surveywin"
		,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=450,height=300");
		document.all[f].target="surveywin";
		var selfAction=document.all[f].action;
		document.all[f].action=fAction;		
		document.all[f].submit();
		document.all[f].target="_self";
		document.all[f].action=selfAction;
		
		
	//}catch(E){}
}
function reloadPrePage()
{
	var parentWin = window.dialogArguments;
	parentWin.location.reload();
}

function openJsWD(_target,widtha,heighta)
{
window.open(_target, "_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="
+widtha+",height="
+heighta);
}

function localPageName()
{
	try{
			var   s   =   document.location.href;   
	  	s   =   s.substr(s.lastindexof("/")+1);   
	  return s;
  }catch(E){
  	return "";
  }
}



function CopyHtml(tDivFrom,tDivTarget,tLen,tVar,keepI_A)
{
	tDivTarget.innerHTML =tDivTarget.innerHTML+tDivFrom.innerHTML;
	try
	{
		for(i=1;i<=tLen;i++)
		{
			var correI=tVar.length-i;
			for(var k=0;k<keepI_A.length;k++)
			if(i.toString() != keepI_A[k].toString())
				tVar[correI].value="";
		}
	}catch(e){

	}
}


function ShowWindow(url, width, height)
{
	try{		
		var arr = showModelessDialog(url+"&A="+Math.random(), window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:yes;status:no");
	}catch(e){}
}


function ShowDialog(url, width, height)
{
	try{		
		var arr = showModalDialog(url+"&A="+Math.random(), window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
	}catch(e){}
}

function ShowDialogScroll(url, width, height,title)
{
	if(title==undefined)
	{
		title="小窗口";
	}
	//alert(url+","+width+","+height+","+title);
	$().ready(function(e) {
        try{
			var dialog = jDialog.iframe(url,{
			title : title,
			width : width,
			height : height
		    });
			
		}catch(e){alert(e);}
    });
}

function ShowDialogScroll_2016(url, width, height)
{
	try{		
		var arr = showModalDialog(url+"&A="+Math.random(), window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:auto;status:no");
	}catch(e){
		try{
			window.open(url+"&A="+Math.random(),'newWin','modal=yes,width='+width+',height='+height+',resizable=no,scrollbars=no');
		}catch(ee)
		{
			alert(ee);
		}		
	}
}



function CopyAllHtml(tDivFrom,tDivTarget)
{
	try
	{
	document.getElementById(tDivTarget).innerHTML
		=document.getElementById(tDivTarget).innerHTML
			+document.getElementById(tDivFrom).innerHTML;
	}catch(e){

	}
}

function CopyKAllHtml(tDivFrom,tDivTarget,VarName,clearIndexList)
{
	try
	{
	document.getElementById(tDivTarget).innerHTML
		=document.getElementById(tDivTarget).innerHTML
			+document.getElementById(tDivFrom).innerHTML;	
	}catch(e){}
	try
	{
		if(clearIndexList.length==0)
			return;

		var tCheckBtn=document.getElementsByName(VarName);
		var allNul=tCheckBtn.length;
		var tListA=clearIndexList.split('|');
		var tListAN=tListA.length;
		
		if (allNul==undefined || tListAN==undefined)
			return;


		if(allNul<tListAN)
			return;

		for(var k=0;k<tListAN;k++)
		{
			var clearIndex=allNul-tListA[k];
			if(clearIndex>=0 && clearIndex<allNul)
			tCheckBtn[clearIndex].value="";
		}

	}catch(e){

	}
}

function objS_H(objName){
	try{
		
		if(document.getElementById(objName).style.display=="")
		{
			document.getElementById(objName).style.display='none';
		}else{
			document.getElementById(objName).style.display="";
		}
	}catch(e){}
}

function srcPIC(obj,tPic)
{
	try{
		obj.src=tPic;
		}catch(e){}
}

function newAjax()
{
	var xmlHttp;
	if(window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		
	}else if(window.XMLHttpRequest){
		xmlHttp=new XMLHttpRequest();
	}
	return xmlHttp;
}

function createAjax(){
	var httpRequest;
　　try{
　　　　　　　httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
　　}catch(e){
　　　try{
　　　　　httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
　　　　}catch(e1){
　　　　　httpRequest=new XMLHttpRequest();
　　　}
　　}
　　return httpRequest;
}


function setHTML(obj,val)
{
	try{
	document.getElementById(obj).innerHTML=val;		
	}catch(e){}
}
function setVALUE(obj,val)
{
	try{
		document.getElementById(obj).value=val;
		
	}catch(e){}
}
function ER(str)
{
	if(str=="")
		return "<font color=green>√</font>";
	
	return "<font color=red>×</font><font color=red> "+str+"</font>";
}


function OpenSWd(Url)
{	
	if(Url =="")
	return;
    var OKPrintForm = document.createElement("FORM");
    document.body.appendChild(OKPrintForm);
    OKPrintForm.method = "GET"; 
    OKPrintForm.action=Url;
    OKPrintForm.target="_blank";
    OKPrintForm.submit();
}


function copyLink(){try{var cText=document.location.toString();if(window.clipboardData){window.clipboardData.setData("Text",cText);alert("复制完成!");}else if(window.netscape){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}catch(e){alert("您的浏览器设置为不允许复制！\n如果需要此操作，请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true',再重试复制操作!");return false;}
var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);if(!clip)return;var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);if(!trans){return;}
trans.addDataFlavor('text/unicode');var str=new Object();var len=new Object();var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);str.data=cText;trans.setTransferData("text/unicode",str,cText.length*2);var clipid=Components.interfaces.nsIClipboard;if(!clip)return false;clip.setData(trans,null,clipid.kGlobalClipboard);alert("复制完成!");}}catch(e){}};/*  |xGv00|946870e9799bcd16f72c1f8858e736dd */

// 设置为主页
//SetHome(this,window.location) 
function SetHome(obj,vrl){ 
try{ 
  obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl); 
} 
catch(e){ 
if(window.netscape) { 
try { 
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
} 
catch (e) { 
  alert("此操作被浏览器拒。"); 
} 
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
prefs.setCharPref('browser.startup.homepage',vrl); 
}else{ 
alert("您的浏览器不支持。"); 
} 
} 
} 
// 加入收藏 兼容360和IE6 
//shoucang(document.title,window.location)
function shoucang(sTitle,sURL) 
{ 
try 
{ 
window.external.addFavorite(sURL, sTitle); 
} 
catch (e) 
{ 
try 
{ 
window.sidebar.addPanel(sTitle, sURL, ""); 
} 
catch (e) 
{ 
alert("加入收藏失败，请使用Ctrl+D进行添加"); 
} 
} 
} 