//Common
var http = false;
var ajaxurl = '../code/ajax.php?';

function createRequestObject()
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function cursorOver() {
    document.body.style.cursor = 'pointer';
}

function cursorClear() {
    document.body.style.cursor = 'default';
}

function openWindow(popupURL,popupWidth,popupHeight)
{
	var width  = popupWidth;
	var height = popupHeight;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open(popupURL,'popupWindow', params);
	if (window.focus) {newwin.focus()}
	return false;			
}

//Deletions
function deleteCategory(recordID)
{
	if(confirm("Are you sure you want to delete Category " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteCategory&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function deleteRange(recordID)
{
	if(confirm("Are you sure you want to delete Range " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteRange&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function deleteProduct(recordID)
{
	if(confirm("Are you sure you want to delete Product " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteProduct&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function deleteMaster(recordID)
{
	if(confirm("Are you sure you want to delete drop down " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteMaster&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function deleteDDNValue(recordID)
{
	if(confirm("Are you sure you want to delete drop down value " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteDDNValue&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function deleteArticle(recordID)
{
	if(confirm("Are you sure you want to delete article " + recordID + "?"))
	{
		http = createRequestObject(); 
		if(http)
		{
			document.body.style.cursor = 'wait';
			http.open("GET", ajaxurl + "ajaxMethod=deleteArticle&recordID=" + recordID, true);
			http.onreadystatechange = handledeleteRecord;
			http.send(null);
		}
	}
}

function handledeleteRecord()
{
	if(http.readyState == 4)
	{
	    document.body.style.cursor = 'default';
		window.location.href = window.location.href;
	}
}
