function getCookie(pre)
{
	var dc = document.cookie;
	var prefix = pre + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
		begin += 2;

	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return dc.substring(begin + prefix.length, end);


}
function GetWhere()
{
  var from = getCookie("WHERE");
  if(from != "" && from != null) document.all.ListingWHEREPrefix.innerHTML = from;  
}

function GetFrom() {
  
  var from = getCookie("TEST");   
  if (from != "" && from != null) document.all.ListingFROMClause.innerHTML = from;  
  document.cookie = "TEST="+";path=/;expires=Monday, 19-Aug-1996 05:00:00 GMT;";
}

function openFromWindow()
{	
  
  	if(document.all.QueryDataSourcephp && document.all.QueryDataSourcephp.value != "")
  	{  	
  		var url = "fromClause.php?dataSource=" + document.all.QueryDataSourcephp.value;
  		
  		window.open(url, "form");
  	}
  	else
  	{
  		alert("unable to launch helper function for FromClause, please make user the Data Source Field is filled");
  	}
  	
  

}

function openWhereWindow()
{
  
  if(document.all.QueryDataSourcephp.value && document.all.ListingFROMClause.value)
  {  	
  	var where = getCookie("TABLE");  	
  	var url = "whereClause.php?dataSource=" + document.all.QueryDataSourcephp.value + "&From=" + document.all.ListingFROMClause.value + "&Table=" + where;
  	
  	window.open(url, "form");
  }
  else if(document.all.QueryTable && document.all.QueryTable.value)
  {
  	var url = "whereClause.php?dataSource=" + document.all.QueryDataSourcephp.value + "&From=" + document.all.QueryTable.value + "&Table=" + document.all.QueryTable.value;
  	window.open(url, "form");
  	
  }
  else
  {
  	alert("unable to launch helper function for WhereClause, please make user the Data Source Field and From Clause are filled");
  }

}

function deleteCookie()
{


	document.cookie = "TEST="+";path=/;expires=Monday, 19-Aug-1996 05:00:00 GMT;";	
	document.cookie = "TABLE=" + ";path=/;expires=Monday, 19-Aug-1996 05:00:00 GMT;";
	document.cookie = "WHERE=" + ";path=/;expires=Monday, 19-Aug-1996 05:00:00 GMT;";
}

var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

function showhide(lay) {
if (ie4)
  if (document.all[lay].style.visibility == "visible")
    document.all[lay].style.visibility = "hidden";
  else
    document.all[lay].style.visibility = "visible";
else if (ns4)
  if (document.layers[lay].visibility == "show")
    document.layers[lay].visibility = "hide";
  else
    document.layers[lay].visibility = "show";
else if (ns6)
  if (document.getElementById([lay]).style.visibility == "visible")
    document.getElementById([lay]).style.visibility = "hidden";
  else
    document.getElementById([lay]).style.visibility = "visible";
}

