//added on 08092011 for SUCESS STORIES
function hideme(id) 
{
	document.getElementById(id).style.height='1px';
	document.getElementById(id).style.visibility='hidden';
}
function killme(id)
{
	document.getElementById(id).innerHTML='';	
}
function category_click(id)
{
	var category = new Array("agriculture","horticulture","food_processing","dairy","fishries","animal_husbandry");
	var len = category.length;
	for (var i=0;i<len;i++)
	{
		if(id==category[i])
		{
			document.getElementById(category[i]).style.visibility='visible';
			document.getElementById(category[i]).style.height='auto';
			continue;
		}	
		
		
		
	}
	
}
//function countChildElements(parent, child)
//     {
//          var parent = document.getElementById(parent);
//          var childCount = parent.getElementsByTagName(child).length;
//          alert(childCount);
//		  var child1 = parent.getElementsByTagName(child);
//		  alert(child1[0].style.visibility);
//    }
function subcategory_click(subid)
{
	document.getElementById(subid).style.visibility='visible';
	document.getElementById(subid).style.height='auto';
}
function loadpdf2(url,id,width,height)
{

	//var url_out = encodeURI(url);//component='+escape(encodeURI(component))+'&majoractivity='+escape(encodeURI(majoractivity));;
	document.getElementById('show_agri').innerHTML='';
	document.getElementById('show_horti').innerHTML='';
	document.getElementById('show_fp').innerHTML='';
	document.getElementById('show_dairy').innerHTML='';
	document.getElementById('show_fish').innerHTML='';
	document.getElementById('show_animal').innerHTML='';
	
	
	document.getElementById(id).innerHTML = "<div style='margin-top:10px;background-color:#CCC;padding:5px'><a href='"+url+"'><span style='font-size:14px;'>Click Here to Download</span></a><span style='float:right'><a href='javascript:killme(\""+id+"\");'>Close</a></span></div><iframe src='http://docs.google.com/viewer?url="+url+"&embedded=true' width='"+width+"' height='"+height+"'></iframe>";
}
//--------END FOR SUCESS STORIES ADDITION
//before 08/09/2011

// JavaScript Document
var loading = new Image();
		loading.src = '../images/loading.gif';

function hidediv (id)
{
	document.getElementById(id).style.visibility='hidden';
	//document.getElementById('body_main').style.visibility='visible';
}
function showdiv (id)
{
	//document.getElementById('body_main').style.visibility='hidden';
	document.getElementById(id).style.visibility='visible';
}



// creates an XMLHttpRequest instance=====================================================
function createXmlHttpRequestObject()  
{ 
  // will store the reference to the XMLHttpRequest object 
  var xmlHttp; 
  // this should work for all browsers except IE6 and older 
  try 
  { 
    // try to create XMLHttpRequest object 
    xmlHttp = new XMLHttpRequest(); 
  } 
  catch(e) 
  { 
    // assume IE6 or older 
    var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 
                                    'MSXML2.XMLHTTP.5.0', 
                                    'MSXML2.XMLHTTP.4.0', 
                                    'MSXML2.XMLHTTP.3.0', 
                                    'MSXML2.XMLHTTP', 
                                    'Microsoft.XMLHTTP'); 
    // try every prog id until one works 
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    { 
      try  
      {  
        // try to create XMLHttpRequest object 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]); 
      }  
      catch (e) {} // ignore potential error 
    } 
  } 
  // return the created object or display an error message 
  if (!xmlHttp) 
    alert("Error creating the XMLHttpRequest object."); 
  else  
    return xmlHttp; 
} 

var http = createXmlHttpRequestObject();
//===================================================================================================



//loadPage===========================================================================================


var nocache = 0;

function loadpage(catid,subcatid,subsubcatid)
{
	showdiv('loading');
	if (http)
	{
		
		try
		{
        	nocache = Math.random();
			var poststr = "catid="+ escape(encodeURI(catid)) +"&subcatid=" + escape(encodeURI(subcatid)) +"&subsubcatid=" +escape(encodeURI(subsubcatid))+  "&nocache=" +escape(encodeURI(nocache));
			 var url = "../server/loadpage.php?";

             http.open('post', url, true);
			 http.onreadystatechange = loadpageReply;
			 http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	      	 http.setRequestHeader("Content-length", poststr.length);
    	  	 http.setRequestHeader("Connection", "close");
        	 http.send(poststr);
		}
		catch (e)
		{
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

function loadpageReply()
{
	//wait(1000);
         if(http.readyState == 4)
         {
			 hidediv ('loading');
			 if (http.status==200)
			 {
				 try
				 {
					var response = http.responseText;
					document.getElementById('body_main').innerHTML = response;
				 }
				 catch (e)
				 {
					 alert ("ERROR receiving Responce :\n "+e.toString());
				 }
			 }
			 else
			 {
				 alert("There was a problem retrieving the data:\n" +xmlHttp.statusText); 
			 }
         }
}
//=======================================================================================================
