//CREATED BY PROSENJIT PRAMANICK
//File Name common_lib.php . 
//Date  31-03-08
//Reason : 
//Project : Jobsjop (PHP)
//Company Name: Navigators Software pvt ltd;

var req=null;
//var console=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;


function sendRequest(url,params,HttpMethod){
	if (!HttpMethod){
		HttpMethod="POST";
	}
	req=initXMLHTTPRequest();
	if (req){
		req.onreadystatechange=onReadyState;
		req.open(HttpMethod,url,true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(params);
	}
}
//****************************creating the XMLHTTPRequest object
function initXMLHTTPRequest(){
	//var xRequest=null;
	//if (window.XMLHttpRequest){
	//	xRequest=new XMLHttpRequest();
	//} 
	//else if (window.ActiveXObject){
	//	xRequest=new ActiveXObject("Microsoft.XMLHTTP");
	//}
	//return xRequest;
    try {
        req = new XMLHttpRequest();
    }
    catch(err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (err3) {
                req = false;
            }
        }
    }	
	//alert(req);
    return req;
}
http =initXMLHTTPRequest();
//alert(http);

//--------- PROSENJIT PRAMANICK -----------------
//function getXMLHTTPRequest() {
//    try {
//        req = new XMLHttpRequest();
//    }
//    catch(err1) {
//        try {
//            req = new ActiveXObject("Msxml2.XMLHTTP");
//        }
//        catch (err2) {
//            try {
//                req = new ActiveXObject("Microsoft.XMLHTTP");
//            }
//            catch (err3) {
//                req = false;
//            }
//        }
//    }
//    return req;
//}
//
//var http = getXMLHTTPRequest();
//---------PROSENJIT PRAMANICK -----------------

function MyHttpResponse() {
	var data=null;
	if (http.readyState==READY_STATE_COMPLETE){
		var xmlDoc = http.responseText;
		//alert(xmlDoc);		
		var found1 = http.responseXML.getElementsByTagName("record_found")[0].childNodes[0].nodeValue;
		if(found1 == 1){
			//document.getElementById("page_action").value='update_record';
			try{
				var div_id = http.responseXML.getElementsByTagName("div_id")[0].childNodes[0].nodeValue;				
				var response_text = http.responseXML.getElementsByTagName("response_text")[0].childNodes[0].nodeValue;				
				if(response_text != '__NULL__'){
					document.getElementById(div_id).innerHTML=response_text;
				}
				else{
					document.getElementById(div_id).innerHTML="";
				}
			}
			catch(e){
				//alert(e.description);
			}
		}
	}
}

function MyHttpResponse_text() {
	var data=null;
	if (http.readyState==READY_STATE_COMPLETE){
		var xmlDoc = http.responseText; 
		//alert(xmlDoc);		
		//alert('dddd');
		var pos=xmlDoc.indexOf('^');
		var len=xmlDoc.length;		
		var content=trim(xmlDoc.substring(0,pos));
		var text=xmlDoc.substring(pos+1,len);		
		//alert(content);
		//alert(text);
		var divID=trim(text);
		//document.getElementById(divID).innerHTML = content; 
		//-------------------------------------------------------
		//var pos2=text.indexOf('^');
		//var n2=text.substring(0,pos2);
		//var topic=text.substring(pos2+1,text.length);
		//var num=parseInt(topic);
		//var pos3=topic.indexOf('^');
		//var n3=topic.substring(0,pos3);
		//var topic1=topic.substring(pos3+1,topic.length);
		//var num1=parseInt(topic1);
		//-------------------------------------------------------
		if(divID)
		{		
			if(divID == 'showLogo_div')
			{
				var bname = navigator.appName;
				if (bname != "Microsoft Internet Explorer")
				{
				   opacityTween = new OpacityTween(document.getElementById('showLogo_div'),Tween.bounceEaseOut, 30, 100, 3);
				   opacityTween.start();
				}

			}
			if(divID == 'ajax_comp_name_id')
			{
				var split_content=content.split("||||");
				document.getElementById("ajax_comp_name_id").innerHTML = split_content[0];
				document.getElementById("ajax_comp_addr_id").innerHTML = split_content[1];
				document.getElementById("ajax_comp_location_id").innerHTML = split_content[2];
				document.getElementById("ajax_comp_sector_id").innerHTML = split_content[3];
				document.getElementById("ajax_comp_desc_id").innerHTML = split_content[4];
			}
			else
			{
				document.getElementById(divID).innerHTML = content;
			}
			
			if(divID == 'error_delloc')
			{
					check_location_del_eror();
			}
			if(divID == 'wid_prev_other')
			{
					other_wid_prev();
			}
			if(divID == 'matching_record_count_div')
			{						
					IndustryCategoryId();
			}
			
			
			
			//document.getElementById(divID).innerHTML = 'ghcgdgcdgcdg'; 
			//document.getElementById(divID).focus();
		}
		
		//------------- SPECIAL CASES ------------------------------
		if(text == 'disp_group_members_div'){
			document.getElementById('group_list').style.display = 'none';			
			document.getElementById('save_continue_button_div').style.display = 'none';			
			document.getElementById('back_to_group_list_div').style.display = '';	
			document.getElementById('disp_group_members_div').style.display = '';	
		}
		if(text == 'ddfrom_jobsjop_div'){
            // JOBSEEKER DELETE ALL DATA FROM JOBSJOP
			document.location.href='index.php';
		}
		if(text == 'hide_delete_resume_div'){
            change_msg_status2('');
		}
        
        
		//..........SPECIAL CASE FOR ADD Favourite......................
		/*if(div_id == 'add_fav'){
			document.getElementById('status_favourite').style.display = 'block';
			
		}*/
		
	}
}
//function zone1(){
//  var zone_id=document.manageadmin.State.value;
//  if(zone_id!="0"){
//  	sendRequest("ajax/state_ajax_search.php","topic=zone&str="+zone_id,"POST");
//  }
//}

