<!--

pos = 0;

function slideshow()
{
	if(pos>5)
	{
		pos = 0;
	}


	var text_array = Array(
		"From start to finish the service was professional and of a very high standard.....",
		"Your Chef was most efficient, calm, patient and helpful .....",
		"Everybody raved about the fountain and how yummy it was......",
		"Both my client and myself were extremely pleased with your company's service......",
		"Your guys were fantastic and an asset to your company......",
		"I wouldn't hesitate to use your fountain again, both professionally and personally......"
	);

	var client_array = Array(
										"The Motivaction Group",
										"Cadbury's Chocolate",
										"The Nestle Group",
										"Chameleon",
										"Canary Wharf Group PLC ",
										"Preston  Duckworth"
										);
										
	var img_array = Array(
		"testimonial_motivaction.jpg",
		"testimonial_cadburys.jpg",
		"testimonial_nestle.jpg",
		"testimonial_chamealeon.jpg",
		"testimonial_canarywarf.jpg",
		"testimonial_prestonduckworth.jpg"
	);

	var id1 = 'textchange';
	var shtml = text_array[pos] + "<br /><strong>" + client_array[pos] + "</strong>";
	
	document.images['imgchange'].src = "files/images/homepage/rotatingtestimonial/" + img_array[pos];

	if (document.getElementById || document.all)
	{
		var el = document.getElementById? document.getElementById(id1): document.all[id1];
		if (el && typeof el.innerHTML != "undefined") 
		{
			el.innerHTML = shtml;
		}
	}

	pos = pos+1;

	setTimeout('slideshow()', 9000);

}
		
function reloadBasket()
{
    var country_id = document.forms[0].postage_country.value;
    document.location.href = "basket.php?country_id=" + country_id;
}

function nextDay()
{
    if(document.forms[0].nextday.checked)
    {
        document.location.href = "basket.php?nextday=true";
    }
    else
    {
        document.location.href = "basket.php?nextday=false";
    }
}

function checkbasketQty(f)
{
    // checks that all values entered in the quantities boxes are +ve integers
    // and valid number

    var formok = true;

    for (var i = 0; i < f.length; i++)
    {
        e = f.elements[i];
        if (e.type == "text")
        {
            if (!isNumber(e.value) || !isPosInteger(e.value))
            {
                formok = false;
                e.focus();
                e.select();
                break;
            }
        }
    }

    return formok;
}

function submitBasket()
{

    // submits basket form and checks that all quantities are correct
    f = document.forms[0];
    if (checkbasketQty(f))
    {
        f.submit();
    }
    else
    {
        alert("Product quantities must be a positive whole number or zero\n\nPlease check quantities.");
    }
    return;
}

function Go(){return}

function checkLogin(f)
{
    var formok = true;
    var errmsg = "The following errors have been found:\n\n";

    if (f.email.value == "")
    {
        formok = false;
        errmsg += "- E-mail address has not completed\n";
    }

    if (f.pass.value == "")
    {
        formok = false;
        errmsg += "- Password has not been completed\n";
    }

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }
    return formok;
}

function checkRegister(f)
{
    var formok = true;
    var errmsg = "The following errors have been found:\n\n";

    if (f.name.value == "")
    {
        formok = false;
        errmsg += "- Name has not been completed\n";
    }

    if (f.email.value == "")
    {
        formok = false;
        errmsg += "- E-mail has not been completed\n";
    }
    else if (!validateEmail(f.email.value))
    {
        formok = false;
        errmsg += "- E-mail address is not a valid address\n";
    }

    if (f.password.value == "")
    {
        formok = false;
        errmsg += "- Password has not been completed\n";
    }

    if (f.address1.value == "")
    {
        formok = false;
        errmsg += "- Contact address has not been completed\n";
    }

    if (f.city.value == "")
    {
        formok = false;
        errmsg += "- Contact city has not been completed\n";
    }

    if (f.postcode.value == "")
    {
        formok = false;
        errmsg += "- Contact postcode has not been completed\n";
    }

    if (f.ship_address1.value == "")
    {
        formok = false;
        errmsg += "- Shipping address has not been completed\n";
    }

    if (f.ship_city.value == "")
    {
        formok = false;
        errmsg += "- Shipping city has not been completed\n";
    }

    if (f.ship_country_text.value == "")
    {
        formok = false;
        errmsg += "- Shipping country name has not been completed\n";
    }

    if (f.ship_postcode.value == "")
    {
        formok = false;
        errmsg += "- Shipping postcode has not been completed\n";
    }

    //if (f.hear_about.value == "")
    //{
    //    formok = false;
    //    errmsg += "- Please indicate where you heard about us\n";
    //}

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }
    return formok;
}

function makesame()
{
    var flag = document.forms[1].same_address.checked;
    if (flag)
    {
        // set same as contact address
        var address1 = document.forms[1].address1.value;
        var address2 = document.forms[1].address2.value;
        var city     = document.forms[1].city.value;
        var country  = document.forms[1].country.selectedIndex;
        var postcode = document.forms[1].postcode.value;
        var contact_country = document.forms[1].contact_country.value;
    }
    else
    {
        // set to blank
        var address1 = "";
        var address2 = "";
        var city     = "";
        var country  = "";
        var postcode = "";
        var contact_country = "";
    }

    // set shipping values
    document.forms[1].ship_address1.value = address1;
    document.forms[1].ship_address2.value = address2;
    document.forms[1].ship_city.value = city;
    document.forms[1].ship_country_text.value = contact_country;

    if (flag)
    {
        document.forms[1].ship_country.selectedIndex = country;
    }
    else
    {
        document.forms[1].ship_country.selectedIndex = 2;
    }

    document.forms[1].ship_postcode.value = postcode;
    return;
}


