if(document.location.host == "192.168.10.2")
{
	var base_url = "http://192.168.10.2/authorforsale";	
	var relative_url = "/authorforsale/";
}
else
{
	var base_url = "http://www.authorforsale.com";	
	var relative_url = "/";
}

function createRequestObject_obj() {
 var ro;
 var browser = navigator.appName;
 if(browser == "Microsoft Internet Explorer"){
 ro = new ActiveXObject("Microsoft.XMLHTTP");
 }else{
 ro = new XMLHttpRequest();
 }
 return ro;
}

function createRequestObject()
{

	var xmlhttp=false;
	if (window.XMLHttpRequest)
	{
			xmlhttp=new XMLHttpRequest();		
	}
	else
	{
		
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				
				xmlhttp = false;
			}
		}	
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp; 
}

var http = createRequestObject();

function sndReq(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleResponse;

http.send(null);
}

function handleResponse() {
 if (http.readyState == 1){
         
		x = document.getElementById('product_select');
        x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('product_select');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}


function sndReqProdContract(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleResponseProd;

http.send(null);
}

function handleResponseProd() {
 if (http.readyState == 1){
         
		//x = document.getElementById('contract_select');
        //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('contract_select');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}
var arSelected = new Array(); 

function get_categories(genre_id,destination)
{
//	var ob =document.forms[0].genre_ids;
// while (ob.selectedIndex != -1) 
// { if (ob.selectedIndex != 0) 
//	 arSelected.push(ob.options[ob.selectedIndex].value); 
//	 ob.options[ob.selectedIndex].selected = false;
//}

 // You can use the arSelected array for further processing. }	
	var selected_array =new Array();
	var count = 0;
      for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
      {
                if (document.forms[0].genre_ids.options[i].selected)
                   count++;
       }
			 
			  if(count > 2)
			   {
				alert("You can select only 2 genres");   
			  for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
					  {
							  if (document.forms[0].genre_ids.options[i].selected)
								{
								 	document.forms[0].genre_ids.options[i].selected = false;
							    }
					   }
					   
				return false;
			   }
			   else
			   {
					  for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
					  {
							  if (document.forms[0].genre_ids.options[i].selected)
								{
								 	selected_array.push(document.forms[0].genre_ids.options[i].value);
							    }
					   }
				}
			   
			 if(selected_array.length == 2)  
			 {
				 var append_string = "/"+selected_array[1];
			 }
			 else
			 {
				 var append_string = '';
			 }

 var val = base_url+'/admin/authors/ajax_get_categories/'+selected_array[0]+append_string;
	http.open('get', val, true);
 http.onreadystatechange = handlecatResponse;

http.send(null);

 return false;
}

function get_categories_front_publishers(genre_id,destination)
{
	if(document.getElementById('category_div'))
	{
		document.getElementById('category_div').style.display = 'block';
	}
	if(document.getElementById('category_ids_1'))
	{
		document.getElementById('category_ids_1').style.display = 'block';
	}
	
	if(document.getElementById('word_div'))
	{
		document.getElementById('word_div').style.display = 'block';
	}
	if(document.getElementById('word_category_div'))
	{
		document.getElementById('word_category_div').style.display = 'block';
	}
	 	
document.getElementById("showcase_count").innerHTML ='&nbsp;';	
	var hide_genre = document.getElementById("hide_genre").value;
	if(hide_genre == '')
	{
		hide_genre = genre_id;
	}

	var selected_array = new Array();
	var count = 0;
	for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
	{
		if (document.forms[0].genre_ids.options[i].selected)
			count++;
	}
	/*if(count > 2)
	{
		alert("You can select only 2 genres");  
		document.getElementById("category_ids_1").style.display = 'none';
		for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
		{
			if (document.forms[0].genre_ids.options[i].selected)
			{
				document.forms[0].genre_ids.options[i].selected = false;
			}
		}
		return false;
	}
	else*/
	
	if(count > 0)
	{
		document.getElementById("category_ids_1").style.display = 'block';
		document.getElementById('category_div').style.display = 'block';
	}
	else
	{
		document.getElementById("category_ids_1").style.display = 'none';
		document.getElementById('category_div').style.display = 'none';
	}
	{
		for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
		{
			if (document.forms[0].genre_ids.options[i].selected)
			{
				selected_array.push(document.forms[0].genre_ids.options[i].value);
			}
		}
	}
	if(selected_array.length > 1)  
	{
		var cnt_len = '';
		var append_string = '';
		for(cnt_len=0; cnt_len<selected_array.length; cnt_len++)
		{
			if(cnt_len!=0)
			{
				append_string += "-" + selected_array[cnt_len];
			}
		}
	}
	else
	{
		var append_string = '';
	}
	
	var val = base_url+'/publishers/ajax_get_categories/'+selected_array[0]+append_string+'/'+hide_genre;
	http.open('get', val, true);
	http.onreadystatechange = handlecatResponseFront_publish;
	
	http.send(null);
	
	return false;
}
function get_categories_front(genre_id,destination)
{
	if(document.getElementById('category_ids_1'))
	{
		document.getElementById('category_ids_1').style.display = 'block';
	}
	if(document.getElementById('word_category_ids_1'))
	{
		document.getElementById('word_category_ids_1').style.display = 'block';
	}
	
	
	var selected_array =new Array();
	var count = 0;
	for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
	{
		if (document.forms[0].genre_ids.options[i].selected)
			count++;
	}
	if(count > 2)
	{
		alert("You can select only 2 genres");  
		document.getElementById("category_ids_1").style.display = 'none';
		document.getElementById('word_category_ids_1').style.display = 'none';
		for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
		{
			if (document.forms[0].genre_ids.options[i].selected)
			{
				document.forms[0].genre_ids.options[i].selected = false;
			}
		}
		return false;
	}
	else
	{
		document.getElementById("category_ids_1").style.display = 'block';
		document.getElementById('word_category_ids_1').style.display = 'block';
		for (var i=0, len=document.forms[0].genre_ids.options.length; i<len; i++)
		{
			if (document.forms[0].genre_ids.options[i].selected)
			{
				selected_array.push(document.forms[0].genre_ids.options[i].value);
			}
		}
	}
	if(selected_array.length == 2)  
	{
		var append_string = "/"+selected_array[1];
	}
	else
	{
		var append_string = '';
	}
	
	var val = base_url+'/authors/ajax_get_categories/'+selected_array[0]+append_string;
	http.open('get', val, true);
	http.onreadystatechange = handlecatResponseFront;
	
	http.send(null);
	
	return false;
}

function handlecatResponse() {
 if (http.readyState == 1){
         
		//x = document.getElementById('contract_select');
        //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
			  var res_array =new Array();
			  res_array = http.responseText.split("||");
               x = document.getElementById(res_array[1]);
               x.innerHTML = res_array[0];

        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}
function handlecatResponseFront()
{
	if (http.readyState == 1){
		//x = document.getElementById('contract_select');
		//x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
	}
	if(http.readyState == 4){
		if(http.status == 200)
		{
			var res_array =new Array();
			res_array = http.responseText.split("||");
			
            
			  x = document.getElementById(res_array[1]);
			   x.innerHTML = res_array[0];
			   document.getElementById("word_category_div").style.display = "block";
               y = document.getElementById("word_category_ids_1");
			   y.innerHTML = res_array[2];
		}
		else
		{
			alert("Error loading page\n"+ http.status +":"+ http.statusText);
		}
	}
}

function handlecatResponseFront_publish()
{
	if (http.readyState == 1){
						x = document.getElementById('category_ids_1');
						x.innerHTML = '<img src="'+base_url+'/images/load.gif">';
					}
	if(http.readyState == 4){
		if(http.status == 200)
		{
			var res_array =new Array();
			res_array = http.responseText.split("||");
               x = document.getElementById(res_array[1]);
			x.innerHTML = res_array[0];
			document.getElementById("showcase_count").innerHTML = res_array[2];;
		}
		else
		{
			alert("Error loading page\n"+ http.status +":"+ http.statusText);
		}
	}
}
var arSelected = new Array(); 

function get_number_categories()
{
	var selected_array =new Array();
	var count = 0;
	var cat_1_count =0;
	var cat_2_count =0;
      for (var i=0, len=document.forms[0].category_ids.options.length; i<len; i++)
      {
                if (document.forms[0].category_ids.options[i].selected)
				{
					var string1 = document.forms[0].category_ids.options[i].value;
					if(string1.substr(0,6)== 'cat_1_')  //cat_2_
					{
						cat_1_count++;
				 	}
					if(string1.substr(0,6)== 'cat_2_')  //cat_2_
					{
						cat_2_count++;
				 	}
				}
                    count++;
					
		}
		
			  if(cat_1_count > 6)
			   {
				alert("You can select only 6 categories per genre");   
					  for (var i=0, len=document.forms[0].category_ids.options.length; i<len; i++)
					  {
								var string1= document.forms[0].category_ids.options[i].value;
							//if(document.forms[0].category_ids.options[i].selected && string1.substr(0,6)== 'cat_1_')  //cat_2_
								if(string1.substr(0,6)== 'cat_1_')
								{
								 	document.forms[0].category_ids.options[i].selected = false;
							    }
					   }
				return false;
			   }
			   
			  if(cat_2_count > 6)
			   {
				  alert("You can select only 6 categories per genre");   
					  for (var i=0, len=document.forms[0].category_ids.options.length; i<len; i++)
					  {
								var string1= document.forms[0].category_ids.options[i].value;
								//if(document.forms[0].category_ids.options[i].selected && string1.substr(0,6)== 'cat_2_')  //cat_2_
								if(string1.substr(0,6)== 'cat_2_')
								{
								 	document.forms[0].category_ids.options[i].selected = false;
							    }
					   }
				return false;
			   }
			   
}

function get_number_word_categories()
{
	var selected_array_word =new Array();
	var count = 0;
	var word_cat_1_count =0;
	var word_cat_2_count =0;
      for (var i=0, len=document.forms[0].word_category_ids.options.length; i<len; i++)
      {
                if (document.forms[0].word_category_ids.options[i].selected)
				{
					var string1 = document.forms[0].word_category_ids.options[i].value;
					if(string1.substr(0,11)== 'word_cat_1_')  //cat_2_
					{
						word_cat_1_count++;
				 	}
					if(string1.substr(0,11)== 'word_cat_2_')  //cat_2_
					{
						word_cat_2_count++;
				 	}
				}
                    count++;
					
		}
		
			  if(word_cat_1_count > 1)
			   {
				alert("You can select only 1 word count per genre");   
					  for (var i=0, len=document.forms[0].word_category_ids.options.length; i<len; i++)
					  {
								var string1= document.forms[0].word_category_ids.options[i].value;
							//if(document.forms[0].word_category_ids.options[i].selected && string1.substr(0,11)== 'word_cat_1_')  //cat_2_
								if(string1.substr(0,11)== 'word_cat_1_') 
								{
								 	document.forms[0].word_category_ids.options[i].selected = false;
							    }
					   }
				return false;
			   }
			   
			  if(word_cat_2_count > 1)
			   {
				  alert("You can select only 1 word count per genre");   
					  for (var i=0, len=document.forms[0].word_category_ids.options.length; i<len; i++)
					  {
								var string1= document.forms[0].word_category_ids.options[i].value;
								//if(document.forms[0].word_category_ids.options[i].selected && string1.substr(0,11)== 'word_cat_2_')  //cat_2_
								if(string1.substr(0,11)== 'word_cat_2_')
								{
								 	document.forms[0].word_category_ids.options[i].selected = false;
							    }
					   }
				return false;
			   }
			   
}



function get_user_list(promo_date)
{
		 document.getElementById("user_list").style.display='none';
	var selected_array =new Array();
	var count = 0;
/*	var ob = document.frmnewsletter.receipent_ids;
 while (ob.selectedIndex != -1) 
 { if (ob.selectedIndex != 0) 
	 selected_array.push(ob.options[ob.selectedIndex].value); 
	 ob.options[ob.selectedIndex].selected = false;
}
*/	
	
	
var len = document.getElementById("receipent_ids").options.length;
	var search_string ='';
	
		   for (var i=0; i<len; i++)
		   {
				 if(document.getElementById("receipent_ids").options[i].selected)
				 {
				   selected_array.push(document.getElementById("receipent_ids").options[i].value);
				 }
		   }
	
		if(!Array.indexOf){
		  Array.prototype.indexOf = function(obj){
		   for(var i=0; i<this.length; i++){
			if(this[i]==obj){
			 return i;
			}
		   }
		   return -1;
		  }
		}	
		
	 if(selected_array.indexOf('all')!= -1)
	 {
		   for (var i=0; i<len; i++)
		   {
			   document.getElementById("receipent_ids").options[i].selected = true;
		   }
		// document.getElementById("author_date").style.display='block';
		 search_string='&all';
	  }
	 
	 if(selected_array.indexOf('author_promo')!= -1 || selected_array.indexOf('publisher_promo')!= -1)
	 {
		 //search_string=search_string+'/author_promo';
		 document.getElementById("author_date").style.display='block';
		 if(selected_array.indexOf('author_promo')!= -1)
		 {
			search_string =	search_string +'&author_promo';
		 }
		 
		 if(selected_array.indexOf('publisher_promo')!= -1)
		 {
			search_string =	search_string +'&publisher_promo';
		 }
		 
	 }
	else
	{
		 document.getElementById("author_date").style.display='none';
	 }
	 
	
	
	if(selected_array.indexOf('authors')!= -1)
	 {
		 search_string=search_string+'&authors';
	 }
	
	 if(selected_array.indexOf('publishers')!= -1)
	 {
		search_string=search_string+'&publishers'; 
	 }
	 
	 if(promo_date == 0)
	 {
		var val = base_url+'/admin/newsletter/ajax_get_users/0/'+search_string;
	 }
	 else
	 {
		var val = base_url+'/admin/newsletter/ajax_get_users/'+promo_date+'/'+search_string;
	 }
	 
	http.open('get', val, true);
	http.onreadystatechange = handlenewsResponse;
	
	http.send(null);
	
	return false;
}

function handlenewsResponse() {
 if (http.readyState == 1){
         
		x = document.getElementById('user_list');
        x.innerHTML = '<img src="'+base_url+'/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
			
			res_array = http.responseText;
               x = document.getElementById("user_list");
			   x.style.display="block";
               x.innerHTML = res_array;

        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}


function display_showcase_count(genre_id)
{
   var val = base_url+'/publishers/ajax_get_showcase_count/'+genre_id;
   //alert(val);
	 http.open('get', val, true);
	 http.onreadystatechange = handleResponseShowcase;
	
	http.send(null);
   return false;		
}

function handleResponseShowcase() {
 if (http.readyState == 1){
         
		//x = document.getElementById('contract_select');
        //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('showcase_count');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}


function getproducts(cid)
{
var val = base_url+'/employees/ajax_get_product/'+cid;
 //alert(val);
 sndReq(val);
 return false;
}

function getproductsContract(cid,url)
{
  var i;
  if(document.getElementById("contract_id"))
  {
	  for(i=document.getElementById("contract_id").options.length-1;i >= 0;i--)
	  {
		 if(document.getElementById("contract_id").options[i].value != 0)
		 {
			document.getElementById("contract_id").remove(i);
		 }
	  }
  }
   var val = url+'customer/ajax_get_product_contract/'+cid;
   //alert(val);
   sndReqProdContract(val);
   return false;		
 
}

//For company users
function sendcompanyuser(action,company_value) {
  if(company_value > 0)
  {
  	document.getElementById('pagination_top').style.display ="none";
  	document.getElementById('pagination_bottom').style.display ="none";
  }
  else
  {
	document.getElementById('pagination_top').style.display ="block";
  	document.getElementById('pagination_bottom').style.display ="block";  
  }
 http.open('get', action, true);
 http.onreadystatechange = handleCompanyUserResponse;

http.send(null);
}

function handleCompanyUserResponse() {
  if (http.readyState == 1){
            x = document.getElementById('company_select');
            x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
			   x = document.getElementById('company_select');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}



function getcompanyuser(cid)
{
 /*if(document.domain=='192.168.10.2') {
 	var val = 'http://192.168.10.2/oqapc/index.php/employees/ajax_get_company_user/'+cid;
 }*/
 //alert(val);
 var val = base_url+'/employees/ajax_get_company_user/'+cid;
 sendcompanyuser(val,cid);
 return false;
}


//+==========  function is for toggling on clicking on company name======================

function toggleproduct(src,company)
{
  var source=eval("document.forms[0]."+src+".checked");
  
 // if(source==true)
  //{
	var x=document.getElementsByTagName("input");
  
		 for(var i=0;i<x.length;i++)
		 {
		//alert(company); 
			  if(x[i].id == company)
			   {
				  var inputname=x[i].name;
				  var str=inputname.indexOf("[]");  // we are using this method because we need input name without [] as javascript 
				  if(str != -1)						//doesnot support [] in checkbox name and PHP needs that. so to adjust both we 
				  {									//use this code.
				   inputname=inputname.replace("[]","");
				   inputname1=eval("document.forms[0]."+inputname);
				  if(inputname1.length)
				  {
					  for (var j=0;j<inputname1.length;++ j)
					  {
						  var newcompany="document.forms[0]";  
						  if(source==true)
						  {
							inputname1[j].disabled = false;
						  }
						  else
						  {
							  inputname1[j].disabled = true;
						  }
					  }
				  }
				  else
				  {
						  if(source==true)
						  {
							inputname1.disabled = false;
						  }
						  else
						  {
							  inputname1.disabled = true;
						  }
				  }
				  
				  }
			   }
		}
}  
  
function sndReqVarieties(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleVarietiesResponse;

http.send(null);
}

function handleVarietiesResponse() {
 if (http.readyState == 1){
            x = document.getElementById('varieties');
           x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('varieties');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}

function get_varieties(vid,url)
{
   var val = url+'farmer/ajax_get_varieties/'+vid;
//alert(val);
   sndReqVarieties(val);
   return false;	
}

//================== function added for auto selecting 


function sndReq_farmer(action) {

http.open('get', action, true);
 http.onreadystatechange = handleResponse_farmer;

http.send(null);
}

function handleResponse_farmer() {
 if (http.readyState == 1){
            x = document.getElementById('autoSuggestionsList');
           x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('autoSuggestionsList');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}


function showlist(str)
{
//alert(str);
if(str.length != 0)
 {

	 /*if(document.domain=='192.168.10.2') {
		var val = 'http://192.168.10.2/oqapc/index.php/plotregister/ajax_get_farmer/'+str;
	 }*/
	 var val = base_url+'/plotregister/ajax_get_farmer/'+str;
 }
sndReq_farmer(val);
 return false;

}

function setValue(id,str)
{
document.getElementById("name").value=str;
document.getElementsByName("farmer_id").value=id;
alert(id);
document.getElementById("autoSuggestionsList").innerHTML='';
}



//Show company product

function sndReqProduct(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleProductResponse;
http.send(null);
}

function handleProductResponse() {
 if (http.readyState == 1){
            x = document.getElementById('product');
            //x.innerHTML = 'Loading...';
			//x.innerHTML = '<img src="'+base_url+'public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('product');
                x.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}
//function show_product(cid,url)
function show_product(cid)
{
 
  //alert(document.getElementById("contract_id").options.length)
  var i;
  if(document.getElementById("contract_id"))
  {
	  for(i=document.getElementById("contract_id").options.length-1;i >= 0;i--)
	  {
		 if(document.getElementById("contract_id").options[i].value != 0)
		 {
			document.getElementById("contract_id").remove(i);
		 }
	  }
  }
  var val = base_url+'user/ajax_get_product/'+cid;
	//alert(val);
   sndReqProduct(val);
   return false;		
	
}

//shor product End Here


//Show Contract

function sndReqContract(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleContractResponse;
 http.send(null);
}



function handleContractResponse() {
 if (http.readyState == 1){
            x1 = document.getElementById('contract');
		    x1.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x1 = document.getElementById('contract');
                x1.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}
/////////////////////  show contract-according to company
function sndReqcompContract(action) {
 http.open('get', action, true);
 http.onreadystatechange = handlecompContractResponse;
 http.send(null);
}



function handlecompContractResponse() {
 if (http.readyState == 1){
            x1 = document.getElementById('consignment_select');
		    x1.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x1 = document.getElementById('consignment_select');
                x1.innerHTML = http.responseText;
        }
        else
        {
            alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}

//////////////////////
function show_contract(pid)
{
	 var company_id=document.getElementById("company").value;
	 var comapny_product_id= company_id+"-"+pid;
	// var val ='http://192.168.10.2/oqapc/index.php/user/ajax_get_contract/'+comapny_product_id;
	var val =base_url+'/user/ajax_get_contract/'+comapny_product_id;
	 
	//alert(val);
  	 sndReqContract(val);
 	  return false;		
	
}
//////////////////////////////
function show_compcontract(pid)
{
	 //var contract_id=document.getElementById("contract_select").value;
	 //var comapny_product_id= contract_id+"-"+pid;
	 var comapny_product_id=pid;
	// var val ='http://192.168.10.2/oqapc/index.php/user/ajax_get_contract/'+comapny_product_id;
	 var val =base_url+'/customer/ajax_get_contract/'+comapny_product_id;
	 
	//alert(val);
  	 sndReqcompContract(val);
 	  return false;		
	
}

//////////////////////////////
//shor product End Here
function sndReqlogo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleResponselogo;

http.send(null);
}

function handleResponselogo() {
 if (http.readyState == 1){
            x = document.getElementById('image_id');
            x.innerHTML = 'Loading...';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                x = document.getElementById('image_id');
                x.innerHTML = http.responseText;
        }
        else
        {
           // alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}


function remove_logo(id)
{
 /*if(document.domain=='192.168.10.2') {
 	var val = 'http://192.168.10.2/oqapc/index.php/companies/ajax_remove_logo/'+id;
 }*/
 var val = base_url+'/companies/ajax_remove_logo/'+id;
 sndReqlogo(val);
 return false;
 	
}

function sndtext(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleResponsetext;

http.send(null);
}

function handleResponsetext() {
 if (http.readyState == 1){
           // x = document.getElementById('image_id');
            //x.innerHTML = 'Loading...';
 }
 if(http.readyState == 4){
  	if(http.status == 200)
        {
                //x = document.getElementById('image_id');
                alert(http.responseText);
        }
        else
        {
           // alert("Error loading page\n"+ http.status +":"+ http.statusText);
        }
 }
 
}

function check_value(str,productid)
{
/* if(document.domain=='192.168.10.2') {
 	var val = 'http://192.168.10.2/oqapc/index.php/varieties/ajax_check_value/'+str+'/'+productid;
 }*/
 var val = base_url+'/varieties/ajax_check_value/'+str+'/'+productid;
 sndtext(val);
 return false;
 	
}


function show_contract_list(contractid,baseurl,check)
{
	//alert(baseurl);
	xmlHttp=createRequestObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	//http://192.168.10.16/biggyan/course/editsection.php?id=2
	
	var url=baseurl+contractid;
	
	xmlHttp.onreadystatechange=displaycontractdetails;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
function displaycontractdetails() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	  document.getElementById("resource_links").innerHTML=xmlHttp.responseText; 
		  
	}
}


function setResourceAction() { 
	//alert("came here");
	alert(document.forms['contractform'].contract_no.value);
	new Ajax.Request('http://192.168.10.2/oqapc/index.php/contract/ajax_add', {
	method: 'post',
	parameters: {
	//$('contractform').serialize(true)
	contract_no: document.forms['contractform'].contract_no.value
	}
	});	
	
	
	//sleep(1000);	
	updateCourseSection(document.forms['contractform'].company_id.value,document.forms['contractform'].contract_no.value);
}


function updateCourseSection(companyid,contractno)
{
	xmlHttp=createRequestObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	//sleep(1000);
	var url= "http://192.168.10.2/oqapc/contract/addcontract/"+companyid;
	//alert(url);
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 && xmlHttp.status==200) 
		{
						
				sleep(1000);
				//alert(innerHTML=xmlHttp.responseText);
			
			//closeDivResourceFormYuiNew(course,section,instance); //instance 
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function sleep(ms)
{
	var dt = new Date();
	dt.setTime(dt.getTime() + ms);
	while (new Date().getTime() < dt.getTime());
}


//RM QUALITY LOT INFO 
function fill_lot_no(farmerid,path)
{
	var farmer_id = farmerid.split("-");
	var dt = new Date();
	if(path=="packing")
	{
		var val =base_url+'/packing/ajax_lot_info/'+farmer_id[0]+'/'+dt.getTime();
	}
	else
	{ 
		var val =base_url+'/rm_quality/ajax_lot_info/'+farmer_id[0]+'/'+dt.getTime();
	}
	//alert(val);
  	 sndReqLot(val);
 	 return false;		
}

function sndReqLot(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleLotResponse;
 http.send(null);
 
}

function handleLotResponse()
{
	 if (http.readyState == 1){
            x = document.getElementById('lot_info');
		  //  x.innerHTML = '<img src="'+base_url+'public/images/load.gif">';
		 }
		 if(http.readyState == 4){
			if(http.status == 200)
				{
						x = document.getElementById('lot_info');
						if(document.getElementById("rm_info_td"))
						{
							document.getElementById("rm_info_td").innerHTML="";
						}
						
						if(document.getElementById("packing_info"))
						{
							document.getElementById("packing_info").style.display="none";
							document.getElementById("weight_details").style.display="none";
					    }
								
						x.innerHTML = http.responseText;
						
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

//RM QUALITY LOT INFO END

//RM INFO BASED ON LOT NO
function show_rm_info(rminfo_id)
{
	var val =base_url+'/rm_quality/ajax_rm_info_by_lot/'+rminfo_id;
	//alert(val);
  	 sndReqRmInfo(val);
 	 return false;		
}


function sndReqRmInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleRmInfoResponse;
 http.send(null);
 
}

function handleRmInfoResponse()
{
	 if (http.readyState == 1){
            x = document.getElementById('rm_info_td');
		    x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4){
			if(http.status == 200)
				{
						x = document.getElementById('rm_info_td');
						x.innerHTML = http.responseText;
						
					if(document.getElementById('update_incoming_weight'))
					{
						if(document.getElementById('update_incoming_weight').value == "")
						{
							document.getElementById('total_weight').value=document.getElementById('incoming_weight').value;
						}
					}
					else
					{
						document.getElementById('total_weight').value=document.getElementById('incoming_weight').value;
					}
						
						
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

function calculate_weight()
{
	if(document.getElementById("incoming_weight"))
	{
		var incoming_weight = document.getElementById("incoming_weight").value;
		var rejected_weight = document.getElementById("rejected_weight").value;
		if(rejected_weight=='')
		{
					document.getElementById("total_weight").value=incoming_weight;
	 	}
		else
		{
			if(parseFloat(incoming_weight) < parseFloat(rejected_weight))
			{
				alert("Rejected weight cannot be greater than incoming weight");
				document.getElementById("rejected_weight").value ="";
				document.getElementById("total_weight").value = "";
			}
			else
			{
				//var rejected_weight = document.getElementById("rejected_weight").value;
				if(parseFloat(rejected_weight) >= 0)
				{
					var total_weight = parseFloat(incoming_weight) - parseFloat(rejected_weight);
					document.getElementById("total_weight").value=total_weight;
				}
					
			}
		}
	}
	else
	{
		alert("Please select lot no")	
	}
	
}
//RM INFO BASED END 

function show_rm_quality_info(rminfo_id)
{
	var val =base_url+'/packing/ajax_rm_quality_lot_info/'+rminfo_id;
	//alert(val);
  	 sndReqRmQualityInfo(val);
 	 return false;		
}


function sndReqRmQualityInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleRmQualityInfoResponse;
 http.send(null);
 
}

function handleRmQualityInfoResponse()
{
	 if (http.readyState == 1){
            x = document.getElementById('rm_quality_info_td');
		    x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4){
			if(http.status == 200)
				{
						x = document.getElementById('rm_quality_info_td');
						x.innerHTML = http.responseText;
						document.getElementById("balance_weight").value=document.getElementById("total_available_wt").value;
						document.getElementById("total_packed_weight").value='0.00';
						document.getElementById("remaining_weight").value=document.getElementById("total_available_wt").value;
						//document.getElementById('packing_info').style.display="block";
						//document.getElementById('weight_details').style.display="block";
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

function get_grade_value(grade,id)
{
	id.value=Math.round(parseFloat(document.getElementById('wt_multiplier').value * grade * 10))/10;
	var available_wt=document.getElementById('total_available_wt').value;
	var x=document.getElementsByTagName("input");
   var total_wt=0;
		 for(var i=0;i<x.length;i++)
		 {
	       if(x[i].name.indexOf("packewt_")!=-1)
			{
				if(x[i].value!='')
				{
				  total_wt=parseFloat(total_wt)+parseFloat(x[i].value);
				  if(total_wt > available_wt)
				  {
					 total_wt=parseFloat(total_wt)-parseFloat(x[i].value)
					 var block_arr=x[i].name.split("_");
					 var block_name='box_'+block_arr[1];
					 x[i].value='';
					 document.getElementById(block_name).value='';
					 alert("Packed weight cannot be greater than available weight");
				  }
				}
			} 
		 }
		 
		 document.getElementById("total_packed_weight").value=Math.round((total_wt*10))/10;
		 var remaining_wt=0;
		 
		 remaining_wt=available_wt-total_wt;
		 if(remaining_wt<0)
		 {
			alert("Packed weight cannot be greater than available weight") ;
			document.getElementById("total_packed_weight").value=total_wt;
			document.getElementById("remaining_weight").value='';
			document.getElementById("balance_weight").value='';
		  }
		  else
		  {
			document.getElementById("remaining_weight").value=Math.round((remaining_wt*10))/10;
			get_balance_wt();
			}
		 
}

function get_balance_wt()
{
	var remaining_wt=document.getElementById("remaining_weight").value;
	var wastage_wt=document.getElementById("wastage_weight").value;
	
	var balance_wt=remaining_wt-wastage_wt;
	if(balance_wt < 0)
	{
	 alert("Wastage weight cannot be greater than remaining weight")	;
	 document.getElementById("wastage_weight").value='';
	 document.getElementById("balance_weight").value='';
	}
	else
	{
	 document.getElementById("balance_weight").value=Math.round((balance_wt*10))/10;
	}
}



// function on keypress to bloack alphabets starts here

// version: beta
// created: 2005-08-30
// updated: 2005-08-31
// mredkj.com
function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
	
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}
// function on keypress ends here


function sndReqnext_page(action) {
 http.open('get', action, true);
 http.onreadystatechange = handlenext_pageResponse;
 http.send(null);
 
}

function handlenext_pageResponse()
{
	 if (http.readyState == 1){
            //x = document.getElementById('rm_quality_info_td');
		    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4){
			if(http.status == 200)
				{
						if(http.responseText!="" && http.responseText!="End sequence")
						{
					  	  //alert(http.responseText);
						   window.location=base_url+"/"+http.responseText;
						}
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}
function next_page(sequence)
{
	var val =base_url+'/ajax/next_process/'+sequence;
	//alert(val);
  	 sndReqnext_page(val);
 	 return false;		

}


function reload_chamber()
{
	//alert("HERE")	
	var time = new Date();
	var val =base_url+'/precooling/ajax_chamber_update/'+time.getTime();
	//alert(val);
  	 sndReqChamberInfo(val);
 	 return false;		
}

function sndReqChamberInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handlechamber_response;
 http.send(null);
 
}

function handlechamber_response()
{
	 if (http.readyState == 1){
            //x = document.getElementById('rm_quality_info_td');
		    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 //alert(http.responseText);
		 if(http.readyState == 4){
			if(http.status == 200)
			{
					y = document.getElementById('flex3');
					y.innerHTML = http.responseText;
			}
			else
			{
				alert("Error loading page\n"+ http.status +":"+ http.statusText);
			}
		 }

}

//For unit drop down reaload
function reload_unit()
{
	//alert("HERE")	
	var time = new Date();

	var val =base_url+'/precooling/ajax_unit_reload_dtl/'+time.getTime();
	//alert(val);
  	 sndReqUnitInfo(val);
 	 return false;		
}

function sndReqUnitInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleUnit_response;
 http.send(null);
}

function handleUnit_response()
{
	 if (http.readyState == 1){
            //x = document.getElementById('rm_quality_info_td');
		    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4 ){
			
			//alert(http.responseText);
				if(http.status == 200)
				{
						//alert(http.responseText);
						z = document.getElementById('unit_number');
						z.innerHTML = http.responseText;
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

//End Here 

function get_lot()
{
	var time = new Date();
	if(document.getElementById("day_of_year").value=='' || document.getElementById("created_date").value=='')
	{
	 alert("Please select Incoming RM Date");
	 document.getElementById("created_date").focus();
	 return false;
	}
	
	var dayofyear=document.getElementById("day_of_year").value;
	var year=document.getElementById("year").value;
	var farmer_code=document.getElementById("farmercode").value;
	//dayofyear,year,farmer_code
	if(farmer_code=='')
	{
		 alert("Please add RM details to enter farmer code");
		 return false;
	}
	

	var lot_code=farmer_code+"-"+year+dayofyear;
	var val =base_url+'/rm_incoming/ajax_get_lot_code/'+lot_code+'/'+time.getTime();
  	 sndReqlot_code(val);
 	 return false;		
}

function sndReqlot_code(action) {
 http.open('get', action, true);
 http.onreadystatechange = handlelot_codeResponse;
 http.send(null);
 
}

function handlelot_codeResponse()
{
	 if (http.readyState == 1){
	    //x = document.getElementById('rm_quality_info_td');
	    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
	 }
	 if(http.readyState == 4){
		if(http.status == 200)
		{
			document.getElementById("already_lot").innerHTML=http.responseText;
		}
		else
		{
			alert("Error loading page\n"+ http.status +":"+ http.statusText);
		}
	 }
}

function blockEnter(event)
{
	//alert(event.keyCode);
	if(event.keyCode != 13) 
	{
		return event.returnValue = true;
	}
	else
	{
		return event.returnValue = false;
	}
}

function skippage(consignment_id)
{
	document.location=base_url+"/consignment_details/packingDetails/"+consignment_id;
}



//For unit drop down reaload
function consignment_details(id)
{
	//alert("HERE")	
	var time = new Date();
	document.getElementById("cons_id").value=id;
	window.location=base_url+'/packing_slip/index/'+id;
	/*var val =base_url+'/packing_slip/ajax_consignment_details/'+id;
	//alert(val);
  	 sndReqConsignmentInfo(val);
 	 return false;	*/	
}

function get_con_detail(id)
{
	window.location=base_url+'/packing_slip_report/index/'+id;
}

function sndReqConsignmentInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = handleConsignment_response;
 http.send(null);
}

function  handleConsignment_response()
{
	 if (http.readyState == 1){
            //x = document.getElementById('rm_quality_info_td');
		    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4 ){
			
			//alert(http.responseText);
				if(http.status == 200)
				{
						document.getElementById("print_td").style.display="block";
						//alert(http.responseText);
						z = document.getElementById('display_info');
						z.innerHTML = http.responseText;
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

//End Here 
function delete_anchor(id)
{
 if(id)
 {
	if(confirm("Are you sure want to delete this info?"))
	{ 
	  document.location=base_url+"/"+id;
	}
 }

}


function unique_chamber(unit_id)
{
	var time = new Date();
	var val =base_url+'/precooling/ajax_unit_chamber/'+unit_id+"/"+time.getTime();
	//alert(val);
  	chamberDropdownInfo(val);
	return false;				
}

function chamberDropdownInfo(action) {
 http.open('get', action, true);
 http.onreadystatechange = chamberDropdown_response;
 http.send(null);
}


function  chamberDropdown_response()
{
	 if (http.readyState == 1){
            //x = document.getElementById('rm_quality_info_td');
		    //x.innerHTML = '<img src="'+base_url+'/public/images/load.gif">';
		 }
		 if(http.readyState == 4 ){
				if(http.status == 200)
				{
					var response_array=new Array();
					response_array=http.responseText.split("||");
					z = document.getElementById('chamber_id');
					y = document.getElementById('unit_count');
					y.value = response_array[0];
					z.innerHTML = response_array[1];
				}
				else
				{
					alert("Error loading page\n"+ http.status +":"+ http.statusText);
				}
		 }

}

function popup_window()
{
	var id=document.getElementById("cons_id").value
	window.open (base_url+"/uploads/packing_list/"+id+".html","mywindow","width=800,height=500,scrollbars=yes,menubar=yes"); 
}


function check_time(timeval,id)
{
	//alert(timeval)
	if(parseInt(timeval) > 59)
	{
		alert("Minute cannot be grater than 59");
		document.getElementById(id).value="";
		document.getElementById(id).focus();
	}
}

function check_time_hr(timeval,id)
{
	//alert(timeval)
	if(parseInt(timeval) > 12)
	{
		alert("Hours cannot be grater than 12");
		document.getElementById(id).value="";
		document.getElementById(id).focus();
	}
}

function light_box(farmercode,image1, image_width, image_height)
{
	if(image_width)
	{
		image_width = parseInt(image_width) + parseInt(50);
	}
	else
	{
		image_width = parseInt(20);
	}
	if(image_height)
	{
		image_height = parseInt(image_height) + parseInt(100);
	}
	else
	{
		image_height = parseInt(50);
	}
	document.getElementById('light').style.height=image_height + 'px';
	document.getElementById('light').style.width=image_width + 'px';

	document.getElementById('light').style.display='block';	
/*	document.getElementById('light').style.float='none';
	document.getElementById('light').style.left='50%';
	document.getElementById('light').align='center';*/
	document.getElementById('light').innerHTML = "<div style='clear:both'></div><div style='border:0px solid #FF0000; float:none; margin:0px; paddding:0px: position:absolute; '><span  style=\"float:right; padding-right:30px;\" ><a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\"><img  border='0' src='" + base_url + "/system/css/images/closebox.png' /></a></span><br><br><br><img src="+base_url+"/uploads/farmers/"+farmercode+"/"+image1+">&nbsp;<br><br><br></div>";//<a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\">Close</a>
	document.getElementById('fade').style.display='block';
}	

function light_box_pallet(consignment_id,image1, image_width, image_height)
{
	if(image_width)
	{
		image_width = parseInt(image_width) + parseInt(50);
	}
	else
	{
		image_width = parseInt(20);
	}
	if(image_height)
	{
		image_height = parseInt(image_height) + parseInt(100);
	}
	else
	{
		image_height = parseInt(50);
	}
	document.getElementById('light').style.height=image_height + 'px';
	document.getElementById('light').style.width=image_width + 'px';

	document.getElementById('light').style.display='block';	
/*	document.getElementById('light').style.float='none';
	document.getElementById('light').style.left='50%';
	document.getElementById('light').align='center';*/
	document.getElementById('light').innerHTML = "<div style='clear:both'></div><div style='border:0px solid #FF0000; float:none; margin:0px; paddding:0px: position:absolute; '><span  style=\"float:right; padding-right:30px;\" ><a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\"><img  border='0' src='" + base_url + "/system/css/images/closebox.png' /></a></span><br><br><br><img src="+base_url+"/uploads/barcodes/"+consignment_id+"/"+image1+">&nbsp;<br><br><br></div>";//<a href = \"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\">Close</a>
	document.getElementById('fade').style.display='block';
}


function count_validate()
{
 var total_packed_weight=document.getElementById("total_packed_weight").value;
  var remaining_weight=document.getElementById("remaining_weight").value;
  
  if(total_packed_weight <=0 )
  {
	alert("Please enter atleast one of boxes")  ;
	return false;
  }

return true;
}

/***********************************************
* Cool DHTML tooltip script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

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

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}


