//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';
}

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

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

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

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

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

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

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

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

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

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

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

function swapImage(imageName)
{	
    document.body.style.cursor = 'pointer';
	//var miniImage = document.getElementById(imageName);
	var mainImage = document.getElementById('productMainImage');	
	var src = imageName.src
	mainImage.src = src.replace("/small/","/large/");
	
	document.body.style.cursor = 'default';
}
