﻿/*
          _____    ____   __  __  ______   ____          
         |  __ \  / __ \ |  \/  ||  ____| / __ \       
         | |__) || |  | || \  / || |__   | |  | |      
         |  _  / | Mr-ROMEO@Hotmail.com  | |  | |   
         | | \ \ | |__| || |  | || |____ | |__| |       
         |_|  \_\ \____/ |_|  |_||______| \____/       

*/

$(document).ready(function(){



init()
});


////////////// ValidateModule 
var ErrBorderColor = 'red';
var CorectBorderColor = 'green';
var EmailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
var SenderExp = /^[a-zA-z0-9]{3,11}$/;
var MobileExp = /^[0-9]{9,9}$/;
var NumperExp="[0-9]+[0-9]+[0-9]+[0-9]+[0-9]+[0-9]+[0-9]";
//var ROMEOtest=[A-z];
var ROMEOmessageStan = "Incorect";

function init()
{
	$('input[id=]').attr("id", function (arr) {return "ROMEO-id" + arr;})
	$('textarea[id=]').attr("id", function (arr) {return "ROMEOtextarea-id" + arr;})
	$('[ROMEOtype]').attr('autocomplete','off');
	$('[ROMEOtype=FormSubmit]').bind
	(
		'submit',function()
		{
			$('[ROMEOtype=FormSubmit]').attr("id", function (arr) {return "ROMEOform-id" + arr;})
			return Validat(this);
		}
	);
	$('input[ROMEOtype]').bind('keyup blur',function(){return Validat(this);});
	$('textarea[ROMEOtype]').bind('keyup blur',function(){return Validat(this);});
	
}

function Validat(ID,type,Message)
{
	ROMEOcheck 		= document.getElementById(ID.id);
	ROMEOmessage 	= document.getElementById(ID.id).getAttribute('ROMEOmessage');
	ROMEOtype 		= document.getElementById(ID.id).getAttribute('ROMEOtype');
	if (ROMEOtype=="FormSubmit")
	{
		var theForm = document.forms[ID.id];
		for(i=0; i<theForm.elements.length; i++)
		{
			if (theForm.elements[i].getAttribute('ROMEOtype'))
			{
				if (!theForm.elements[i].getAttribute('ROMEOmessage'))
				{
					theForm.elements[i].setAttribute("ROMEOmessage",ROMEOmessageStan);
				}
				if (checkROMEO(theForm.elements[i].id,theForm.elements[i].getAttribute('ROMEOtype'),theForm.elements[i].getAttribute('ROMEOmessage'))==false)
				{
					alert(theForm.elements[i].getAttribute('ROMEOmessage'));
					ROMEOfocus 		= document.getElementById(theForm.elements[i].id);
					ROMEOfocus.focus();
					return false
				}
			}
		}
	return true
	}else{
		checkROMEO(ID.id,ROMEOtype,ROMEOmessage);
	}

	function checkROMEO(ID,type,Message)
	{
		ROMEOcheck 		= document.getElementById(ID);
		if (type=="TEXT")
		{
			if(!ROMEOcheck.value)
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
			else
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
		}	
				
		if (type=="NUMPER")	
		{
			if(ROMEOcheck.value.match(NumperExp))
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
			else
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
		}
						
		if (type=="EMAIL")
		{
			if(ROMEOcheck.value.match(EmailExp))
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
			else
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
		}
		if (type=="RePASS")
		{
			if($('[name=NewPass]').val()==$('[name=ReNewPass]').val())
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
			else
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
		}
		if (type=="MOBILE")
		{
			if(ROMEOcheck.value > 963911111111 && ROMEOcheck.value < 9639111111110 )
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
			else
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
		}
		if (type=="SENDER")
		{
			if(ROMEOcheck.value.match(SenderExp))
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}
			else
			{
				ROMEOcheck.style.borderColor = ErrBorderColor;
				return false
			}
		}

		if (type=="MESSAGE")
		{
			var MLn;var ML;
			db =$('#'+ID).val().length;
			if(db < 50)
			{
					ROMEOcheck.style.borderColor = ErrBorderColor;
					return false
				
			}
			else
			{
				document.getElementById(ID).style.borderColor = CorectBorderColor;
			}

		}

	

	}	
return true

}



