
function f1(){

var z="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_. ";
var u="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var count=0;
var count1=0;
var c=0;

var count2=0,count3=0;
var c1=0;

var w=moha.email.value;
var y=moha.fname.value;
var y1=moha.lname.value;

if(y==""){

window.alert("Please enter your first name");

return false;

}


if(y1==""){

window.alert("Please enter your last name");

return false;

}


if(w==""){
window.alert("Please enter your email ");
return false;

}

for(var i=0;i<w.length;i++)
{
if(w.charAt(i)=="@")
count2++;
}
if(count2==0||count2>1){
window.alert(" your email must contain just one @ and the email form  like:(youremailname@domainname.com)")
return false;}

var m=w.split("@");
var t=m[0];var q=m[1];

for(var i=0;i<t.length;i++)
{
if(z.indexOf(t.charAt(i))<0){
window.alert("your email name must be in range of A-Z, a-z,0-1");
return false;}
}

for(var i=0;i<t.length;i++)
{
if(t.charAt(i)==".")
count3++;}
if(count1>1){
window.alert(" your email name must contain just one dot");
return false;}


for(var i=0;i<w.length;i++)
{
if(q.charAt(i)==".")
c1++;}
if(c1==0){
window.alert("your domain name should have at least  one dot");
return false;}

var k=q.split(".") ;

var e=k[1];
var p=k[0];
for(var i=0;i<e.length;i++)
{
if(u.indexOf(e.charAt(i))<0){
window.alert("your domain must be in the range  of A-Z, a-z,0-1");

return false;}}



return true;


}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

$(document).ready(function(){
    $("#btnSubmit").click(function() {
    
       if ( f1() )
         {
		
		// we can use other domain to perform this task, 
		// for example, this page (index.asp) sit in domain www.encelabs.com
		// and captcha.asp sit in www.smartplanetcms.com
		// we can use url as below, this is because we are using cross domain ajax
		// $.getJSON("www.smartplanetcms.com/captcha.asp?validateCaptchaCode=" +  $("#captchacode").val() + "&format=json&jsoncallback=?", function(data){
		
		$.getJSON("captcha.asp?validateCaptchaCode=" +  $("#captchacode").val() + "&format=json&jsoncallback=?", function(data){
		if (data.status == "1")
			{
				//if (formValidation() == true)
				//{
					$("#moha").submit();
				//}
				
				
				result = true;
				
			}
		
			else
			{
				if (data.session == "0")
					RefreshImage("imgCaptcha");
				
				alert("Write the code in the image correctly!");
				$("#captchacode").focus();
		
				result = false;
				
			}
			
		});
   	}
   	else
   	  return false;
    });
  });



function typee()
{
	if (document.getElementById("country").value=="Lebanon")
		{
			deleteRow(document.getElementById("myTable").rows[5],0);
			
		}
	else
		{
			 insertRow(5, '<b>Specify</b>','<input name="specify" type="text" size="20">');
			 	}	
return 0;
}

function insertRow(r, str1, str2)
  {
  var x=document.getElementById('myTable').insertRow(r);
  var y=x.insertCell(0);
  var z=x.insertCell(1);
  y.innerHTML=str1;
  z.innerHTML=str2;
  }
function deleteRow(r, minRows)
{ 
   var tb=r.parentNode.parentNode.id;
  if(document.getElementById(tb).rows.length<=minRows) 
  	{
		alert("You have to leave at least "+minRows+" row.");
		return false;
	}
   	var i=r.rowIndex;
  	document.getElementById(tb).deleteRow(i);
}







