var req;
function createXmlhttp(){
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		if (req.overrideMimeType){
		req.overrideMimeType("text/xml");
		}
	}
	else if(window.ActiveXObject){
		try{
		req = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
		req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if(!req){
		window.alert("Your broswer doesn't support XMLHttpRequest!");
	}
	return req;
	}
var dateSort=0;
var deptSort=0;
var positionSort=0;
var locationSort=0;
function getJobList(){
	createXmlhttp();
	req.onreadystatechange=setJobList;
	url="/qi/aiJob.nsf/2008jsongetJobList?OpenAgent&type=byDate&sort="+dateSort;
	
	req.open("GET",url,true);
	req.send(null);
	if(dateSort==0){
		dateSort=1;
	}else{
		dateSort=0;
	}
}
	
function getJobListByDept(){
	createXmlhttp();
	req.onreadystatechange=setJobList;
	url="/qi/aiJob.nsf/2008jsongetJobList?OpenAgent&type=byDept&sort="+deptSort;
	req.open("GET",url,true);
	req.send(null);
	if(deptSort==0){
		deptSort=1;
	}else{
		deptSort=0;
	}
}

function getJobListByPosition(){
	createXmlhttp();
	req.onreadystatechange=setJobList;
	url="/qi/aiJob.nsf/2008jsongetJobList?OpenAgent&type=byPosition&sort="+positionSort;
	req.open("GET",url,true);
	req.send(null);
	if(positionSort==0){
		positionSort=1;
	}else{
		positionSort=0;
	}
}

function getJobListByLocation(){
	createXmlhttp();
	req.onreadystatechange=setJobList;
	url="/qi/aiJob.nsf/2008jsongetJobList?OpenAgent&type=byLocation&sort="+locationSort;
	req.open("GET",url,true);
	req.send(null);
	if(locationSort==0){
		locationSort=1;
	}else{
		locationSort=0;
	}
}
function setJobList(){	
	if (req.readyState==4){
  	  if (req.status==200){
		jsonText = req.responseText;
//		alert (jsonText);
		var tmphml="";	
		jsonObj = eval("("+jsonText+")");
 		
// 		alert (jsonObj.totalAmount);
// 		alert(jsonObj.root.length);
		var num
		if (window.navigator.userAgent.indexOf("MSIE")>=1) 	//IE
		{num=jsonObj.root.length-1
		}else{										//FIREFOX
		num=jsonObj.root.length
		}

 		if (jsonObj.totalAmount!="0"){
		  for(var i=0;i<num;i++){
			
			var OfferDate=jsonObj.root[i].OfferDate;
			var Dept=jsonObj.root[i].Dept;	
			var Postion=jsonObj.root[i].Postion;
			var Location=jsonObj.root[i].Location;	
			var docid=jsonObj.root[i].unid;
//			alert (Location)
			if(i % 2==0){
			tmphml=tmphml+"<TR class='oddtr'><TD class='mytdthNoBorder'>" + OfferDate+ "</TD><TD>" + Dept +"</TD><TD>" + Postion + "</TD><TD>" +Location+"</TD><TD>"
//			tmphml=tmphml+"<table width=100% border=0 cellpadding=0 cellspacing=0><TR><TD style='border-left:0px;!important;'><a href=\"javascript:popupJob('" + docid+ "')\" class='blueColorThinUnderline'>Details</a></TD><TD style='border-left:0px;!important;'><img name='" + docid 
//			tmphml=tmphml+"<' width='80' height='17' type=\"image\" id='" + docid + "  onMouseDown=\"MM_swapImage('" +docid+"','','/QI/Aiweb.nsf/ApplyNowTrans_click.gif',1)\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + docid
//			tmphml=tmphml+"','','/QI/Aiweb.nsf/ApplyNowTrans_over.gif',1)\" class='inputButton' onClick=\"javascript:ApplyOne('" + docid+ "');\" src=\"/QI/Aiweb.nsf/ApplyNowTrans_normal.gif\" ></TD></TR></TABLE></TD></TR>"

			tmphml=tmphml+"<table width=100% border=0 cellpadding=0 cellspacing=0>"
			//tmphml=tmphml+"<TR><TD style='border-left:0px;!important;'><a href=\"javascript:popupJobDetail('" + docid+ "')\" class='blueColorThinUnderline'>Details</a>"
			tmphml=tmphml+"<TR><TD style='border-left:0px;!important;'><a href=\"javascript:popupJobDetailThisForm('" + docid+ "')\" class='blueColorThinUnderline'>Details</a>"
			tmphml=tmphml+"</TD><TD style='border-left:0px;!important;'><img name='" + docid 
			tmphml=tmphml+"' width='80' height='17' type=\"image\" id='" + docid 
			tmphml=tmphml+"' onMouseDown=\"MM_swapImage('" +docid+"','','/QI/Aiweb.nsf/ApplyNowTrans_click.gif',1)\" "
			tmphml=tmphml+" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + docid
			tmphml=tmphml+"','','/QI/Aiweb.nsf/ApplyNowTrans_over.gif',1)\" style=\"cursor:pointer\" onClick=\"javascript:ApplyJob('" + docid
			tmphml=tmphml+"');\" src=\"/QI/Aiweb.nsf/ApplyNowTrans_normal.gif\" ></TD></TR></TABLE></TD></TR>"
			}else{
			tmphml=tmphml+"<TR ><TD class='mytdthNoBorder'>" + OfferDate+ "</TD><TD>" + Dept +"</TD><TD>" + Postion + "</TD><TD>" +Location+"</TD><TD>"
			tmphml=tmphml+"<table width=100% border=0 cellpadding=0 cellspacing=0>"
			//tmphml=tmphml+"<TR><TD style='border-left:0px;!important;'><a href=\"javascript:popupJobDetail('" + docid+ "')\" class='blueColorThinUnderline'>Details</a>"
			tmphml=tmphml+"<TR><TD style='border-left:0px;!important;'><a href=\"javascript:popupJobDetailThisForm('" + docid+ "')\" class='blueColorThinUnderline'>Details</a>"			
			tmphml=tmphml+"</TD><TD style='border-left:0px;!important;'><img name='" + docid 
			tmphml=tmphml+"' width='80' height='17' type=\"image\" id='" + docid 
			tmphml=tmphml+"' onMouseDown=\"MM_swapImage('" +docid+"','','/QI/Aiweb.nsf/ApplyNowTrans_click.gif',1)\" "
			tmphml=tmphml+" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + docid
			tmphml=tmphml+"','','/QI/Aiweb.nsf/ApplyNowTrans_over.gif',1)\" style=\"cursor:pointer\" onClick=\"javascript:ApplyJob('" + docid
			tmphml=tmphml+"');\" src=\"/QI/Aiweb.nsf/ApplyNowTrans_normal.gif\" ></TD></TR></TABLE></TD></TR>"
			}

	 	  }		
	 	
//	 	var hml="<table border=0 cellpadding=0 cellspacing=0  id='tableRoundCnner'>";
//		hml=hml+tmphml+"</table>";	
		var hml="<table width=750 border=0 cellpadding=0 cellspacing=0 id=\"tableRoundConner\">";
		hml=hml+"<th style=\"border-left:none;cursor:pointer\" onclick=\"getJobList()\" ><center>Post Date<img src=\"/QI/AIJob.nsf/sortbg.gif\"></center></th>";
		hml=hml+"<th onclick=\"getJobListByDept()\" style=\"cursor:pointer\"><center>Department<img src=\"/QI/AIJob.nsf/sortbg.gif\"></center></th>";
		hml=hml+"<th onclick=\"getJobListByPosition()\" style=\"cursor:pointer\"><center>Position<img src=\"/QI/AIJob.nsf/sortbg.gif\"></center></th>";
		hml=hml+"<th onclick=\"getJobListByLocation()\" style=\"cursor:pointer\"><center>Location<img src=\"/QI/AIJob.nsf/sortbg.gif\"></center></th>";
		hml=hml+"<th width=150px >&nbsp</th></tr></Thead>";

		hml=hml+tmphml
		hml=hml+"</table>";
		
//		alert(hml)
		document.getElementById("selshow").innerHTML=hml;
		document.getElementById("loading").style.display="none"
		document.getElementById("spxx").innerHTML=jsonObj.totalAmount;
//		document.getElementById("xx").value=jsonObj.totalAmount;
		
		}
		
	  }
	}
}



//revised by henry to show it beautifull
//for test
function popupJobDetailThisForm(strid){
	//alert("run");
	url='/QI/AIJOB.nsf/vWebJobOfferByIds/' + strid + '?OpenDocument'
	fillContainer(url+'&height=520&width=596&KeepThis=true&TB_iframe=true&modal=true');
	//return true;

     //var url='/QI/AIJOB.nsf/vWebJobOfferByIds/' + strid + '?OpenDocument'
     //var x = parseInt(screen.width / 2.0) - (width / 2.0);  
     //var y = parseInt(screen.height / 2.0) - (height / 2.0); 
	//var myBars='directories=no,location=no,menubar=no,status=no';
	//var myOptions='scrollbars=yes,width=700,height=500,left=200,top=100,resizable=yes';
	//var myFeatures=myBars+','+myOptions;
	//window.open(url,'_Blank',myFeatures);
} 

//add by henry0123
function fillContainer(arg){
	$("#containerclick").attr("href",arg);
	$("#containerclick").click();
}
function ApplyJob(b1)
{
var lg=document.forms[0].language.value;
//alert(lg);
window.location.href="/QI/AIJob.nsf/Ag_2008ApplyOffer?OpenAgent&Language=" + lg+"&ID=" + b1;
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}