function updateCosts()
{
	
	var Url = location.href;
	Url = Url.replace(/.*\?(.*?)/,"$1");
	Variables = Url.split ("&");
	for (i = 0; i < Variables.length; i++) {
		Separ = Variables[i].split("=");
		eval ('var '+Separ[0]+'="'+Separ[1]+'"');
	}
    // refreshes pages with new shipping country
    var new_country = document.forms[0].ship_country.value;
    document.location.href = "paynow.php?shipping=" + new_country + "&CUST_ID=" + CUST_ID + "&BASKET_NO=" + BASKET_NO;
}


function checkForm(f)
{
    valid = true;
    errors = "The following errors have occured:\n";


    if(f.name.value == "")
    {
        errors+="\n- Name must be filled in."
        valid=false;
    }

    if (f.email.value == "")
    {
        errors += "\n- Email Address must be filled in."
        valid=false;
    }
    else if (!validateEmail(f.email.value))
    {
        errors += "\n- Email Address does not appear to be valid."
        valid=false;
    }


    if (f.address1.value == "")
    {
        valid = false;
        errors += "\n- Contact address has not been completed.";
    }

    if (f.city.value == "")
    {
        valid = false;
        errors += "\n- Contact city has not been completed";
    }

    if (f.postcode.value == "")
    {
        valid = false;
        errors += "\n- Contact postcode has not been completed";
    }

    if (f.ship_address1.value == "")
    {
        valid = false;
        errors += "\n- Shipping address has not been completed.";
    }

    if (f.ship_city.value == "")
    {
        valid = false;
        errors += "\n- Shipping city has not been completed.";
    }

    if (f.ship_country_text.value == "")
    {
        valid = false;
        errors += "\n- Shipping country name has not been completed.";
    }

    if (f.ship_postcode.value == "")
    {
        valid = false;
        errors += "\n- Shipping postcode has not been completed.";
    }

    if (f.frommonth.value == "")
    {
        errors+="\n- From month must be filled in."
        valid=false;
    }

    if (f.fromyear.value == "")
    {
        errors+="\n- From year must be filled in."
        valid=false;
    }

    if (f.tomonth.value == "")
    {
        errors+="\n- To month must be filled in."
        valid=false;
    }

    if (f.toyear.value == "")
    {
        errors+="\n- To year must be filled in."
        valid=false;
    }

    if (f.cardno.value == "")
    {
        errors+="\n- Card Number must be filled in."
        valid=false;
    }

    if (f.cardtype.value == "Switch" && f.issueno.value == "")
    {
        errors+="\n- Issue number must be completed for Switch card payments."
        valid=false;
    }

    if (!valid)
    {
        errors += "\n\nPlease check your entries.";
        alert(errors);
    }

    return valid;
}


/*
 * checks is +ve integer
 * arguments: string to validate
 * returns: true if +ve integer
 */
function isPosInteger(inputVal)
{
    inputStr = inputVal.toString()
    for (var i = 0; i < inputStr.length; i++)
    {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9")
        {
            return false;
        }
    }
    return true;
}

/*
 * general check for +ve or -ve number
 * arguments: string to validate
 * returns: true if number
 */
function isNumber(inputVal)
{
    oneDecimal = false;
    inputStr = inputVal.toString();
    for (var i = 0; i < inputStr.length; i++)
    {
        var oneChar = inputStr.charAt(i);
        if (i == 0 && oneChar == "-")
        {
            continue;
        }
        if (oneChar == "." && !oneDecimal)
        {
            oneDecimal = true;
            continue;
        }
        if (oneChar < "0" || oneChar > "9")
        {
            return false;
        }
    }
    return true;
}

/*
 * validate email address, check for illegal characters, check there is one
 * @ sign and at least one . after it. return true or false
 */
function validateEmail(tempEmail)
{

   var valid = true;
   len = tempEmail.length;

   if(len==0){
        valid = false;
   }


   spaces = tempEmail.indexOf(' ');
        // check for spaces
        if(spaces != -1)
                valid = false;

   ampers = tempEmail.indexOf('&');
        // check for ampersands
        if(ampers != -1)
                valid = false;

   at = tempEmail.indexOf('@');
        // check there is a at sign
        if(at == -1)
                valid = false;

   atmore = tempEmail.indexOf('@',(at+1));
        // check for more at signs
        if(atmore != -1)
                valid = false;

   dot = tempEmail.indexOf('.',at);
        // check for a dot after the at sign
        if(dot== -1)
                valid = false;

   if((at == 0)||(at== len))
   {
        // check where the at sign is
        valid = false;
   }

   return valid;
}

function properCase(strInput, strSplitChar)
{
    // converts a string to Proper Case
    if (strSplitChar == undefined)
    {
          // use space by default
          var strSplitChar = " ";
    }

    strArray = strInput.split(strSplitChar);

    for (var i = 0; i < strArray.length; i++)
    {
        if (strArray[i].length > 1)
        {
            strArray[i] = strArray[i].charAt(0).toUpperCase() + strArray[i].substr(1).toLowerCase();
        }
        else if (strArray[i].length == 1)
        {
            strArray[i] = strArray[i].toUpperCase();
        }
    }
    return strArray.join(" ");
}


//-->