function addToBasket(objForm, strCode, strType)
{
	var objAjax, objItem, objUnitItem, objSupercedeItem, strSupercedeCode, nQuantity, strUnit, objXmlRequestDom, objKmsgNode, objXmlNode, objWidthInput, objKmsgNode;

	if (validateForm(objForm))
	{
		objAjax = new CAjax();
		objAjax.create();

		objSupercedeItem = document.getElementById("supercededTo_" + strCode);

		strSupercedeCode = objSupercedeItem.value;

		if (objSupercedeItem.value.length > 0)
		{
			if (!confirm(lang("This product is superceded by") + " " + strSupercedeCode + ".\n" + lang("Are you sure you want to order this product?")))
			{
				return false;
			}
		}

		if (strType == "U")
		{
			objItem = document.getElementById("pr_quantity_" + strCode);
			objUnitItem = document.getElementById("pr_unit_" + strCode);

			nQuantity = objItem.value;
			strUnit = objUnitItem.value;

			startLoading();
			setTimeout("_addToBasket('" + strCode + "', '" + nQuantity + "', '" + strUnit + "')", 1);
		}
		else
		{
			objXmlRequestDom = xml_createXmlDom();
			objXmlRequestDom.loadXML("<kmsg></kmsg>");
			objKmsgNode = objXmlRequestDom.selectSingleNode("/kmsg");

			for (var i = 1; i <= MAX_TALLY; i++)
			{
				objQuantityInput = document.getElementById("t_quantity_" + i + "_" + strCode);
				objLengthInput = document.getElementById("t_length_" + i + "_" + strCode);
				objWidthInput = document.getElementById("t_width_" + i + "_" + strCode);

				if (objQuantityInput.value == "")
				{
					break;
				}

				objXmlNode = xml_createNode(objKmsgNode, "tally");
				objXmlNode.setAttribute("quantity", objQuantityInput.value);
				objXmlNode.setAttribute("length", objLengthInput.value);

				if (objWidthInput)
				{
					objXmlNode.setAttribute("width", objWidthInput.value);
				}
			}

			startLoading();
			setTimeout("_addToBasketTally('" + strCode + "', '" + objXmlRequestDom.xml + "')", 1);

		}

	}
  
  setTimeout("chkButton()", 1000);
  
}

