//添加到收藏夹
function AddFavorite(sURL, sTitle)
{
    try{
        window.external.addFavorite(sURL, sTitle);
    }catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }catch (e){
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
//设为首页
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("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',vrl);
        }
    }
}
//隐藏所有JS错误提示
function killErrors() {
    return true;
}
window.onerror = killErrors;
function encodeURIComponentnew(v){
	try{
		v = v.replace(/\//g, "=");
		s = encodeURIComponent(v);
	}catch (e){
		s='';
	}
	return s;
}
function searchjob(){
  var formaction="/index.php/search-job";
  var joffice = encodeURIComponentnew($("#joffice").val());
  var office = encodeURIComponentnew($("#office").val());
  var zwname = encodeURIComponentnew($("#zwname").val());
  var qyname = encodeURIComponentnew($("#qyname").val());
  
  var address = encodeURIComponentnew($("#address").val());
  var edu = encodeURIComponentnew($("#edu").val());
  var money = encodeURIComponentnew($("#money").val());
			
  if((joffice!='') && (joffice!=null)){
	formaction+='-joffice-'+joffice;
  }
  if((office!='') && (office!=null)){
	formaction+='-office-'+office;
  }
  if((zwname!='') && (zwname!=null)){
	formaction+='-zwname-'+zwname;
  }
  if((qyname!='') && (qyname!=null)){
	formaction+='-qyname-'+qyname;
  }
  if((address!='') && (address!=null) && (address!='undefined')){
	formaction+='-address-'+address;
  }
  if((edu!='') && (edu!=null) && (edu!='undefined')){
	formaction+='-edu-'+edu;
  }
  if((money!='') && (money!=null) && (money!='undefined')){
	formaction+='-money-'+money.replace('-',',');
  }
  $("#searchjob").attr("action",formaction);
}

function searchpeople(){
  var formaction="/index.php/search-people";
  var office = encodeURIComponentnew($("#rcoffice").val());
  var joffice = encodeURIComponentnew($("#rcjoffice").val());
  var edu = encodeURIComponentnew($("#edu").val());
  var workexp = encodeURIComponentnew($("#workexp").val());
  var jobclass = encodeURIComponentnew($("#jobclass").val());
  var zsname = encodeURIComponentnew($("#zsname").val());
  var subject = encodeURIComponentnew($("#subject").val());
  var jsubject = encodeURIComponentnew($("#jsubject").val());
  if((office!='') && (office!=null)){
	formaction+='-office-'+office;
  }
  if((joffice!='') && (joffice!=null)){
	formaction+='-joffice-'+joffice;
  }
  if((edu!='') && (edu!=null)){
	formaction+='-edu-'+edu;
  }
  if((workexp!='') && (workexp!=null)){
	formaction+='-workexp-'+workexp;
  }
  if((jobclass!='') && (jobclass!=null)){
	formaction+='-jobclass-'+jobclass;
  }
  if((zsname!='') && (zsname!=null)){
	formaction+='-zsname-'+zsname;
  }
  if((subject!='') && (subject!=null) && (subject!='undefined')){
	formaction+='-subject-'+subject;
  }
  if((jsubject!='') && (jsubject!=null) && (jsubject!='undefined')){
	formaction+='-jsubject-'+jsubject;
  }
  $("#searchpeople").attr("action",formaction);
}

function searchwm(){
  var formaction="/index.php/WM";
  var posts = encodeURIComponent($("#posts").val());
  
  if((posts!='') && (posts!=null)){
	formaction+='-posts-'+posts;
  }
  $("#searchwm").attr("action",formaction);
}

function CheckAll(strSection,checkedval){
	var i;
	var	colInputs = document.getElementById(strSection).getElementsByTagName("input");
	for	(i=0; i < colInputs.length; i++)
	{
		colInputs[i].checked=checkedval;
	}
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

var ajaxflag=0;
$(document).ready();
function invite(){
var height=250;
var width=540;
$.ajax({ //一个Ajax过程    
    type: "post",  //以get方式与后台沟通   
    url : "/index.php/People-postinvite", //与此php页面沟通   
    dataType:'html',//从php返回的值以 JSON方式 解释
    data:$("#postinvitego").serialize(),
    success: function(json){
    	var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var layerheight=(arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2) + 'px');
		var layerwidth=(((arrayPageSize[0] - 25 - width) / 2) + 'px');
		$('#indexlayer').css('top',layerheight);
		$('#indexlayer').css('left',layerwidth);
    	$("#indexlayer").html('<div class="index_closd"><a href="javascript:" onclick="closedWindow();">关闭</a></div>'+json);
    	$("#indexlayer").removeClass('indexlayer');
    }
    });
}

function closedWindow(){
	$("#indexlayer").attr('class','indexlayer');
}

// 设置cookie
function setCookie(cName,cValue,cTime){
	var expire=new Date();
	if(cTime<=0){
		cTime=3600; //默认一个小时
	}
	expire.setTime(expire.getTime() + cTime*1000);
	document.cookie = cName + "=" + cValue + "; expires = " + expire.toGMTString(); 
}

// 读取cookie
function getCookie( name ){
   var val = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
   return  val == null ? false : val[2];
}

/**
 * 定义ForceWindow类构造函数
 * 无参数
 * 无返回值
 */
function ForceWindow ()
{
  this.r = document.documentElement;
  this.f = document.createElement("FORM");
  this.f.target = "_blank";
  this.f.method = "post";
  this.r.insertBefore(this.f, this.r.childNodes[0]);
}

/**
 * 定义open方法
 * 参数sUrl：字符串，要打开窗口的URL。
 * 无返回值
 */
ForceWindow.prototype.open = function (sUrl)
{
  this.f.action = sUrl;
  this.f.submit();
}

 //var myWindow = new ForceWindow(); 
 //myWindow.open("http://bbs.0594.com");
