﻿var BROWSER = {};
var BROWSER_TYPE="";
var USERAGENT = navigator.userAgent.toLowerCase();
browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','mozilla':'','webkit':'','maxthon':'','qq':'qqbrowser'});
function browserVersion(types) {
	var other = 1;
	for(i in types) {	    
		var v = types[i] ? types[i] : i;		
		if(USERAGENT.indexOf(v) != -1) {		
			var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
			var matches = re.exec(USERAGENT);
			var ver = matches != null ? matches[2] : 0;
			
			other = ver !== 0 && v != 'mozilla' ? 0 : other;
			
		}else {
			var ver = 0;
		}
		eval('BROWSER.' + i + '= ver');
	}
	BROWSER.other = other;
}

//添加到收藏夹   
	function AddToFavorite()   
	{   
		if (document.all){   		    
		   window.external.addFavorite(parent.document.URL,parent.document.title);   
		}else if (window.sidebar){   
		   window.sidebar.addPanel(parent.document.title, parent.document.URL, "");   
		}   
	}   
  
	//设为首页   
	function setHomepage(){   
		if (document.all){   
		    document.body.style.behavior='url(#default#homepage)';   
		    document.body.setHomePage(parent.document.URL);   
	  }else if (window.sidebar){   
			if(window.netscape){   
		   try{    
			  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
		   }catch (e){    
						alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );    
		   }   
			}    
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);   
		prefs.setCharPref('browser.startup.homepage',parent.document.URL);   
		}   
	} 



var request = new Object();  
request = GetRequest(); 

//获得url的参数
function GetRequest() {
   var url = location.search; //获取url中"?"符后的字串
   var theRequest = new Object();
   if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
   }
   return theRequest;
}
//获得通过id对象
function $id(id) {
	return !id ? null : document.getElementById(id);
}
//是否已经定义变量
function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}
//提交方式
function ctrlEnter(event, btnId, onlyEnter) {
	if(isUndefined(onlyEnter)) onlyEnter = 0;	
	if((event.ctrlKey || onlyEnter) && event.keyCode == 13) {	    
		$id(btnId).click();
		return false;
	}
	return true;
}
//展示加载
function showloading(display, waiting) {
	var display = display ? display : 'block';
	var waiting = waiting ? waiting : '请稍候...';
	$id('ajaxwaitid').innerHTML = waiting;
	$id('ajaxwaitid').style.display = display;
}

function _attachEvent(obj, evt, func, eventobj) {

	eventobj = !eventobj ? obj : eventobj;
	if(obj.addEventListener) {
		obj.addEventListener(evt, func, false);
	} else if(eventobj.attachEvent) {
		obj.attachEvent('on' + evt, func);
	}
}

function _detachEvent(obj, evt, func, eventobj) {
	eventobj = !eventobj ? obj : eventobj;
	if(obj.removeEventListener) {
		obj.removeEventListener(evt, func, false);
	} else if(eventobj.detachEvent) {
		obj.detachEvent('on' + evt, func);
	}
}
function showTopLink() {
	if($id('ft')){
		var viewPortHeight = parseInt(document.documentElement.clientHeight);
		var scrollHeight = parseInt(document.body.getBoundingClientRect().top);

		var basew = parseInt($id('ft').clientWidth);
		var sw = $id('scrolltop').clientWidth;

		if (basew < 1000) {
		
			var left = parseInt(fetchOffset($id('ft'))['left']);			
			left = left < sw ? left * 2 - sw : left;
			$id('scrolltop').style.left = ( basew + left ) + 'px';
			$id('scrolltop').style.top='500px';
		} else {
			$id('scrolltop').style.left = 'auto';
			$id('scrolltop').style.right = 0;
		}

		if (BROWSER.ie && BROWSER.ie < 7) {		
			$id('scrolltop').style.top = viewPortHeight - scrollHeight - 150 + 'px';
		}

		if (scrollHeight < -100) {
			$id('scrolltop').style.visibility = 'visible';
		} else {	
			$id('scrolltop').style.visibility = 'hidden';
		}
	}
}

//我的收藏 收藏到数据库
function favAdd() {
    
}
