var loadedobjects="";
var rootdomain="http://"+window.location.hostname

var step_count=0;
var prev_news='';
var	prev_job_id='';

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function show_status(success, message){
		var status_div=document.getElementById('status_mgs');
	var img_path="images/";
	var status_str='';
	var col='';
		
		switch (success){
		case 0:			//FAILED
				col = "#FF0000";
				img_path = img_path+"error.gif";		
				break;
		case 1:			//SUCCESS
				col = "#056b00";		
				img_path = img_path+"validated.gif";						
				break;
		case 2:			//MESSAGE
				col = "#680000";		
 				img_path = img_path+"invalid.gif";		
				break;
		case 3:			//required
				col = "#0026e5";		
 				img_path = img_path+"required.gif";		
				break;
		case 4:			//PROCESS
				col = "006d7a";		
 				img_path = img_path+"loading.gif";		
				break;

		default:	//CLEAN
			document.getElementById('status_mgs').style.display='none';
			document.getElementById('sp_status').innerHTML='';
			return;
	}
		
		status_div.style.display='';
		status_div.style.top=iecompattest().scrollTop+'px';
		var width=screen.width;
		status_div.style.left = (width - status_div.offsetWidth)/2;
		document.getElementById('stat_img').src = img_path;
		document.getElementById('sp_status').innerHTML='<span style="color:'+col+'">'+message+'</span>';
		if(success!=4)
			setTimeout("document.getElementById('status_mgs').style.display='none'",5000);
		
}

function get_plain_value(full_txt){
	if(full_txt=='')
		return '';
		
	full_txt=escape(full_txt);
	return full_txt.replace(RegExp("[+]","g"),'^p^');
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function general_query(){
	qstring='more';
}
function load_content(url,target,flag){		//flag=true need to load a js
	if(url==''||!url)
		return;
	//alert(url);
	
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		//alert(url);
		show_status(4,"loading data ...");
		
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{		
				//alert(xmlHttp.responseText);
				document.getElementById(target).innerHTML = xmlHttp.responseText;
				
				if(flag){
					var arr = url.split(".");
						//alert(arr[0]);
							loadobjs(arr[0]+"_java.js",arr[0]+"_setup");
						}
			show_status();
			}
		}
		//alert(url);

		xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}
}

function no_action(){		//default no ection function

}

function loadobjs(){
	
	if (!document.getElementById)
		return;
	for (i=0; i<arguments.length-1; i++){
		var file=arguments[i];
		var fileref="";
		if(loadedobjects.indexOf(file) !=-1){
//			alert("already loaded");		
			eval(arguments[arguments.length-1])();
		}
		else if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
			
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref);
			loadedobjects+=file+" "; //Remember this object as being already added to page
//			alert("executing new function");
			//alert(loadedobjects);
		}
		}
}

function show_jobdetails(anchorobj,job_id){
	
	
	var subobj=document.getElementById('news_view');
	
	var ref_div=document.getElementById('ref_div');
	var left_offset=getposOffset(ref_div, "offsetLeft");	//POSIION THE IMAGE DIV CENTER OF CONTENT DIV
	//var left_offset=0;
	var top_offset=iecompattest().scrollTop+125;
	if(prev_job_id==job_id&& subobj.innerHTML!=''){
	    show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
	}
	else
	{
			prev_job_id=job_id;
			var xmlHttp="";
				try
				{
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)
					{
					  alert ("Your browser does not support AJAX!");
					  return;
					}
					//loadobjs('search_java.js');
					var url="job_details.php?id="+job_id;
										show_status(4,"loading data ...");
					xmlHttp.onreadystatechange=function() 
					{ 
						if (xmlHttp.readyState==4)
							{
								if(xmlHttp.status!=200){
									//alert("Error no = "+ xmlHttp.status);
									show_status(0,'error in communication, error no = '+ xmlHttp.status);
									return;
									}
									
							var subobj=document.getElementById('news_view');
							subobj.innerHTML = xmlHttp.responseText;
							show_status();
							show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
						}
					}
					xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
					xmlHttp.send(null);
				}
				catch(exception)
				{
					alert(exception);
				}		
		}
}


function show_anidiv(anchorobj, url,flag){
	
	
	var subobj=document.getElementById('ani_view');
	
	var ref_div=document.getElementById('ref_div');
	var left_offset=getposOffset(ref_div, "offsetLeft");	//POSIION THE IMAGE DIV CENTER OF CONTENT DIV
	//var left_offset=0;
	var top_offset=iecompattest().scrollTop+0;

//	if(prev_job_id==job_id&& subobj.innerHTML!=''){
	//    show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
	//}
//	else
	{
		//	prev_job_id=job_id;
			var xmlHttp="";
				try
				{
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)
					{
					  alert ("Your browser does not support AJAX!");
					  return;
					}
					//loadobjs('search_java.js');
				//	var url="job_details.php?id="+job_id;
					var url=url;
										show_status(4,"loading data ...");
					xmlHttp.onreadystatechange=function() 
					{ 
						if (xmlHttp.readyState==4)
							{
								if(xmlHttp.status!=200){
									//alert("Error no = "+ xmlHttp.status);
									show_status(0,'error in communication, error no = '+ xmlHttp.status);
									return;
									}
									
							var subobj=document.getElementById('ani_view');
							subobj.innerHTML = xmlHttp.responseText;
							
							
								if(flag){
								var arr = url.split(".");
						//alert(arr[0]);
								loadobjs(arr[0]+"_java.js",no_action);
								}
							show_status();
							show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
						}
					}
					xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
					xmlHttp.send(null);
				}
				catch(exception)
				{
					alert(exception);
				}		
		}
}







// For Displaying News in the Drop Down Display area
function show_news(anchorobj,news_id){
	
	
	var subobj=document.getElementById('news_view');
	
	var ref_div=document.getElementById('ref_div');
	var left_offset=getposOffset(ref_div, "offsetLeft");	//POSIION THE IMAGE DIV CENTER OF CONTENT DIV
	//var left_offset=0;
	var top_offset=iecompattest().scrollTop+125;
	if(prev_news==news_id && subobj.innerHTML!=''){
	    show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
	}
	else
	{
			prev_news=news_id;
			var xmlHttp="";
				try
				{
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)
					{
					  alert ("Your browser does not support AJAX!");
					  return;
					}
					//loadobjs('search_java.js');
					var url="show_news.php?id="+news_id;
										show_status(4,"loading data ...");
					xmlHttp.onreadystatechange=function() 
					{ 
						if (xmlHttp.readyState==4)
							{
								if(xmlHttp.status!=200){
									//alert("Error no = "+ xmlHttp.status);
									show_status(0,'error in communication, error no = '+ xmlHttp.status);
									return;
									}
									
							var subobj=document.getElementById('news_view');
							subobj.innerHTML = xmlHttp.responseText;
							show_status();
							show_div(anchorobj,subobj,'down',500,left_offset,top_offset);
						}
					}
					xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
					xmlHttp.send(null);
				}
				catch(exception)
				{
					alert(exception);
				}		
		}
}
loadobjs("ani_div.js",no_action);
