//Common
var http = false;
var http1 = false;
var http2 = 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 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 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 deletedesigneritem(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=deletedesigneritem&recordID=" + recordID, true);
			http.onreadystatechange = handleDelete;
			http.send(null);
		}
	}
}

function deletedesignerproduct(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=deletedesignerproduct&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 shopAdd(recordID,actionType,elemID)
{
	http = createRequestObject(); 
	if(http)
	{
		document.body.style.cursor = 'wait';
		var variation = "";
		variationElem = document.getElementById('ddnVariation-'+recordID);
		if(variationElem != null) variation = variationElem.options[variationElem.selectedIndex].value;
		if(variation == "") variation = "-";
		http.open("GET", ajaxurl+"ajaxMethod="+actionType+"&recordID="+recordID+"&quantity=1&variation="+variation+"&dummy="+new Date().getTime(), true);
		http.onreadystatechange = handleShop;
		http.send(null);
	}
}

function updateTotals()
{
	http2 = createRequestObject(); 
	if(http2)
	{
		document.body.style.cursor = 'wait';
		http2.open("GET", ajaxurl+"ajaxMethod=basketTotals"+"&dummy="+new Date().getTime(), true);
		http2.onreadystatechange = handleBasket;
		http2.send(null);
	}
	document.body.style.cursor = 'default';
}

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

function handleShop()
{
	if(http.readyState == 4)
	{
		updateTotals();
	}
}

function handleBasket()
{
	if(http2.readyState == 4)
	{
		var basketTotals = document.getElementById('basketTotals');
		basketTotals.innerHTML = http2.responseText;
	}
}

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

function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