function _addToBasketTally(strCode, strXml)
{
	objTab.addTab("tab_basket", lang("Basket"), true);
	objTab.showTab("tab_basket");

	if (objAjax.open("ajax/ajax_basket.php?mode=ADDTALLY&productCode=" + strCode, false))
	{
		objAjax.send(strXml);

		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}

function _addToBasket(strCode, nQuantity, strUnit)
{
	objTab.addTab("tab_basket", lang("Basket"), true);
	objTab.showTab("tab_basket");

	if (objAjax.open("ajax/ajax_basket.php?mode=ADD&productCode=" + strCode + "&quantity=" + nQuantity + "&unit=" + strUnit, true))
	{
		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}



function viewBasket()
{
	
	startLoading();
	setTimeout("_viewBasket()", 1);
	setTimeout("chkButton()", 1);
  
}


function chkButton(){
		
	$(function() {
		$.ajax({
	        type: "POST",
	        url: "purchaseorder/Validate_To_Show_Button.php",  
	        dataType: "json",
	        complete:function(data){
				
				
	    	},
	        success: function(data){
	    		
	    		if (data.showpurchaseorderbut == "true"){
				
            //alert('BUTTON SHOULD DISPLAY');
            $("input#btncreatePurchaseTab").css("display","inline");
	    			
	    		} else {
            
	    			//attr("disabled","disabled");
	    			//alert($("input#btncreatePurchaseTab").val());
	    			$("input#btncreatePurchaseTab").css("display","none");
            
				}	
	    		
	        }
	     });	  
	});
}

function showNotes(strNotesId)
{
	var objItem = document.getElementById(strNotesId);

	if (objItem.getAttribute("notesOn") == "true")
	{
		objItem.style.visibility = "hidden";
		objItem.style.display = "none";
		objItem.setAttribute("notesOn", "false");
	}
	else
	{
		objItem.style.visibility = "visible";

		try
		{
			objItem.style.display = "block";
		}
		catch (e)
		{
			objItem.style.display = "table-cell";
		}

		objItem.setAttribute("notesOn", "true");
	}
}

function _viewBasket(strMode)
{
	objAjax = new CAjax();
	objAjax.create();

	objTab.addTab("tab_basket", lang("Basket"), true);
	objTab.showTab("tab_basket");

	if (!strMode)
	{
		strMode = "";
	}

	if (objAjax.open("ajax/ajax_basket.php?mode=" + strMode, true))
	{
		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}

function updateQuickBasket()
{
	var objAjax;

	objAjax = new CAjax();
	objAjax.create();

	if (objAjax.open("ajax/ajax_xsl.php?xsl=ajax/ajax_quickBasket", true))
	{
		var objTabDiv = document.getElementById("quickBasket");
		objTabDiv.innerHTML = objAjax.getResponse();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}
}

function emptyBasket()
{
	startLoading();
	setTimeout("_viewBasket('EMPTY')", 1);
}


function updateBasket()
{
	startLoading();
	setTimeout("_updateBasket()", 1);
  setTimeout("chkButton()", 1000);
}

function getBasket()
{
	var objXmlRequestDom, objKmsgNode, arrInputs, objProductNode, strInputId, strCode;

	objXmlRequestDom = xml_createXmlDom();
	objXmlRequestDom.loadXML("<kmsg></kmsg>");
	objKmsgNode = objXmlRequestDom.selectSingleNode("kmsg");

	arrInputs = document.getElementsByTagName("input");
	arrTally = document.getElementsByTagName("tally");

	for (var i = 0; i < arrInputs.length; i++)
	{
		strInputId = "" + arrInputs[i].getAttribute("id");

		if (strInputId.substr(0,9) == "quantity_")
		{
			strCode = strInputId.substr(9);
			objProductNode = getProductRow(objXmlRequestDom, strInputId.substr(9));
			objProductNode.setAttribute("quantity", arrInputs[i].value);

			for (var iTallyCount = 0; iTallyCount < arrTally.length; iTallyCount++)
			{
				objTally = arrTally[iTallyCount];

				if (objTally.getAttribute("name") == "tally_" + strCode)
				{
					objTallyXmlNode = xml_createNode(objProductNode, "tally");
					objTallyXmlNode.setAttribute("quantity", objTally.getAttribute("quantity"));
					objTallyXmlNode.setAttribute("width", objTally.getAttribute("width"));
					objTallyXmlNode.setAttribute("length", objTally.getAttribute("length"));
				}
			}

			objTempInput = document.getElementById("balance_" + strCode);
			objProductNode.setAttribute("balance", objTempInput.value);

			objTempInput = document.getElementById("remove_" + strCode);
			objProductNode.setAttribute("remove", objTempInput.value);

			objTempInput = document.getElementById("description_" + strCode);

			if (objTempInput)
			{
				objProductNode.setAttribute("description", objTempInput.value);
			}

			objTempInput = document.getElementById("unit_" + strCode);
			objProductNode.setAttribute("unit", objTempInput.value);

			objTempInput = document.getElementById("notes_" + strCode);
			objProductNode.setAttribute("notes", objTempInput.value);
		}

	}

	return objXmlRequestDom.xml;
}

function _updateBasket()
{
	var objForm, strBasketXml;
	var objAjax;

	objForm = document.getElementById("basket");

	strBasketXml = getBasket();

	objAjax = new CAjax();
	objAjax.create();

	if (objAjax.open("ajax/ajax_basket.php?mode=UPDATE", false))
	{
		objAjax.send(strBasketXml);

		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}

function getProductRow(objXmlDom, strProductCode)
{
	var objXmlNode = objXmlDom.selectSingleNode("/kmsg/product[@code = '" + strProductCode + "']");

	if (!objXmlNode)
	{
		var objKmsgNode = objXmlDom.selectSingleNode("/kmsg");
		objXmlNode = xml_createNode(objKmsgNode, "product");
		objXmlNode.setAttribute("code", strProductCode);
	}

	return objXmlNode;
}

function deliveryDetails()
{
	startLoading();
	setTimeout("_deliveryDetails()", 1);
}


function validateComplete(value){
		if (value == true){
			deliveryDetails();
		}else if(value == false){
			alert('Please accept terms and conditions');
			return false;
		}
}

function _deliveryDetails()
{
	var objAjax, objItem, strBasketXml;

	objAjax = new CAjax();
	objAjax.create();
	
	strBasketXml = getBasket();
	//alert(strBasketXml);

	if (objAjax.open("ajax/ajax_deliveryDetails.php", false))
	{
		objAjax.send(strBasketXml);

		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();

		setFocus("delivery_reference");
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
	
	
}

function completeOrder(strOrderType)
{
   
	var objForm = document.getElementById("orderForm");

	if (!validateForm(objForm))
	{
            return false;
	}      
       
	startLoading();
	setTimeout("_completeOrder('" + strOrderType + "')", 1);
}

function validate_extra_fields(){
    
    error = "";
    if ($("#drp_claim_accounts  option:selected").val() == ""){
        if (error == ""){
            error = error + "Please complete the following\n\r";
        }
        error = error + "Please select a Invoice to."
    }
    
    if ($("#claim").val() == ""){
        if (error == ""){
            error = error + "Please complete the following\n\r";
        }
        error = error + "Please provide a claim number"
    }
    
    if ($("#contname").val() == ""){
        if (error == ""){
            error = error + "Please complete the following\n\r";
        }
        error = error + "Please provide a Contractor Name"
    }
   
   
   if (error != ""){
       alert(error);   
       return false;
   }else{
       return true;
   }
    
}

function _completeOrder(strOrderType)
{
        
	var objXmlRequestDom, objKmsgNode, objAjax;
	var strReference, strName, strLine1, strLine2, strLine3, strLine4, strPostCode, strInstructions;

	strReference = document.getElementById("delivery_reference").value;
	strName = document.getElementById("delivery_name").value;
	strLine1 = document.getElementById("delivery_address1").value;
	strLine2 = document.getElementById("delivery_address2").value;
	strLine3 = document.getElementById("delivery_address3").value;
	strLine4 = document.getElementById("delivery_address4").value;
	strPostCode = document.getElementById("delivery_postcode").value;
	strInstructions = document.getElementById("delivery_instructions").value;
	strTel = document.getElementById("tel").value;

	objXmlRequestDom = xml_createXmlDom();
	objXmlRequestDom.loadXML("<kmsg></kmsg>");
	objKmsgNode = objXmlRequestDom.selectSingleNode("kmsg");

	xml_createNode(objKmsgNode, "reference", strReference);
	xml_createNode(objKmsgNode, "tel", strTel);
	xml_createNode(objKmsgNode, "name", strName);
	xml_createNode(objKmsgNode, "line", strLine1);
	xml_createNode(objKmsgNode, "line", strLine2);
	xml_createNode(objKmsgNode, "line", strLine3);
	xml_createNode(objKmsgNode, "line", strLine4);
	xml_createNode(objKmsgNode, "postcode", strPostCode);
	xml_createNode(objKmsgNode, "instructions", strInstructions);
	xml_createNode(objKmsgNode, "orderType", strOrderType);
        
        
        xml_createNode(objKmsgNode, "drp_claim_accounts", $("#drp_claim_accounts  option:selected").val());
        xml_createNode(objKmsgNode, "claim",$("#claim").val() );
        xml_createNode(objKmsgNode, "contname", $("#contname").val());
        xml_createNode(objKmsgNode, "contaddinfo",$("#contaddinfo").val() );
        xml_createNode(objKmsgNode, "advinfo", $("#advinfo").val());

        
        
	objAjax = new CAjax();
	objAjax.create();

	if (objAjax.open("ajax/ajax_completeOrder.php", false))
	{
		objAjax.send(objXmlRequestDom.xml);

		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}


function _completeOrder3(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, pam, CardHolderIpAddr, MaskedCardNumber, TransactionType)
    {
		
    	var objXmlRequestDom, objKmsgNode, objAjax;
    	var strReference, strName, strTel, strLine1, strLine2, strLine3, strLine4, strPostCode, strInstructions, strOrderType, VCSCODE, strAmount;
    
    	strReference = m1;
      strName = m2;
      strTel = m3;
    	strLine1 = m4;
    	strLine2 = m5;
    	strLine3 = m6;
    	strLine4 = m7;
    	strPostCode = m8;
    	strInstructions = m9;
		  strOrderType = 'p';
		  VCSCODE = m10;
		  strAmount = p6;
    
    	objXmlRequestDom = xml_createXmlDom();
    	objXmlRequestDom.loadXML("<kmsg></kmsg>");
    	objKmsgNode = objXmlRequestDom.selectSingleNode("kmsg");
    
    	xml_createNode(objKmsgNode, "reference", strReference);
    	xml_createNode(objKmsgNode, "name", strName);
     	xml_createNode(objKmsgNode, "tel", strTel);
    	xml_createNode(objKmsgNode, "line", strLine1);
    	xml_createNode(objKmsgNode, "line", strLine2);
    	xml_createNode(objKmsgNode, "line", strLine3);
    	xml_createNode(objKmsgNode, "line", strLine4);
    	xml_createNode(objKmsgNode, "postcode", strPostCode);
    	xml_createNode(objKmsgNode, "instructions", strInstructions);
    	xml_createNode(objKmsgNode, "orderType", strOrderType);
      xml_createNode(objKmsgNode, "VCSCODE", VCSCODE);
		  xml_createNode(objKmsgNode, "amount", strAmount);
    
    	objAjax = new CAjax();
    	objAjax.create();
    
    	if (objAjax.open("ajax/ajax_completeOrder2.php", false))
    	{
    		objAjax.send(objXmlRequestDom.xml);
			
			var objTabDiv = document.getElementById("tab_basket");
			objTabDiv.innerHTML = objAjax.getResponse();
			updateQuickBasket();

          //  document.write(objAjax.getResponse());

    	}
    	else
    	{
    		alert(lang("There has been a problem, please contact an administrator"));
    	}
    
		endLoading();
		
	}

function createTemplate(strName)
{
	startLoading();

	setTimeout("_createTemplate('" + strName + "')", 10);
}

function _createTemplate(strName)
{
	var objButton, objAjax, objItem, objDiv;

	objAjax = new CAjax();
	objAjax.create();

	if (objAjax.open("ajax/ajax_basket.php?mode=SAVETEMPLATE&name=" + strName, true))
	{
		objDiv = document.getElementById("createTemplateResponse");
		objDiv.innerHTML = objAjax.getResponse();

		objItem = document.getElementsByTagName("templateCreated");

		if (objItem.length > 0)
		{
			objButton = document.getElementById("templateSaveButton");
			objButton.disabled = "true";
		}
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}

function createTemplateTab()
{
	startLoading();
	setTimeout("_createTemplateTab()", 1);
}

function _createTemplateTab()
{
	var objAjax;

	objAjax = new CAjax();
	objAjax.create();

	if (objAjax.open("ajax/ajax_xsl.php?xsl=ajax/ajax_createTemplate", true))
	{
		objTab.addTab("tab_createTemplate", lang("Create Template"), true);
		objTab.showTab("tab_createTemplate");

		var objTabDiv = document.getElementById("tab_createTemplate");
		objTabDiv.innerHTML = objAjax.getResponse();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}


function createClaimTab(){
	client_account = "";
	client_userId = "";
	client_password = "";
	ipAddress = "";	
	
	if ($("#claim").val() != ""){
		if (validateRest()){
			$.ajax({
				type: "POST",
				url: "purchaseorder/get_login_details.php",  
				dataType: "json",
				complete:function(data){
					createClaimTab2(client_account,client_userId,client_password,ipAddress, $("#claim").val());	
				},
				success: function(data){				
					client_account = data.client_account;
					client_userId = data.client_userId;
					client_password = data.client_password;
					ipAddress = data.ipAddress;
					
				}
			});
		}else{
			alert("Please provide all client details");	
		}
	}else{
		alert("Please provide claim number");	
	}
	
}

function ChangesAddress(object, id){
	//alert(object.id);
	dropValue = $("#" + object.id + " option:selected").val();
	//alert(dropValue);
	
	claimaddress1 = $("#claimaddress1" + dropValue).val();
	claimaddress2 = $("#claimaddress2" + dropValue).val();
	claimaddress3 = $("#claimaddress3" + dropValue).val();
	claimaddress4 = $("#claimaddress4" + dropValue).val();
	
	$("#delivery_address1").val(claimaddress1);
	$("#delivery_address2").val(claimaddress2);
	$("#delivery_address3").val(claimaddress3);
	$("#delivery_address4").val(claimaddress4);
}

function validateRest(){
	return true;	
}



function createClaimTab2(client_account, client_userId, client_password, ipAddress, claim) {
   
        objXmlRequestDom1 = xml_createXmlDom();	
	objXmlRequestDom1.loadXML("<kmsgsimple></kmsgsimple>");	
	objLineNode = objXmlRequestDom1.selectSingleNode("kmsgsimple");
	objLineNode.setAttribute("claim", claim); 
	objLineNode.setAttribute("id", client_userId);
	objLineNode.setAttribute("password", client_password);	
		
	formatedstr = objXmlRequestDom1.xml;
	
  	formatedstr = formatedstr.replace(/&lt;/g, "<");
  	formatedstr = formatedstr.replace(/&gt;/g, ">");
  	
	objAjax = new CAjax();
	objAjax.create();
	
	if (objAjax.open("ajax/ajax_validate_claim_order.php?claim=" + claim, false))
	{
            objAjax.send(formatedstr);		
            //$("#tab_basket").prepend("*" + claim  + objAjax.getResponse());	
		
           htmlresponse = jQuery.trim(objAjax.getResponse());                            
        
            if (htmlresponse.match("Claim number already exists") != null){   
                alert("Claim number already exists");
                $("#btnPlaceorder").attr("disabled","disabled");
                $("#btncreateClamTab").attr("disabled","");
                $("#claim").attr("readonly","");
            } else if (htmlresponse.match("Claim order verified") != null){
                alert("Claim order verified");
                $("#btnPlaceorder").attr("disabled","");
                $("#claim").attr("readonly","readonly");
                $("#btncreateClamTab").attr("disabled","disabled");
            }               
	}
	else
	{
            alert(lang("There has been a problem, please contact an administrator"));
	}
}


function createPurchaseTab(strCode, nQuantity, strUnit)
{
	client_account = "";
	client_userId = "";
	client_password = "";
	ipAddress = "";
	
	Source = "";
	Destination = "";
	Branch = "";
	SupplierCode = "";
	
	Address1 = "";
	Address2 = "";
	Address3 = "";
	Address4 = "";
	Address5 = "";
	
	$.ajax({
        type: "POST",
        url: "purchaseorder/validate_purchase.php",  
        dataType: "json",
        complete:function(data){
			
			docreate_xml(client_account,client_userId,client_password,ipAddress,Source,Destination,Branch,SupplierCode,Address1,Address2,Address3,Address4,Address5);
    	},
        success: function(data){
    	
    		client_account = data.client_account;
    		client_userId = data.client_userId;
    		client_password = data.client_password;
    		ipAddress = data.ipAddress;
    		
    		Source = data.Source;
    		Destination = data.Destination;
    		Branch = data.Branch;
    		SupplierCode = data.SupplierCode;
    		
    		Address1 = data.Address1;
    		Address2 = data.Address2;
    		Address3 = data.Address3;
    		Address4 = data.Address4;
    		Address5 = data.Address5;
        }
      });

}

function docreate_xml(client_account,client_userId,client_password,ipAddress,Source,Destination,Branch,SupplierCode,Address1,Address2,Address3,Address4,Address5){
	successfull = false;
	
	LineXml = "";
	LineXml2 = "";
	
  	/*$.ajax({
		type: "POST",
		url: "purchaseorder/gen_purchase_order2.php?file=test.xml",		
		dataType: "json",		
		success: function(data){

		}
	});*/
	
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	
	var formatDate = year + "/" + month + "/"  + day;


	
	objXmlRequestDom1 = xml_createXmlDom();
	objXmlRequestDom1.loadXML("<kmsgsimple></kmsgsimple>");
	objLineNode = objXmlRequestDom1.selectSingleNode("kmsgsimple");
	objLineNode.setAttribute("id", client_userId);
	objLineNode.setAttribute("password", client_password);
	objLineNode.setAttribute("ip", ipAddress);  

	xml_createNode(objLineNode, "header", "");
	objLineNode = objLineNode.selectSingleNode("header");	
  
	xml_createNode(objLineNode, "branch", Branch);
	xml_createNode(objLineNode, "destbranch", Destination);
	xml_createNode(objLineNode, "account", SupplierCode);
	xml_createNode(objLineNode, "reference", "");
	xml_createNode(objLineNode, "daterequired", formatDate);
	xml_createNode(objLineNode, "name", "naidu");
	xml_createNode(objLineNode, "instructions", "");
	xml_createNode(objLineNode, "ordertype", "");
	xml_createNode(objLineNode, "address", "");
	
	objLineNode = objLineNode.selectSingleNode("address");
	xml_createNode(objLineNode, "line", Address1);
	xml_createNode(objLineNode, "line", Address2);
	xml_createNode(objLineNode, "line", Address3);
	xml_createNode(objLineNode, "line", Address4);
	xml_createNode(objLineNode, "line", Address5);
	
	objLineNode = objXmlRequestDom1.selectSingleNode("kmsgsimple");
	
	  
	strProduct = "";
	countlines = 0;
	$('tr#Purchase1').each(function(i) { 
		code = $(this).find('#code').val();
		description = $(this).find('#description').val(); 
		position = $(this).find('#position').val();
		balance = $(this).find('#balance').val() ; 
		quantity = $(this).find('#quantity').val(); 
		calcPrice = $(this).find('#calcPrice').val();
		totalPrice = $(this).find('#totalPrice').val();
		unit = $(this).find('#unit').val();
		
				
		//objLineNode = objLineNode.selectSingleNode("lines");		
		//xml_createNode(objLineNode, "line", "");	
		//objLineNode=objLineNode.getElementsByTagName("line")[countlines];		
		//alert(objLineNode);
		
		strProduct = strProduct + "<line>";
		strProduct = strProduct + "<product>" + code + "</product>";
		strProduct = strProduct + "<description>" + description + "</description>";
		strProduct = strProduct + "<quantity>" + quantity + "</quantity>";
		strProduct = strProduct + "<unit>" + unit + "</unit>";
		strProduct = strProduct + "<daterequired>"+formatDate+"</daterequired>";
		strProduct = strProduct + "<price>" + calcPrice + "</price>";
		strProduct = strProduct + "<totalPrice>" + totalPrice + "</totalPrice>";
		strProduct = strProduct + "</line>";

		countlines = countlines + 1;
	});	
  
	
	xml_createNode(objLineNode, "lines", strProduct);
	
  	formatedstr = objXmlRequestDom1.xml;
  	formatedstr = formatedstr.replace(/&lt;/g, "<");
  	formatedstr = formatedstr.replace(/&gt;/g, ">");
	//alert(formatedstr);
	
	objAjax = new CAjax();
	objAjax.create();
	
	if (objAjax.open("ajax/ajax_Place_P_Order.php", false))
	{
		objAjax.send(formatedstr);	
		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		//viewBasket();		
		//alert("Purchase order created successfully");
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}
	
	
	

	//alert("Purchase order sent successfully");
	
}

 

/*
function docreate_xml(strCode, nQuantity, strUnit){
	successfull = false;
	alert($('#name').val());
	$('tr#Purchase1').each(function(i) {    
		
alert($(this).find('#parameters').val());
alert($(this).find('#name').val());
alert($(this).find('#line').val());
	    datastring = "code=" + $(this).find('#code').val() +
	                "&description=" + $(this).find('#description').val() + 
	                "&position=" + $(this).find('#position').val() +
	                "&balance=" + $(this).find('#balance').val() + 
	                "&quantity=" + $(this).find('#quantity').val() + 
	                "&calcPrice=" + $(this).find('#calcPrice').val()+
	                "&totalPrice=" + $(this).find('#totalPrice').val() +
	                "&unit=" + $(this).find('#unit').val();
	    
	    $.ajax({
	      type: "POST",
	      url: "purchaseorder/gen_purchase_order.php?file=test.xml",
	      data: datastring, 
	      complete:function(msg){
		    	
	    	},
	      success: function(msg){
	    	successfull = true;
	      }
	    });
	    
	});	
	
	
	
		alert("Purchase order sent successfully");
	
}*/



/*function _addToBasket(strCode, nQuantity, strUnit)
{
	objTab.addTab("tab_basket", lang("Basket"), true);
	objTab.showTab("tab_basket");

	if (objAjax.open("ajax/ajax_basket.php?mode=ADD&productCode=" + strCode + "&quantity=" + nQuantity + "&unit=" + strUnit, true))
	{
		var objTabDiv = document.getElementById("tab_basket");
		objTabDiv.innerHTML = objAjax.getResponse();
		updateQuickBasket();
	}
	else
	{
		alert(lang("There has been a problem, please contact an administrator"));
	}

	endLoading();
}*/




function templatePrompt()
{
	var i, bOkName, strTemplateName;

	strTemplateName = document.getElementById("templateName").value;

	// If the template name is null, then the user must have pressed cancel on the prompt.
	if (strTemplateName != null)
	{
		if (strTemplateName.length > 0 && strTemplateName.length <= 64)
		{
			bOkName = true;

			// As the template name is used for a filename, make sure no invalid characters
			// have been used.
			for (i = 0; i < strTemplateName.length; i++)
			{
				if ("0123456789-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(strTemplateName.charAt(i)) == -1)
				{
					bOkName = false;
					break;
				}
			}

			// If the template name is valid, submit the form.
			if (bOkName)
			{
				createTemplate(strTemplateName);
			}
			else
			{
				alert(lang("Template names can only include characters A-Z, a-z, 0-9 and -"));
			}
		}
		else if (strTemplateName.length > 64)
		{
			alert(lang("The template name cannot be larger than 64 characters"));
		}
		else
		{
			alert(lang("A template name is needed in order to save"));
		}
	}
}
