var manchu_activetab='tab1'; 
var manchu_childNum = 5;


function DomReady(ftn) {
	var timeout = 0;
	var setInt = setInterval(function() 
	{
		timeout++;
		var html = document.getElementsByTagName("HTML")[0];
		html = html.innerHTML.toLowerCase();
		if(html.lastIndexOf("</body>")> 0) {
			ftn();
			clearInterval(setInt);
		}
		if(timeout> 150) {
			clearInterval(setInt);
		}
	}, 100);
}
//start the watcher
DomReady(ManchuAjaxTabInit);


//initially tab1 is active by default


//Initializing ManchuAjaxTabInit
function ManchuAjaxTabInit()
{
	try
	{			
		//document.getElementById(tabid).className = 'mactivetab';
		objFather = document.getElementById('manchu_tabul'); //get the father  ul' ID
		if(objFather)
		{
			arrayChildren = objFather.childNodes; //geting array of children
			manchu_childNum = arrayChildren.length; //getting the number of child , here 'li'  element for navigation
		}
		ManchutabController('tab1');
				
	}catch(err)
	{
		//start the watcher
		DomReady(ManchuAjaxTabInit);	
		//alert('Something went wrong... ( '+err.description+' )'); //yaak there is error
	}
}


function InitXMLRequest(reqType)
{	
	var ajaxRequest = false;		
	try
	{
		ajaxRequest= new XMLHttpRequest();
		if (ajaxRequest.overrideMimeType)
		{
			if (reqType == "XML")
			{
				ajaxRequest.overrideMimeType('text/xml');
			} else 
			{
				ajaxRequest.overrideMimeType('text/html');
			}
		}
	
	}
	catch(err1)
	{
		try{ajaxRequest= new ActiveXObject("Msxml2.XMLHTTP");}
		catch(err2)
		{
			try{ajaxRequest= new ActiveXObject("Microsoft.XMLHTTP");}			
			catch(err3){ajaxrRquest = false;}
		}
	}//end request test
	if (!ajaxRequest)
	{
		//Firebug debug
		//console.log("XMLHttpRequest initialization failed at last :(");		
		
	}
	else
	{
		//Firebug debug
		//console.log("XMLHttpRequest initialized successfully...");		
		return 	ajaxRequest;
	}
}
function ManchutabController(tabid)
{		
	manchu_activetab=tabid;
	ChangeClassName(tabid);
	SendAjaxRequest(manchu_ajaxUrl, "tabid="+tabid, "POST","HTML");
}

function ChangeClassName(tabid)	
{			
		for(i=0; i < manchu_childNum; i++) //now explore them do play
		{		
			if(arrayChildren[i].id == undefined) continue;			
			if(arrayChildren[i].id == tabid  )
			{arrayChildren[i].className = 'manchu_activetab';}
			else{arrayChildren[i].className ='manchu_normaltab';}			
		}		
}


function SendAjaxRequest(url, params, method, reqType)
{
	if ( reqType== "")
	{
		reqType = "HTML";
	}
	ajaxRequest = InitXMLRequest(reqType);
	ajaxRequest.onreadystatechange = GetAjaxResponse;
	
	//Kill the Cache problem in IE.
	params ="?"+params;
	var now = "&upid=" + new Date().getTime();	
	params += now;

	if( method == "POST")
	{
		ajaxRequest.open("POST", url + params, true);		 
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", params.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		
	    ajaxRequest.send(params);
		//Firebug debug
		//console.log("Using post method params sent= %s ", params);
	}
	else //method  = "GET"
	{
		ajaxRequest.open('GET', url + params, true);
		ajaxRequest.send(null);		
		//Firebug debug
		//console.log("Using get method params sent= %s ", params);
	}
	//document.getElementById('mtabdata').innerHTML="<span >Please wait...</span>"; 
	document.getElementById('manchu_mtabdata').innerHTML="<span  style=\"font-size:15px; font-family: Verdana, Helvetica, Arial, sans-serif;\">Please wait...<img src=\""+manchu_loadimage.src+"\" alt=\"loading\"/></span>"; 

}
function GetAjaxResponse() {
	
  if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
    var response = ajaxRequest.responseText;
	
	 
    document.getElementById('manchu_mtabdata').innerHTML=response;
	 
	
  }  
}
