﻿function checkLogin(fid)
{
    var uid = document.getElementById("u_name").value;
    var upss = document.getElementById("u_pass").value;
    var eObj = document.getElementById("login_error");
    var data = '';

    if ((uid.length > 0) && (upss.length > 0))
    {
    
        document.getElementById("options_1").style.display = 'none';
        document.getElementById("options_busy").style.display = 'block';
    
        var poststr = 'callback=true&fid=' + fid.toString() + '&uid=' + escape(uid) + '&upss=' + escape(upss);
        ajaxpack.postAjaxRequest('/forms/checkLogin.asp', poststr, function t() 
        { 
           if(ajaxIsReady()) 
	       {
               if(ajaxpack.ajaxobj.responseText == "error")
               {
                  data = data + 'Your details do not match any records in our database.';
                  eObj.innerHTML = data;
                  document.getElementById("options_busy").style.display = 'none';
                  document.getElementById("options_1").style.display = 'block';
               }
               else if (ajaxpack.ajaxobj.responseText == "pass")
               {
                  data = data + 'Your password does not match the one held in our records.';
                  eObj.innerHTML = data;
                  document.getElementById("options_busy").style.display = 'none';
                  document.getElementById("options_1").style.display = 'block';
               }
               else
               {
                  var userid = ajaxpack.ajaxobj.responseText;
                  document.location = document.getElementById("RedURL").value + '?specid=' + userid.toString();
               }
	       }
	    }, 'html');
    
    }
    else
    {
        data = data + 'Please enter both your Username and your password.';
        eObj.innerHTML = data;
    }
}

function setOrderValues(tid)
{
    var prodid, quantid;
    prodid = document.getElementById("product_select").value;
    quantid = document.getElementById("e_quant").value;
    
    if (quantid.length == 0 && tid == 2)
    {
        quantid = 1
        document.getElementById("e_quant").value = 1;
    }
    
    if (prodid.length > 0 && prodid != 0 && quantid.length > 0)
    {
        var resArray = new Array();
        var poststr;
	    poststr = 'callback=true&prodId=' + prodid + '&qty=' + quantid;

	    ajaxpack.postAjaxRequest('/curo/wg_calc_order.asp', poststr, function t()
	    {
		     if(ajaxIsReady())
		     {
			    var strResult = ajaxpack.ajaxobj.responseText;
			    if(strResult != '0')
			    {
			        resArray = strResult.split(",");
				    document.getElementById("e_price").value = formatCurrency(resArray[0]);
				    document.getElementById("e_vat").value = formatCurrency(resArray[1]);
				    document.getElementById("e_total").value = formatCurrency(resArray[2]);
				    document.getElementById("e_pandp").value = formatCurrency(resArray[4]);
			    }
			 }
	    }, 'html');
    }
    else
    {
        document.getElementById("e_price").value = "";
		document.getElementById("e_vat").value = "";
		document.getElementById("e_total").value = "";
		document.getElementById("e_pandp").value = "";
    }
}

function checkNumeric(raised_event)
{
    if(window.event) // IE
	{
	    keynum = raised_event.keyCode;
	    if(keynum > 47 && keynum < 58 || keynum == 8)
		{
			return true;
		}
		else
		{
		    return false;
		}
	}
	else if(raised_event.which) // Netscape/Firefox/Opera
	{
	    keynum = raised_event.which;
	    if(keynum > 47 && keynum < 58 || keynum == 8)
		{
			return true;
		}
		else
		{
		    return false;
		}
	}
	else
	{
		return true;
	}
}

function custDataLogout()
{
    document.location.href = 'custLogout.asp';
    
}

function formatCurrency(amount)
{
	var iAmount = parseFloat(amount);
    
	iAmount = Math.abs(iAmount);
	iAmount = parseInt((iAmount + .005) * 100);
	iAmount = iAmount / 100;

	var sAmount = new String(iAmount);
	
	if(sAmount.indexOf('.') < 0)
	{
	    sAmount += '.00';
	}
	if(sAmount.indexOf('.') == (sAmount.length - 2))
	{
	    sAmount += '0';
	}

    sAmount = "£ " + sAmount;

	return sAmount;
}