function make_request(div_id,function_name,function_params){
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = "ajax/ajax_response.php?rand="+myRand+"&div_id="+div_id+"&function_name="+function_name+function_params;
	//alert(modurl);
	document.getElementById(div_id).innerHtml = 'Please wait ......';
	http.open("GET", modurl, true);
	http.onreadystatechange = MyHttpResponse;
	http.send(null);
}
function make_request_text(div_id,function_name,function_params){
	//alert(function_name);
	//alert(function_params);
	//alert(div_id);
	//alert(function_name);
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = "ajax/ajax_response.php?rand="+myRand+"&div_id="+div_id+"&function_name="+function_name+function_params;
	//alert(modurl);
	document.getElementById(div_id).innerHtml = 'Please wait ......';
	http.open("GET", modurl, true);
	http.onreadystatechange = MyHttpResponse_text;
	http.send(null);
}
function make_request_text_search(div_id,function_name,function_params){
	//alert(function_name);
	//alert(function_params);
	//alert(div_id);
	//alert(function_name);
	document.getElementById('search_result_div').innerHTML = '<img src="images/loading.gif" alt="loading" width="47" height="39" />';
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = "ajax/ajax_response.php?rand="+myRand+"&div_id="+div_id+"&function_name="+function_name+function_params;
	//alert(modurl);
	document.getElementById(div_id).innerHtml = 'Please wait ......';
	http.open("GET", modurl, true);
	http.onreadystatechange = MyHttpResponse_text;
	http.send(null);
}

function make_request2(div_id,function_name,function_params){
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = "ajax/ajax_response2.php?rand="+myRand+"&div_id="+div_id+"&function_name="+function_name+function_params;
	document.getElementById(div_id).innerHtml = 'Please wait ......';
	http.open("GET", modurl, true);
	http.onreadystatechange = MyHttpResponse;
	http.send(null);
}
function make_request_text2(div_id,function_name,function_params){
	//alert(function_params);
	//alert(div_id);
	//alert(function_name);
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = "ajax/ajax_response2.php?rand="+myRand+"&div_id="+div_id+"&function_name="+function_name+function_params;		
	//alert(modurl);
	document.getElementById(div_id).innerHtml = 'Please wait ......';
	http.open("GET", modurl, true);	
	http.onreadystatechange = MyHttpResponse_text;	
	http.send(null);
}


///.........this  is  trim .......
function ltrim(str) { 
for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
return str.substring(k, str.length);
}
function rtrim(str) {
for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
return str.substring(0,j+1);
}
function trim(str) 
{
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) { 
var whitespaceChars = " \t\n\r\f";
return (whitespaceChars.indexOf(charToCheck) != -1);
}




