{emailerror1="Please input your email address";
 emailerror2="Bad Syntax of Email address";};
function newalert(errorstring) {
   alert(errorstring);
};
function Validator(theForm)
{ 

if (theForm.email.value =="")
  { theForm.email.focus();
    newalert(emailerror1);
    return (false); }
	
  var checkOK = "@";
  var checkStr = theForm.email.value;
  var allValid = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      {
 allValid = true;
 break;
      }
  }
 if (!allValid)
  {
    theForm.email.focus();
    newalert(emailerror2);
    return (false);
  }
  var checkOK = ".";
  var checkStr = theForm.email.value;
  var allValid = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      {
 allValid = true;
 break;
      }
  }
 if (!allValid)
  {
    theForm.email.focus();
    newalert(emailerror2);
    return (false);
  }
  var checkOK = "@???????????????????????º???0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
  var checkStr = theForm.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 (!allValid)
  {
    theForm.email.focus();
    newalert(emailerror2);
    return (false);
  }
  return (true);
}

function Validat(frm)
{
var listitems= eval('document.'+frm).getElementsByTagName("input");
	 for (var a=0;a<listitems.length;a++)
	{ switch (listitems[a].name)
	{
		case 'fields[subscribers_email]':	var reEmail = /^[-\w\d\.]+@[-\w\d\.]+\.[-\w\d\.]+$/;
		if(listitems[a].value == "")
			{   alert("please fill your email");listitems[a].focus();return false;}
				if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(listitems[a].value)))
				{   alert("email field is wrong");listitems[a].focus();return false;}
			break;

	}
	} 

}


var lastform;

function sendForm(frm){
if (Validat(frm)==false) return ;
lastform=frm;
var vars=buildVars(frm);
flashProxy.call("sendfunc",vars);
}

function buildVars(frm){
var str=new Array;
var listitems= eval('document.'+frm).getElementsByTagName("input");
	 for (var i=0;i<listitems.length;i++){
	str[i]=new Object;
	str[i].name=listitems[i].name;
	str[i].value=encodeURIComponent(listitems[i].value);
	}
return str;
}

function formSent(){
var elem=document.getElementById(lastform+'_thanks').style.display='block';
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
  //  alert("XML data OK")
    document.getElementById('page-body').innerHTML=xmlhttp.responseText;
    }
  else
    {
    alert("Problem retrieving XML data:" + xmlhttp.statusText);
    }
  }
}

