screenHeight =  '&screenHeight=' + determineScreenSize();

function showDiv(divToShow) {
	//alert('showDiv(' +divToShow +')');

	document.all['' +divToShow].style.display 	= '';
}

function hideDiv(divToHide) {
	//alert('hideDiv(' +divToHide +')');

	document.all['' +divToHide].style.display 	= 'none';
}

function showHide(childObj)
{
	var dom = document.all[childObj].style;
	if (dom.display == "none")
		dom.display = "";
	else
	dom.display = "none";
}

function table_sort(order_by)
{
	here		= self.location.href;
	order_by	= '?order_by=' + order_by + '&sort_dir=';
	//alert(here);
	if (here.indexOf(order_by + 'asc') < 1) {
		//there	= '<?php echo $PHP_SELF ?>' + order_by + 'asc';
		here = removeExcessQueryString(here);
		there	= here + order_by + 'asc';
	} else {
		//there	= '<?php echo $PHP_SELF ?>' + order_by + 'desc';
		here = removeExcessQueryString(here);
		there	= here + order_by + 'desc';
	}
	//alert(there);

	there = there + screenHeight;
	self.location = there;
}

function table_filter(filter_by,filter_value)
{
//alert(filter_by +', ' +filter_value);
	if(filter_value == '') {
		here		= self.location.href;
		here = removeExcessQueryString(here);
		there	= here;
		there = there + '?' +screenHeight;
		self.location = there;
	} else if(filter_value != '') {
		here		= self.location.href;
		filter_by	= '?filter_by=' + filter_by + '&filter_value=' +filter_value;
		here = removeExcessQueryString(here);
		there	= here + filter_by;
		there = there + screenHeight;
		self.location = there;
	}
}

function table_goFilter(filter_by,filter_value,pageToJumpTo)
{
	if(filter_by != '') {
		here		= self.location.href;
		filter_by	= '?filter_by=' + filter_by + '&filter_value=' +filter_value;
		here = removeExcessQueryString(here);
		//alert('here = ' +here)
		
		here = removeLastDir(here);
		//alert('here = ' +here)

		there	= here + pageToJumpTo + filter_by;
		//alert('there = ' +there)

		there = there + screenHeight;
		self.location = there;
	}
}



function confirm_delete(id, productTitle) {
//	if (confirm("Are you sure you want to delete  " + id + " (" + productTitle + ")?"))
	if (confirm("Are you sure you want to delete " + productTitle + "?"))
	{
		here = self.location.href;
		here = removeExcessQueryString(here);
		/*
		//	I PRESUME THIS IS INCLUDED IF OTHER THINGS ARE IN THE QUERY STRING
		query_thing = '?';
		if (self.location.href.indexOf(query_thing)) {
			query_thing = '&';
		}
		there			= here + query_thing + 'id=' + id + '&action=delete';
		*/

		there			= here + '?' + 'id=' + id + '&action=deleteProduct';

		there = there + screenHeight;
		self.location	= there;
	}
}

function confirm_deleteProject(id, projectTitle) {
	if (confirm("Are you sure you want to delete " + projectTitle + " and all the milestones attached to it?"))
	{
		here = self.location.href;
		here = removeExcessQueryString(here);
		there			= here + '?' + 'id=' + id + '&action=deleteProject';

		there = there;
		self.location	= there;
	}
}

function confirm_deleteMilestone(id, milestoneTitle) {
	if (confirm("Are you sure you want to delete " + milestoneTitle + "?"))
	{
		here = self.location.href;
		here = removeExcessQueryString(here);
		there			= here + '?' + 'id=' + id + '&action=deleteMilestone';

		there = there;
		self.location	= there;
	}
}

function confirm_deleteNews(id, productTitle) {
//	if (confirm("Are you sure you want to delete  " + id + " (" + productTitle + ")?"))
	if (confirm("Are you sure you want to delete " + productTitle + "?"))
	{
		here = self.location.href;
		here = removeExcessQueryString(here);
		/*
		//	I PRESUME THIS IS INCLUDED IF OTHER THINGS ARE IN THE QUERY STRING
		query_thing = '?';
		if (self.location.href.indexOf(query_thing)) {
			query_thing = '&';
		}
		there			= here + query_thing + 'id=' + id + '&action=delete';
		*/

		there			= here + '?' + 'id=' + id + '&action=deleteNews';

		there = there + screenHeight;
		self.location	= there;
	}
}

function confirm_photoDelete(photoname) {
	if (confirm("Are you sure you want to delete photo " + photoname +"?"))
	{
		here = self.location.href;
		here = removeExcessQueryString(here);

		/*
		//	I PRESUME THIS IS INCLUDED IF OTHER THINGS ARE IN THE QUERY STRING
		query_thing = '?';
		if (self.location.href.indexOf(query_thing)) {
			query_thing = '&';
		}
		there			= here + query_thing + 'photoname=' + id + '&action=deletePhoto';
		*/

		there			= here + '?' + 'photoname=' + photoname + '&action=deletePhoto';

		there = there + screenHeight;
		self.location	= there;
	}
}

function refresh_list() {
	here = self.location.href;
	here = removeExcessQueryString(here);
	self.location	= here;
}

function view_product(id) {
	here = self.location.href;
	here = removeExcessQueryString(here);
	there= here + '?' + 'id=' + id + '&action=viewProduct';
	self.location	= there;
}

  function genFilename() {
    //alert('inside generateFilename()');
    
    if(document.all.file.value == '') {
      alert('please chose a file to upload first');
    } else {
      var fullName = document.all.file.value;
      if(fullName.indexOf("\\") != -1) {
        var nameArray = fullName.split("\\");
        reducedName=nameArray[nameArray.length-1];
        //alert('reducedName = ' +reducedName);
      }
    document.all.fileName.value = reducedName;        
    }
    
  }

  function doValidation() {
    //MAIN VALIDATION FUNCTION CALLED ONSUBMIT OF THE FORM. SUBMIT THE FORM IF NO ERRORS, ELSE HIGHLIGHT ERRORS AND RETURN USER TO FORM

    //alert('inside doValidation()');

    //RESET THE ERROR FLAG AND MESSAGE
    var errorFlag = false;
    var errorMessage = 'The following errors have occurred:\n';

    //Dont think we need any error checking or validation - may put some in at a later date

    //UNHIGHLIGHT ALL THE FIELDS
    unHighlightField('fileName');
    unHighlightField('file');

    if (document.all.fileName.value == '') {
      errorFlag     = true;
      errorMessage  += '\nPlease enter a filename';
      highlightField('fileName');
    }
    
    if (document.all.file.value == '') {
      errorFlag     = true;
      errorMessage  += '\nPlease select a file to upload';
      highlightField('file');
    }

    if(errorFlag) {
      alert(errorMessage);
    } else {
      //alert('submit the form');
      document.all.action.value = 'submit';
      document.forms[0].submit(); 
    }
  }

