// JavaScript Document




function validateDonate()
{
	
	var erorxxx = 0;


	if(document.donate.email)
	{
		var eml = document.donate.email.value ;
		if(document.donate.email.value == '')
		{
			alert('الرجاء إدخال البريد الالكتروني');
			document.donate.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('الرجاء إدخال بريد إلكتروني صالح');
				document.donate.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	
		if(document.donate.name && document.donate.name.value == '' )
		{
			alert('الرجاء إدخال الاسم الأول');
			document.donate.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.donate.lname && document.donate.lname.value == '' )
		{
			alert('الرجاء إدخال الاسم الاخير');
			document.donate.lname.focus();
			erorxxx++;
			return false;
		}
	
	if(erorxxx < 1)
	{
	document.donate.submit();
	return true;
	
	}
		
	
	
	
}





function validatecheckoutx()
{
	
	var erorxxx = 0;
		if(document.myform.name && document.myform.name.value == '' )
		{
			alert('please enter First name');
			document.myform.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.myform.lname && document.myform.lname.value == '' )
		{
			alert('please enter Last name');
			document.myform.lname.focus();
			erorxxx++;
			return false;
		}
	if(document.myform.email)
	{
		var eml = document.myform.email.value ;
		if(document.myform.email.value == '')
		{
			alert('please enter Email');
			document.myform.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.myform.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	

	
	if(erorxxx < 1)
	{
		document.myform.submit();
		return true;
	}
	
}




function clearCont()
{
	document.input1.reset();
	
	
}

function validateRegxContact()
{
	var erorxxx = 0;
		if(document.input1.usernamex && document.input1.usernamex.value == '')
		{
			
			alert('Please enter username');
			document.input1.usernamex.focus();
			erorxxx++;
			return false;
		}
	

		if(document.input1.passwordx && document.input1.passwordx.value == '' )
		{
			alert('please enter password');
			document.input1.passwordx.focus();
			erorxxx++;
			return false;
		}
	if(document.input1.email)
	{
		var eml = document.input1.email.value ;
		if(document.input1.email.value == '')
		{
			alert('please enter Email');
			document.input1.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.input1.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	
		if(document.input1.name && document.input1.name.value == '' )
		{
			alert('please enter Full name');
			document.input1.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.subject && document.input1.subject.value == '' )
		{
			alert('please enter Subject');
			document.input1.subject.focus();
			erorxxx++;
			return false;
		}
		
		
		if(document.input1.message && document.input1.message.value == '' )
		{
			alert('please enter Your Message');
			document.input1.message.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.address && document.input1.address.value == '' )
		{
			alert('please enter Message');
			document.input1.address.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.lname && document.input1.lname.value == '' )
		{
			alert('please enter Last name');
			document.input1.lname.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.randomm && document.input1.randomm.value == '' )
		{
			alert('please enter Validation Code');
			document.input1.randomm.focus();
			erorxxx++;
			return false;
		}
	
	if(erorxxx < 1)
	{
	test();
	return true;
	
	}
		
	
	
	
}

function CheckFileExt(fileName, allowedFileTypes)
{

 var dot;
 var fileType;

 dot = fileName.split(".");
 fileType = "." + dot[dot.length-1];

 if(allowedFileTypes.join(".").indexOf(fileType) != -1)
 {
 return true;
 }
 else
 {
 alert("Invalid File Type!");

 return false;
 }
}

function validateup()
{
	var erorxxx = 0;

	if(document.input1.email)
	{
		var eml = document.input1.email.value ;
		if(document.input1.email.value == '')
		{
			alert('please enter Email');
			document.input1.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.input1.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	
		if(document.input1.name && document.input1.name.value == '' )
		{
			alert('please enter Full name');
			document.input1.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.subject && document.input1.subject.value == '' )
		{
			alert('please enter Subject');
			document.input1.subject.focus();
			erorxxx++;
			return false;
		}
		
		
		if(document.input1.message && document.input1.message.value == '' )
		{
			alert('please enter Your Message');
			document.input1.message.focus();
			erorxxx++;
			return false;
		}
		

		if(document.input1.fil && document.input1.fil.value !='' )
		{
		
		
		var ccecker = CheckFileExt(document.input1.fil.value, ['gif', 'jpg', 'doc', 'docx','xls','jpeg' , 'txt', 'pdf']);
		if(ccecker == false)
		{
			
				erorxxx++;
				return false;
		}
		
		}



		
		if(document.input1.lname && document.input1.lname.value == '' )
		{
			alert('please enter Last name');
			document.input1.lname.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.randomm && document.input1.randomm.value == '' )
		{
			alert('please enter Validation Code');
			document.input1.randomm.focus();
			erorxxx++;
			return false;
		}
	
	if(erorxxx < 1)
	{
	document.input1.submit();
	return true;
	
	}
		
	
	
	
}




function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}



function validateRec()
{
	var erorxxx = 0;

	if(document.rec.email)
	{
		var eml = document.rec.email.value ;
		if(document.rec.email.value == '')
		{
			alert('please enter Email');
			document.rec.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.rec.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	

		

	
	if(erorxxx < 1)
	{
	return true;
	document.rec.submit();
	
	}
		
	
	
	
}


function validateRegxnewcoment()
{
	
	var erorxxx = 0;
	
		if(document.input1.comname && document.input1.comname.value == '' )
		{
			alert('please enter Full name');
			document.input1.comname.focus();
			erorxxx++;
			return false;
		}
		
		
	if(document.input1.comemail)
	{
		var eml = document.input1.comemail.value ;
		if(document.input1.comemail.value == '')
		{
			alert('please enter Email');
			document.input1.comemail.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.input1.comemail.focus();
				erorxxx++;
				return false;
			}
		}
	}

	if(document.input1.comcomment && ( document.input1.comcomment.value == 'تعليقك' || document.input1.comcomment.value == '' ))
		{
			alert('please enter Comments');
			document.input1.comcomment.focus();
			erorxxx++;
			return false;
		}

		if(document.input1.randomm && document.input1.randomm.value == '' )
		{
			alert('please enter Validation Code');
			document.input1.randomm.focus();
			erorxxx++;
			return false;
		}
	
	if(erorxxx < 1)
	{
		testar();
		return true;
	}
	
}

function validatesug()
{

	var errornum = 0;

	if(document.formsug.from && document.formsug.from.value=='' )
	{
		alert("Please enter Your  Email ");
		document.formsug.from.focus();
		errornum++;
		return false;
	}
	
	if(document.formsug.name && document.formsug.name.value=='' )
	{
		alert("Please enter Your Name ");
		document.formsug.name.focus();
		errornum++;
		return false;
	}
	
	
	if(document.formsug.tor && document.formsug.tor.value=='' )
	{
		alert("Please enter Recipient  Email ");
		document.formsug.tor.focus();
		errornum++;
		return false;
	}
	
	
	
	if(document.formsug.tor  )
	{
		if(-1 == document.formsug.tor.value.indexOf("@"))
		{ 
			document.formsug.tor.focus(); 
			alert("Your email must have a '@'."); 
			errornum++;
			return false; 
		}
		if(-1 != document.formsug.tor.value.indexOf(",")) 
		{ 
			document.formsug.tor.focus(); 
			alert("Your email must not have a ',' in it"); 
			errornum++;
			return false; 
		}
		if(-1 != document.formsug.tor.value.indexOf("#")) 
		{ 
			document.formsug.tor.focus(); 
			alert("Your email must not have an '#' in it." ); 
			errornum++;
			return false; 
		}
		if(-1 != document.formsug.tor.value.indexOf("!")) 
		{ 
			document.formsug.tor.focus(); 
			alert("Your email must not have a '!' in it." ); 
			errornum++;
			return false; 
		}
		if(-1 != document.formsug.tor.value.indexOf(" "))
		{ 
			document.formsug.tor.focus(); 
			alert("Your email must not have a space in it." ); 
			errornum++;
			return false; 
		}
		if(document.formsug.tor.value.length ==(document.formsug.tor.value.indexOf("@")+1) ) 
		{
			document.formsug.tor.focus();
			alert("Your email must have a domain name after the '@'.");
			errornum++;
			return false;
		}
}
		
	if(errornum < 1)
	{
		window.open('','newwin','left=220,top=190,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=500,height=350')
		//return true;
	}
	
}


function validateRegx()
{
	
	var erorxxx = 0;
	
		if(document.input1.name && document.input1.name.value == '' )
		{
			alert('please enter First name');
			document.input1.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.lname && document.input1.lname.value == '' )
		{
			alert('please enter Last name');
			document.input1.lname.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.usernamex && document.input1.usernamex.value == '')
		{
			
			alert('Please enter username');
			document.input1.usernamex.focus();
			erorxxx++;
			return false;
		}
	


		
	if(document.input1.email)
	{
		var eml = document.input1.email.value ;
		if(document.input1.email.value == '')
		{
			alert('please enter Email');
			document.input1.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.input1.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	

			if(document.input1.passwordxx && document.input1.passwordxx.value == '' )
		{
			alert('please enter password');
			document.input1.passwordxx.focus();
			erorxxx++;
			return false;
		}
		
		
		if(document.input1.password3 && document.input1.password3.value=='' )
		{
		alert("Please Confirm your password");
		document.input1.password3.focus();
		erorxxx++;
		return false;
		}
		if(document.input1.passwordxx && document.input1.passwordxx.value!='' 
		   && document.input1.password3 && document.input1.password3.value!='')
		{
			if(document.input1.passwordxx.value!=document.input1.password3.value)
			{
			alert("Your Passwords Are Not Equal");
			document.input1.password3.focus();
			erorxxx++;
			return false;
			}
		}
			


		if(document.input1.check1 && document.input1.check1.value == '' )
		{
			alert('please enter Your Date of Birth');
			document.input1.check1.focus();
			erorxxx++;
			return false;
		}
	
		if(document.input1.country && document.input1.country.value == '' )
		{
			alert('please enter Country');
			document.input1.country.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.randomm && document.input1.randomm.value == '' )
		{
			alert('please enter Validation Code');
			document.input1.randomm.focus();
			erorxxx++;
			return false;
		}
		
		
		if(document.input1.agreed ) 
		{
			//alert('there is such a form');
			if(document.input1.agreed && ! document.input1.agreed.checked) 
			{
			alert('You Must agree to terms and conditions');
			
			erorxxx++;
			return false;
			}
			else if(document.input1.agreed && document.input1.agreed.checked) 
			{
			return true;
			}

		}
	
	if(erorxxx < 1)
	{
	return true;
	}
		
	
	
	
}



function validateRegx2()
{
	var erorxxx = 0;
		if(document.input1.usernamex && document.input1.usernamex.value == '')
		{
			
			alert('Please enter username');
			document.input1.usernamex.focus();
			erorxxx++;
			return false;
		}
	

		if(document.input1.passwordx && document.input1.passwordx.value == '' )
		{
			alert('please enter password');
			document.input1.passwordx.focus();
			erorxxx++;
			return false;
		}
	if(document.input1.email)
	{
		var eml = document.input1.email.value ;
		if(document.input1.email.value == '')
		{
			alert('please enter Email');
			document.input1.email.focus();
			erorxxx++;
			return false;
		}
		else
		{
			if (echeck(eml)==false)
			{
				alert('please enter a valid Email');
				document.input1.email.focus();
				erorxxx++;
				return false;
			}
		}
	}
	
		if(document.input1.name && document.input1.name.value == '' )
		{
			alert('please enter First name');
			document.input1.name.focus();
			erorxxx++;
			return false;
		}
		
		if(document.input1.lname && document.input1.lname.value == '' )
		{
			alert('please enter Last name');
			document.input1.lname.focus();
			erorxxx++;
			return false;
		}
	
	if(erorxxx < 1)
	{
	//test();	
	document.input1.submit();
	return true;

	
	}
		
	
	
	
}


function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


