/**
*	网站公用JS代码
*	David Lu@2007-12-2
*	QQ: 79145842
*/

var http_request = false;
function send_request(url,callback,data){
	http_request=false;
	if(window.XMLHttpRequest){
		http_request=new XMLHttpRequest();
		if(http_request.overrideMimeType){
			http_request.overrideMimeType("text/xml");
		}
	}else if(window.ActiveXObject){
		try{
			http_request=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				http_request=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	if(!http_request){
		window.alert("Can NOT creat XMLHttpRequest Object.");
		return false;
	}
	nowtime	 = new Date().getTime();
	url += (url.indexOf("?") >= 0) ? "&nowtime=" + nowtime : "?nowtime=" + nowtime;
	if(typeof(data) =='undefined'){
		http_request.open("GET",url,true);
		http_request.send(null);
	}else{
		http_request.open('POST' , url, true);
		http_request.setRequestHeader("Content-Length",data.length);
		http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http_request.send(data);
	}
	if(typeof(callback) == "function" ){
		http_request.onreadystatechange = function (){
			if (http_request.readyState == 4){
				if(http_request.status == 200 || http_request.status == 304){
					try{gi("process").style.display='none';}catch(e){}
					callback(http_request);
				}else{
					alert("Error loading page\n" + http_request.status + ":" + http_request.statusText);
				}
			}else{
				try{gi("process").style.display='';}catch(e){}
			}
		}
	}
}
function ajax_convert(str){
	f = new Array(/\r?\n/g, /\+/g, /\&/g);
	r = new Array('%0A', '%2B', '%26');
	for (var i = 0; i < f.length; i++){
		str = str.replace(f[i], r[i]);
	}
	return str;
}
function gi(id){
	if (document.getElementById){
		return document.getElementById(id);
	}else if (document.all){
		return document.all[id];
	}else if (document.layers){
		return document.layers[id];
	}else{
		return null;
	}
}
function Ajax(){
    var ajax=false; 
    try { 
    	ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (e) { 
   	 	try { 
    		ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
    	} catch (E) { 
    		ajax = false; 
    	} 
    }
    if (!ajax && typeof XMLHttpRequest!='undefined') { 
    	ajax = new XMLHttpRequest(); 
    } 
    return ajax;
}
function chkLen()
{
	var o = chkLen.arguments;
	if(o.length > 0)
	{
		for(var i=0;i<o.length;i+=2)
			if(getId(o[i]).value.length > parseInt(o[i+1]))
			{
				alert("您输入的内容超出字数限制！");
				getId(o[i]).focus();
				return false;
			}
	}
	return true;
}
function chk(fm)
{
	if(typeof(fm) == "string"){
		if(!window.confirm(fm+"，您是否确定此操作？"))
			return false;
		else
			return true;
	}
	var o = fm.elements;
	for(var i=0;i<o.length;i++)
	{
		if(o[i].type == 'password' || o[i].type == 'text' || o[i].type == 'textarea')
			if(!o[i].id.match(/null/g) && o[i].value.match(/^\s*$/g))
			{
				alert("请把必填项目填写完整！");
				o[i].focus();
				return false;
			}
		if(o[i].type == 'checkbox' && (o[i].name == 'del[]' || o[i].name.match(/^del\w*\[\]$/)) && o[i].checked)
		{
			if(!window.confirm("删除不可恢复，您是否确定？"))
				return false;
		}
	}
	return true;
}
function getCord(o)
{
	var t = o;
	var cord = new Array();
	cord[0] = o.offsetLeft;
	cord[1] = o.offsetTop + o.offsetHeight;
	while(t = t.offsetParent)
	{
		cord[0] += t.offsetLeft;
		cord[1] += t.offsetTop;
	}
	return cord;
}
function getNavigator()
{
	var t = navigator.userAgent.toLowerCase();
	if(t.indexOf("firefox") != -1)
		return "firefox";
	else if(t.indexOf("maxthon") != -1)
		return "maxthon";
	else if(t.indexOf("msie") != -1)
		return "ie";
	else
		return "other";
}
function chkFm(o)
{
	if(typeof(o) == 'string')
		o = document.getElementById(o);
	if(o.name.value.match(/^\s*$/))
	{
		o.name.select();
		alert("请填写你的姓名/公司名称！");
		return false;
	}
	if(!o.tel.value.match(/^\d[\d-]{4,}\d$/))
	{
		o.tel.select();
		alert("请填写你的电话号码！");
		return false;
	}
	if(!o.msn.value.match(/^\s*$/) && !o.msn.value.match(/^\w+[\w\.]+@(\w+\.)+[a-z]{2,4}$/))
	{
		o.msn.select();
		alert("请填写正确的MSN！");
		return false;
	}
	if(!o.mobile.value.match(/^\s*$/) && !o.mobile.value.match(/^1[35]\d{9}$/))
	{
		o.mobile.select();
		alert("请填写正确的手机号码！");
		return false;
	}
	if(!o.em.value.match(/^\w+[\w\.]+@(\w+\.)+[a-z]{2,4}$/))
	{
		o.em.select();
		alert("电邮地址必须填写！");
		return false;
	}
	return true;
}
function showBack()
{
	if(window.history.length > 0)
		document.write("<div style='margin-top:10px;'><a href='javascript:history.go(-1)'>返 回</a></div>");
}
function showTxt(divId)
{
	if(gi(divId).style.display == 'none')
		gi(divId).style.display = '';
	else
		gi(divId).style.display = 'none';
}
function hideIt(Id)
{
	getId(Id).style.display = 'none';
}
function jump(u)
{
	window.open(u,"nw","");
}
function setDefault(Id,getStr)
{
	if(window.location.href.indexOf(getStr+'=') == -1){
		try{
			gi(Id).value = getStr;
		}catch(e){return false;}
		return true;
	}
	var reg = new RegExp("(&|\\?)"+getStr+"=(\\w+)","i");
	try{
		var tmp = window.location.href.match(reg);
		gi(Id).value = tmp[2];
	}catch(e){}
}
function setGetParam(formId){
	var reg = "";
	var tmp = "";
	var u = window.location.href;
	var fm = gi(formId).elements;
	for(var i=0;i<fm.length;i++){
		if(u.indexOf(fm[i].name) != -1){
			reg = new RegExp("(&|\\?)"+fm[i].name+"=([^&]+)");
			try{
				tmp = u.match(reg);
				fm[i].value = tmp[2];
			}catch(e){}
		}
	}
}
function changeCode(p,Id){
	if(typeof(Id) == 'undefined')
		Id = 'imgcode';
	var str = (Math.random()+"").substr(2,5);
	var oSrc = gi(Id).src.replace(/\?.+/i,'');
	//gi(Id).src = "../include/code.php?p="+p+"&rand="+str;
	gi(Id).src = oSrc+'?p='+p+'&rand='+str;
}
function shorten(linkName,len){
	var lnk = gn(linkName);
	for(var i=0;i<lnk.length;i++){
		if(lnk[i].innerHTML.length > len){
			lnk[i].title = lnk[i].innerHTML;
			lnk[i].innerHTML = lnk[i].innerHTML.substr(0,len) + '...';
		}
	}
}
function shortenAll(divID,tLen){
	var s = document.getElementById(divID);
	var sa = s.getElementsByTagName('a');
	for(var i=0;i<sa.length;i++){
		var txt = sa[i].innerHTML.replace(/<[^>]+/ig,'');
		if(txt.length > tLen){
			sa[i].title = txt;
			sa[i].innerHTML = txt.substr(0,tLen-1)+'...';
		}
	}
}
function chkKey(e){
	var e=e||event;
	if(e.ctrlKey){
		return false;
	}
}
function getInnerText(i){
	return gi(i).innerHTML.replace(/<[\w&%#@:,;\'\"\(\)\-\+\=\.\?\/ 	]+>/ig,'');
	//return gi(i).innerHTML.replace(/<[^>]+>/ig,'');
}
function url2link(divId){
	txt = gi(divId).innerHTML;
	gi(divId).innerHTML = gi(divId).innerHTML.replace(/(\w+@(\w+\.)+\w{2,4})/ig,"<a href='mailto:$1'>$1</a>");
	gi(divId).innerHTML = gi(divId).innerHTML.replace(/(http:\/\/[\w\.]+)/ig,"<a href='$1'>$1</a>");
}
function copyToClipboard(txt) {
     if(window.clipboardData) {
             window.clipboardData.clearData();
             window.clipboardData.setData("Text", txt);
			 return true;
     } else if(navigator.userAgent.indexOf("Opera") != -1) {
          window.location = txt;
     } else if (window.netscape) {
          try {
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
          } catch (e) {
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
          }
          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);
          var copytext = txt;
          str.data = copytext;
          trans.setTransferData("text/unicode",str,copytext.length*2);
          var clipid = Components.interfaces.nsIClipboard;
          if (!clip)
               return false;
          clip.setData(trans,null,clipid.kGlobalClipboard);
		  return true;
     }
	 return false;
}
function getId(i)
{
	return document.getElementById(i);
}
function gt(i)
{
	return document.getElementsByTagName(i);
}
function gn(i)
{
	return document.getElementsByName(i);
}
document.onkeypress = chkKey;
