var xmlhttp=false
var xmlhttp2=false
var response=""

//------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------

function ShowResultsBypage(CategoryID,paging,CategoryName,speciesID,thetable,Searchtext,thesource)
{ 
var Searchtext=document.getElementById('SearchString').value

 nocache = Math.random()
    xmlhttp2.onreadystatechange=function(){	
  if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
    {
	var response =xmlhttp2.responseText.split("|")
	
	//request.responseText.split("|");	
  document.getElementById("resultsbar").innerHTML=response[0]
    document.getElementById("lower_resultsbar").innerHTML=response[0]
   document.getElementById("maincontent").innerHTML=response[1]
    }
  }	 
//alert ("bypage_IE.php?CategoryID="+CategoryID+'&paging='+paging+'&CategoryName='+CategoryName+'&nocache='+nocache+'&speciesID='+speciesID+'&targeTable='+thetable+'&Searchtext='+Searchtext+'&thesource='+thesource)
  xmlhttp2.open("GET","process.php?CategoryID="+CategoryID+'&paging='+paging+'&CategoryName='+CategoryName+'&nocache='+nocache+'&speciesID='+speciesID+'&targeTable='+thetable+'&Searchtext='+Searchtext+'&thesource='+thesource, true); 
 xmlhttp2.send(null);
}
//----------------------------------------------------------------------------------------------------------------------


















function GetXMLHttpRequest()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
   xmlhttp2=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return xmlhttp
    return xmlhttp2}




function UseResponseText(){

	
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("results").innerHTML=xmlhttp.responseText;
    }
  }	
	
	
	
	
	
	function showNavigation(){
	
  if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
    {
    document.getElementById("navbar").innerHTML=xmlhttp2.responseText;
    }
  }	
	
	
	
	
	
	
	
	
	
	
	
GetXMLHttpRequest()


/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function login() {

// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var username=document.getElementById('usrname')
var thepassword=document.getElementById('passwd')
if(username.value=="") {document.getElementById('login_response').innerHTML="Enter username...";username.focus();exit;}
if(thepassword.value=="") {document.getElementById('login_response').innerHTML="Enter password...";thepassword.focus();exit;}






var username = encodeURI(username.value);
var password = encodeURI(thepassword.value);

// Set te random number to add to URL request
nocache = Math.random();

// Pass the login variables like URL variable
xmlhttp.open("GET", 'processLogin.php?username='+username+'&password='+password, true);
xmlhttp.onreadystatechange = function () {	
if(xmlhttp.readyState == 4  && xmlhttp.status==200){
	response =xmlhttp.responseText;
theindex=response.indexOf("Invalid credentials")
	if (theindex>=0){ document.getElementById('login_response').innerHTML = response}
 else{ document.getElementById('LoginOut').innerHTML = response}
}
}
loginReply;
xmlhttp.send(null);
}














function Open_Data_Entry_Form(thetable) {
// Set te random number to add to URL request
nocache = Math.random()
// Pass the login variables like URL variable
xmlhttp.open('get', 'formgen.php?thetable='+thetable+'&nocache = '+nocache);

xmlhttp.onreadystatechange = Data_Entry_Reply;
xmlhttp.send(null);
}


function Data_Entry_Reply() {
if(xmlhttp.readyState == 4){
response =xmlhttp.responseText;
 document.getElementById('test').innerHTML = ""
document.getElementById('dataform').innerHTML = ""

document.getElementById('dataform').innerHTML = response

}

}



function displayFormValues(theform)

{
	var elem = document.getElementById('dataform').elements;	
	for(var i = 0; i < elem.length-1; i++)
{
	thecontrol=elem[i]	
	if(thecontrol.id =='countryID'  && thecontrol.selectedIndex =="0")
  {document.getElementById('report').innerHTML = '<b>'+thecontrol.name +'</b>  required';
	exit
	}	
		
	if(thecontrol.className =='required' && thecontrol.value =="")
	{document.getElementById('report').innerHTML = '<b>'+thecontrol.name +'</b>  required';
	thecontrol.focus
	exit
	}
	
	}
	
	
	
	parampassed=""
var str=""


for(var i = 0; i < elem.length-1; i++)
{	
	if( elem[i].type !=undefined || elem[i].name !=undefined || elem[i].value !=undefined )
	{
		
	var fieldvalue= elem[i].value;
	
    var parampassed=elem[i].name+'='+fieldvalue
   if (str=="")
   {	  
   str=parampassed
	   }
	   else
	   {	
	   str += '&'+parampassed
	   }
	}
} 

xmlhttp.open('get', 'Process_User_input.php?'+str);
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4){
	response =xmlhttp.responseText;
document.getElementById('report').innerHTML = response
}
}
xmlhttp.send(null);
}







