function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function CheckForm(thisForm)
{
		if (trim(thisForm.FirstName.value) == "")
		{
			alert("Please enter your Firstname");
			thisForm.FirstName.focus();
			return(false);
		}
		
		if (trim(thisForm.LastName.value) == "")
		{
			alert("Please enter your Lastname");
			thisForm.LastName.focus();
			return(false);
		}
		
		if (trim(thisForm.Email.value) == "")
		{
			alert("Please enter your Email address");
			thisForm.Email.focus();
			return(false);
		}
		
		if (trim(thisForm.EmailConfirm.value) == "")
		{
			alert("Please Confirm your email address");
			thisForm.EmailConfirm.focus();
			return(false);
		}
		
	    if (thisForm.paymentMethod.value == "Credit Card")
	    {
			if (trim(thisForm.NameOnCard.value) == "")
			{
				alert("Please enter your Name on card");
				thisForm.NameOnCard.focus();
				return(false);
			}
			
			if (trim(thisForm.CC_Number.value) == "")
			{
				alert("Please enter your Credit card number");
				thisForm.CC_Number.focus();
				return(false);
			}

/*
			if (isNaN(trim(thisForm.CC_Number.value)) || thisForm.CC_Number.value.length != 16 || thisForm.CC_Number.value < 0)
			{
				alert("The Credit card number is invalid");
				thisForm.CC_Number.focus();
				return(false);
			}
*/
	    }
		
		if (trim(thisForm.DomainName.value) == "")
		{
			alert("Please enter your Domain name");
			thisForm.DomainName.focus();
			return(false);
		}
		
		if (trim(thisForm.Initial.value) == "")
		{
			alert("You have to agree the terms");
			thisForm.Initial.focus();
			return(false);
		}
		
		if (trim(thisForm.EmailConfirm.value) != trim(thisForm.Email.value))
		{
			alert("Email addresses must be same");
			thisForm.Email.focus();
			return(false);
		}

		if (trim(thisForm.upwd.value) == "")
		{
			alert("Please enter your password");
			thisForm.upwd.focus();
			return(false);
		}
		
		if (trim(thisForm.upwdC.value) == "")
		{
			alert("Please confirm your password");
			thisForm.upwdC.focus();
			return(false);
		}

		if (trim(thisForm.upwd.value) != trim(thisForm.upwdC.value))
		{
			alert("Your passwords are not same");
			thisForm.upwd.focus();
			return(false);
		}
		
		/*		if (!checkdomain(thisForm.DomainName.value))
		{
			alert("Your domain name is invalid");
			thisForm.DomainName.focus();
			return(false);
		}*/

        var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
        var checkStr = thisForm.Email.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 (thisForm.Email.value.length < 6)
        {
                        allValid = false;
        }

        if (!allValid)
        {
                alert("Your email address is invalid");
                thisForm.Email.focus();
                return (false);
        }
        address=thisForm.Email.value;
        if(address.length>0)
        {
			i=address.indexOf("@");
			j=address.indexOf(".")
			if((i==-1)||(j==-1))
			{
				window.alert("Your email address is invalid")
				thisForm.Email.focus();
				return false
			}
        }

		if (checktext(thisForm.Email.value))
        {
                alert("Your email address is invalid");
                thisForm.Email.focus();
                return (false);
        }
	thisForm.submit();	
}

function checktext(text)
{
                        allValid = true;

                for (i = 0;  i < text.length;  i++)
                {
                        if (text.charAt(i) != " ")
                        {
                                allValid = false;
                                break;
                        }
                }

return allValid;
}

function checkdomain(text)
{
	allValid = true;
	initstr = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-";
	if (text.length < 4)
	{
		allValid = false;
		return allValid;
	}
	for (i = 0; i < text.length ; i++)
	{
		if (initstr.indexOf(text.charAt(i)) == -1)
		{
			allValid = false;
			break;
		}
	}
	return allValid;
}
