// change it to false if you do not want
// the credit card number to be encrypted
var encrypt_it = true;


/* ==================================================================
   THIS FUNCTION IS TAKEN DIRECTLY FROM NETSCAPE FROM:
   http://developer.netscape.com/library/examples/...
                    .../javascript/formval/FormChek.js
   which is a bunch of functions to validate forms

   FUNCTION: isCreditCard(st)
   INPUT:    st - a string representing a credit card number
   RETURNS:  true, if the credit card number passes the Luhn Mod-10 test
	         false, otherwise
   ================================================================== */
var submitCount = 0;
var whitespace = " \t\n\r";
function isEmpty(s)
 {
	return ((s == null) || (s.length == 0))
}


function isWhitespace (s)
{
	var i;
	// Is s empty?
	if (isEmpty(s))
		return true;
	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
 {
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1)
			return false;
	}

	// All characters are whitespace.
	return true;
}


function isEmail (s)
{
	// is s whitespace?
	if (isWhitespace(s))
		return false;
	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;
	// the last character must not be a .
	if (s.charAt(sLength -1) == ".")
		return false;
	// look for @

	while ((i < sLength) && (s.charAt(i) != "@"))
    {
		 i++
	}


	if ((i >= sLength) || (s.charAt(i) != "@"))
		return false;
	else i += 2;
	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
 	{
		i++
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != "."))
		return false;
	else return true;
}

function FrontPage_Form1_Validator(theForm)
{
	if (submitCount == 0)
	{
		submitCount++;
	}
	else
	{
		return(false);
	}

	if ( theForm.Product.value == "TXT")
 	{
    	alert("Vinsamlega veldu forrit sem á að panta.");
    	theForm.Product.focus();
		submitCount = 0;
    	return (false);
  	}
	
	if (theForm.Name.value == "")
  	{
    	alert("Vinsamlega gefðu upp nafn.");
    	theForm.Name.focus();
    	submitCount = 0;
    	return (false);
  	}
	
	if ((theForm.CustomerKennitala.value.length < 10) || (theForm.CustomerKennitala.value.length > 10))
    {
        alert("Vinsamlega gefðu upp kennitölu - 10 stafir.");
        theForm.CustomerKennitala.focus();
        submitCount = 0;
        return (false);
 	}
	
	var checkOK = "0123456789";
  var checkStr = theForm.CustomerKennitala.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
  	ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    	if (ch == checkOK.charAt(j))
      	break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
   }
   
	 if (!allValid)
   {
		alert("Kennitala inniheldur óleyfileg tákn.");
		theForm.CustomerKennitala.focus();
		submitCount = 0;
		return (false);
   }
			
	if (theForm.Address.value == "")
	{
		alert("Vinsamlega gefðu upp heimilisfang.");
		theForm.Address.focus();
		 submitCount = 0;
		return (false);
	}

	if (theForm.Postcode.value == "")
	{
		alert("Vinsamlega gefðu upp póstnúmer.");
		theForm.Postcode.focus();
		submitCount = 0;
		return (false);
	}
	
	if (theForm.City.value == "")
	{
		alert("Vinsamlega gefðu upp kaupstað.");
		theForm.City.focus();
		submitCount = 0;
		return (false);
	}
	
	if (theForm.Phone.value == "")
	{
		alert("Vinsamlega gefðu upp símanúmer.");
		theForm.Phone.focus();
		submitCount = 0;
		return false;
	}
	
	if (theForm.Email.value == "")
	{
		alert("Vinsamlega gefðu upp netfang.");
		theForm.Email.focus();
		submitCount = 0;
		return false;
	}
	
	if (theForm.Email2.value != theForm.Email.value)
	{
		  alert("Netfangið stemmir ekki. Vinsamlega lagaðu það og reyndu aftur.");
		  theForm.Email2.focus();
		  submitCount = 0;
		  return false;
	}
	
	if (!isEmail(theForm.Email.value))
	{
		alert("Vinsamlega gefðu upp gilt netfang.");
		theForm.Email.focus();
		submitCount = 0;
		return false;
	}
	
	if (theForm.username.value == "")
	{
		alert("Vinsamlega gefðu upp notandanafn.");
		theForm.username.focus();
		submitCount = 0;
		return false;
	}
		
	if (theForm.password.value == "")
	{
		alert("Vinsamlega gefðu upp lykilorð.");
		theForm.password.focus();
		submitCount = 0;
		return false;
	}
		
	if (theForm.password2.value == "")
	{
		alert("Vinsamlega gefðu upp staðfestingu á lykilorði.");
		theForm.password2.focus();
		submitCount = 0;
		return false;
	}
		
	if (theForm.password.value != theForm.password2.value)
	{
		alert("Lykilorð og staðfesting á lykilorði eru ekki eins. Vinsamlegast reynið aftur.");
		theForm.password2.focus();
		submitCount = 0;
		return false;
	}
	
	return (true);
}
	