function ProcessProducInfo() {
document.getElementById('upload_report').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.

var ProductName = encodeURI(document.getElementById('ProductName').value);

var CategoryID = encodeURI(document.getElementById('CategoryID').value);

var Productdescription = encodeURI(document.getElementById('ProductDescription').value);

var keywords = encodeURI(document.getElementById('keywords').value);

var source = encodeURI(document.getElementById('source').value);

var sourceUrl = encodeURI(document.getElementById('sourceurl').value);
nocache = Math.random();
// Pass the login variables like URL variable
xmlhttp.open("GET", 'AddproductInfo.php?ProductName='+ProductName+'&categoryID='+CategoryID+'&ProductDescription='+Productdescription+'&keywords='+keywords+'&source='+source+'&sourceUrl='+sourceUrl+'&MAX_FILE_SIZE=1000000');
xmlhttp.onreadystatechange = ProductReply;
xmlhttp.send(null);
}
function ProductReply() {
if(xmlhttp.readyState == 4){
	
response =xmlhttp.responseText;

document.getElementById('upload_report').innerHTML = '<br>'+response
}

}











////=--------------------------------


function saveEdits()
{
	var elem = document.getElementById('updates').elements;	
	
	
	
	for(var i = 0; i < elem.length-1; i++)
{
	thecontrol=elem[i]	
	
	if(thecontrol.id =='CategoryID'  && thecontrol.selectedIndex =="0")
  {document.getElementById('report').innerHTML = '<b>'+thecontrol.name +'</b>  required';
	exit
	}	
		
		
		
	if(thecontrol.id =='speciesID'  && thecontrol.selectedIndex =="0")
  {document.getElementById('report').innerHTML = '<b>'+thecontrol.name +'</b>  required';
	exit
	}		
		
	
	}
	var ProductName=elem['ProductName'].value
		
	var Productdescription=elem['ProductDescription'].value
	var Keywords=elem['Keywords'].value
	var Source=elem['Source'].value
	var SourceUrl=elem['SourceUrl'].value
	var productID=elem['productID'].value 
	var SpeciesID=elem['SpeciesID'].value 
	var CategoryID=elem['CategoryID'].value 
	


	
xmlhttp.open("GET", 'save_edits.php?Source='+Source
+'&SourceUrl='+SourceUrl
+'&CategoryID='+CategoryID
+'&speciesID='+SpeciesID
+'&ProductDescription='+Productdescription
+'&Keywords='+Keywords
+'&ProductName='+ProductName
+'&productID='+productID)
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4){
	response =xmlhttp.responseText;
document.getElementById('report').innerHTML = '<br>'+response
}
}
xmlhttp.send(null);
}






//-----------------------------------------------------------------------------------
function Add_New_User() {
var Myusername= encodeURI(document.getElementById('myusername').value);
var thepassword= encodeURI(document.getElementById('thepassword').value);
if (Myusername=="" ||   thepassword==""){
	alert ('Username/Password required')
	exit;
	}
//var surname= encodeURI(document.getElementById('surname').value);
//var othernames= encodeURI(document.getElementById('othernames').value);
//v//ar mail= encodeURI(document.getElementById('mail').value);
//alert( 'login.php?Addnew=yes&newUsername='+Myusername+'&pswLogin='+thepassword+'&surname='+surname+'&othernames='+othernames+'&nocache = '+nocache)



// Set te random number to add to URL request
nocache = Math.random()

// Pass the login variables like URL variable
xmlhttp.open('get', 'addnewuser.php?newUsername='+Myusername+'&pswLogin='+thepassword+'&nocache = '+nocache);

xmlhttp.onreadystatechange = loginReply;
xmlhttp.send(null);
}
function loginReply() {
if(xmlhttp.readyState == 4){
 response =xmlhttp.responseText;

document.getElementById('login_response').innerHTML = response
}

}

//------------------------------------------------------------------------------------------------


	


