<!--

// -- To remove leading and trailing spaces, and returns the shortened string --
function TrimString(szString)
{
      var i = 0;
      var j = 0;

      for (i=0; i<parseInt(szString.length); i++) {
            if(szString.charAt(i) != " ") {
                  for (j=parseInt(szString.length) - 1; j > i; j--) {
                        if (szString.charAt(j) != " ") {
                              break;
                        }
                  }
                  break;
            }
      }

      if (i > j)
            i = j;

      if (szString.length > 0 && szString.charAt(j) != " ")
            j++;

      return szString.substring(i, j);
}

// -- To set the shortened value as the input field new value--
function TrimField(szFieldName)
{
  var szNewStr="";
  if (szFieldName.value == "")
  	return;

  if (szFieldName.value.length > 0) {
	szNewStr = TrimString(szFieldName.value);
	szFieldName.value = szNewStr;
	}
}

// -- To set focus to the input box --
function SetFocusSelect(szFieldName)
{
      szFieldName.focus();
      szFieldName.select();
      return true;
}

// -- To set focus to the input box --
function SetFocus(szFieldName)
{
      szFieldName.focus();
      return true;
}

// -- To check that input box is not empty --
function IsEmpty(szFieldName)
{
   var i;
   var ch;

   if (szFieldName.value == "")	//Daniel 29/5
   		return true;

   TrimField(szFieldName);
   if (parseInt(szFieldName.value.length) == 0)
         return true;

      for (i=0; i<parseInt(szFieldName.value.length); i++) {
            ch = szFieldName.value.charAt(i);
            if (ch != ' ' && ch != '\t')
                  return false;
      }
      return true;
}


function IsValidEmail(szFieldName)
{
      var IsEmail;
      var ch;
      var checkAT;
      var checkPERIOD;

      checkAT = 0;
      checkPERIOD = 0;

      if (IsEmpty(szFieldName)) {
            alert("Please enter your email address.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf("@")==-1) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }


      if (szFieldName.value.indexOf("@")==0) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf(":")>=0) {
     	    alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
     	    SetFocusSelect(szFieldName);
     	    return false;
      }

      if ((szFieldName.value.indexOf("."))-(szFieldName.value.indexOf("@"))==1){
     	    alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
     	    SetFocusSelect(szFieldName);
     	    return false;
      }

      if (szFieldName.value.indexOf("@")==(parseInt(szFieldName.value.length)-1)) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.charAt(parseInt(szFieldName.value.length)-1)==".") {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf(" ") != -1) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch= szFieldName.value.charAt(i)


			//Check for more than 1 '@' character
			if (ch == "@") {
				checkAT = checkAT + 1;
				if (checkAT >= 2) {
					IsEmail = false;
					break;
				}
			}

			//Check for more than 1 '.' character
			if (ch == ".") {
				checkPERIOD = checkPERIOD + 1;

			}

            if ((( ch >= "A") && (ch <= "Z")) || ((ch >= "a") && (ch <= "z")) || ((ch >= "0") && (ch <= "9")) ||
                  (ch == "$") || (ch == "-") || (ch == ".") || (ch == "&") || (ch == "+") || (ch == "!") ||
                  (ch == "*") || (ch == "`") || (ch == "(") || (ch == ")") || (ch == ",") || (ch == "@") ||
                  (ch == "_")) {
                  IsEmail= true;
            }
            else {
                  IsEmail= false;
                  break;
            }
      }

	  if (checkPERIOD == 0) {
	       	alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
		SetFocusSelect(szFieldName);
            	return false;
	  }

      if (!IsEmail) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

   return true;
}

function IsNumeric(szFieldName)
{
      var i;
      var IsNum;
      var ch;

      IsNum=true;
      TrimField(szFieldName);
      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if ((ch >= "0") && (ch <= "9"))
               IsNum= true;
            else
                  return false;
      }
      return IsNum;
}

// -- To ensure that value is alphanumeric --
function IsValidPhone(szFieldName)
{
      var i;
      var IsValidPhone;
      var ch;

      IsValidPhone=true;
      TrimField(szFieldName);
      if (parseInt(szFieldName.value.length) == 0)
         IsValidPhone= true;

      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if ( ((ch >= "0") && (ch <= "9")) || (ch == " ") || (ch == "-") || (ch == "+") )
                  IsValidPhone= true;
            else
                  return false;
      }
      return IsValidPhone;
}


function SubmitForm() {

	//Determine if there is a Site URL.
	if(IsEmpty(form1.SiteURL))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your Site URL.");
		SetFocusSelect(form1.SiteURL);
		return false;
	}


	//Determine if there is a Site Title.
	if(IsEmpty(form1.SiteTitle))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your Site Title.");
		SetFocusSelect(form1.SiteTitle);
		return false;
	}


	//Determine if there is a Site Description.
	if(IsEmpty(form1.SiteDescription))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your Site Description.");
		SetFocusSelect(form1.SiteDescription);
		return false;
	}


	if(form1.SiteCategory.options[0].selected == true || form1.SiteCategory.options[1].selected == true)
	{
			alert("Sorry, you have not selected the Site Category.");
			SetFocus(form1.SiteCategory);
			return false;
	}


	//Determine if there is a Name.
	if(IsEmpty(form1.Name))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your Name.");
		SetFocusSelect(form1.Name);
		return false;
	}


	//Determine if there is an email address.
	if(IsEmpty(form1.fEmail))
	{
		//No email -Stop Submission
		alert("Sorry, you have not typed your Email Address.");
		SetFocusSelect(form1.fEmail);
		return false;
	}

	//Determine if the email is valid.
	if(!IsValidEmail(form1.fEmail)) return false;;


	//Determine if there is a Reciprocal URL.
	if(IsEmpty(form1.ReciprocalURL))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed URL Where You Put Our Link. We will add your website in our link exchange page, if we can find our link in your website.");
		SetFocusSelect(form1.ReciprocalURL);
		return false;
	}


	return true;

}


//-->