//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 deletePostage(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=deletePostage&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/");
	var mainImageLink = document.getElementById('productMainImageLink');	
	var src1 = imageName.src
	mainImageLink.src = src1.replace("/small/","/original/");
	
	document.body.style.cursor = 'default';
}

var varImageID;

function showVarImage(elemName)
{	
	varImageID = elemName;
    document.body.style.cursor = 'pointer';
	var mainImage = document.getElementById('ddnVariation-'+varImageID);		
	var productTitle = mainImage.options[mainImage.selectedIndex].value;
	http = createRequestObject(); 
	if(http)
	{
		document.body.style.cursor = 'wait';
		http.open("GET", ajaxurl + "ajaxMethod=getVarImage&recordID=" + productTitle, true);
		http.onreadystatechange = handleVarImage;
		http.send(null);
	}
}

function handleVarImage()
{
	if(http.readyState == 4)
	{
	    document.body.style.cursor = 'default';
		var mainImageLink = document.getElementById('varImage'+varImageID);	
		mainImageLink.src ='/userfiles/image/medium/'+ http.responseText;
	}
}
