// JavaScript Document

function highlight(c,colour){
	if(typeof colour == "undefined")colour = '#f1f1f1';
	c.style.backgroundColor = colour;
}



function lowlight(c,colour){
	if(typeof colour == "undefined")colour = '#ffffff';
	c.style.backgroundColor = colour;
}

function limitText(f1,f2,maxlength) {
	if (f1.value.length > maxlength)
	{
	  f1.value = f1.value.substring(0,1000);
	}
	f2.value = maxlength - f1.value.length;
}

function validCC(cardNo)
{
	var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2

    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {

      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;

      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }

      // Add the units element to the checksum total
      checksum = checksum + calc;

      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    }

    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
	     return false;
    }
    else
    {
		return true;
    }
}



