var errorflag = true;
var errorflag2 = true;
$(document).ready(function () {

var getlanguage = document.setLang.language.value ;
		$(".menu_absolute").hover(
		function() {
			if( $(this).is(":animated") ){
				//alert("YES");
			}
			else
			{
				$(this).animate({"opacity": "0"}, 200);
			}
		},
		function() {
		$(this).animate({"opacity": "1"}, 200);
		});



		$(".button_strip_whydo a").click(
		function() {
			var tabwhydo = $(this).attr('id');
			var whydodescription = "";

			switch(tabwhydo)
			{
			case 'itsaves':
			  $('.center_heading img').attr('src','/'+getlanguage+'/images/hd_it_save_you_money.gif');
			  $('.center_heading img').attr('alt','It save you money');

			  break;
			case 'itssafe':
			  $('.center_heading img').attr('src','/'+getlanguage+'/images/hd_its_safe.gif');
			  $('.center_heading img').attr('alt','It safe');

			  break;
			case 'itsconvenient':
			  $('.center_heading img').attr('src','/'+getlanguage+'/images/hd_its_convenient.gif');
			  $('.center_heading img').attr('alt','Its convenient');

			  break;
			case 'ithelpsu':
			  $('.center_heading img').attr('src','/'+getlanguage+'/images/hd_it_helps_you.gif');
			  $('.center_heading img').attr('alt','It help you');

			  break;
			default:
			  $('.center_heading img').attr('src','/'+getlanguage+'/images/hd_it_save_you_money.gif');
			  $('.center_heading img').attr('alt','It save you money');

			}



			$(".center_txt_out div").fadeOut();
			$("#"+tabwhydo+"_txt").fadeIn();

//			$(".center_txt_out").slideDown().append(whydodescription);
		});


// Partner page / About us script
		$(".partnermenu_absolute").hover(
		function() {
			if( $(this).is(":animated") ){
				//alert("YES");
			}
			else
			{
				$(this).animate({"opacity": "0"}, 10);
			}
		},
		function() {
		$(this).animate({"opacity": "1"}, 10);
		});


		$("#partner_menus li a").click(
		function() {

			var tabpartner = $(this).attr('id');
			var enablepartnerbox="";

			$("#partner_menus li a").find('img:first').removeClass('deactivebox');
			$(this).find('img:first').addClass('deactivebox');


			$(".partner_txt_out").children("div").hide();
			$("#"+tabpartner+"_txt").fadeIn('fast');


		});

//  END Partner / About us page script



// Press News page script
	 //newsprocess()
// End Press News page script

	$('input').checkBox(); 




		$(".topmenu_absolute").hover(
		function() {
			if( $(this).is(":animated") ){
				//alert("YES");
			}
			else
			{
				$(this).animate({"opacity": "0"}, 200);
			}
		},
		function() {
		$(this).animate({"opacity": "1"}, 200);
		});







		$('#signup_fin').submit(function() {
			var errorflag = true;
			var emailFilter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			var getform = document.signup_fin;
			var getemail = getform.email.value;

			  if (getform.name.value==""){
				  validatestyle('invalid','errname',getform.name)
				  errorflag = false;}
			  else
				  validatestyle('valid','errname',getform.name)

			  if (getform.street.value==""){
				  validatestyle('invalid','errstreet',getform.street)
				  errorflag = false;}
			  else
				  validatestyle('valid','errstreet',getform.street)

			  if (getform.city.value==""){
				  validatestyle('invalid','errcity',getform.city)
				  errorflag = false;}
			  else
				  validatestyle('valid','errcity',getform.city)

			  if (getform.organization.value==""){
				  validatestyle('invalid','errorg',getform.organization)
				  errorflag = false;}
			  else
				  validatestyle('valid','errorg',getform.organization)

			  if (getform.state.value==""){
				  validatestyle('invalid','errstate',getform.state)
				  errorflag = false;}
			  else
				  validatestyle('valid','errstate',getform.state)

			  if (getform.zip.value==""){
				  validatestyle('invalid','errzip',getform.zip)
				  errorflag = false;}
			  else
				  validatestyle('valid','errzip',getform.zip)

			  if (getform.phone.value==""){
				  validatestyle('invalid','errphone',getform.phone)
				  errorflag = false;}
			  else
				  validatestyle('valid','errphone',getform.phone)

			if (IsNumeric(getform.phone.value)==false){
				  validatestyle('invalid','errphone',getform.phone)
				  errorflag = false;}
			  else
				  validatestyle('valid','errphone',getform.phone)


			if ( !(emailFilter.test(getemail)) )
			{ 
				  validatestyle('invalid','erremail',getform.email)
					  errorflag = false;
			}
			  else
				  validatestyle('valid','erremail',getform.email)

			  if(errorflag && getemail!='')
				{
						$.post("submitform.php", { formtype: "partner_fin", name: getform.name.value, street: getform.street.value, city: getform.city.value, organization: getform.organization.value, title: getform.title.value, state: getform.state.value, zip: getform.zip.value, phone: getform.phone.value, email: getform.email.value, comments: getform.comments.value  },
						   function(data){
							if(data=='SUCCESS'){
								$('#signup_fin').html("");
								if(getlanguage=="es")
									$('#signup_fin').append("<strong>ˇGracias por tu interés en convertirte un Socio Cuenta con Manhattan! Un representante de Cuenta con Manhattan se comunicará contigo muy pronto.</strong>");
								else
									$('#signup_fin').append("<strong>Thank you for your interest in becoming a Bank On Manhattan Partner! A Bank On Manhattan representative will contact you shortly..</strong>");
							}
							if(data=='FAILED')
							{
								if(getlanguage=="es")
									$('#signup_fin').prepend("<strong>LO SENTIMOS, hubo un error. Por favor intenta nuevamente.</strong>");
								else
									$('#signup_fin').prepend("<strong>SORRY, there is some Error. Please try again.</strong>");
							}
						   });
				}
		  return false;
		});



		$('#signup_comm').submit(function() {
			errorflag2 = true;
			var emailFilter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			var getform = document.signup_comm;
			var getemail = getform.cemail.value;

			  if (getform.cname.value=="")
				  validatestyle('invalid','errcname',getform.cname)
			  else
				  validatestyle('valid','errcname',getform.cname)

			  if (getform.cstreet.value=="")
				  validatestyle('invalid','errcstreet',getform.cstreet)
			  else
				  validatestyle('valid','errcstreet',getform.cstreet)

			  if (getform.ccity.value=="")
				  validatestyle('invalid','errccity',getform.ccity)
			  else
				  validatestyle('valid','errccity',getform.ccity)

			  if (getform.corganization.value=="")
				  validatestyle('invalid','errcorg',getform.corganization)
			  else
				  validatestyle('valid','errcorg',getform.corganization)

			  if (getform.cstate.value=="")
				  validatestyle('invalid','errcstate',getform.cstate)
			  else
				  validatestyle('valid','errcstate',getform.cstate)

			  if (getform.czip.value=="")
				  validatestyle('invalid','errczip',getform.czip)
			  else
				  validatestyle('valid','errczip',getform.czip)

			  if (getform.cphone.value=="")
				  validatestyle('invalid','errcphone',getform.cphone)
			  else
				  validatestyle('valid','errcphone',getform.cphone)


			if (IsNumeric(getform.cphone.value)==false)
				  validatestyle('invalid','errcphone',getform.cphone)
			  else
				  validatestyle('valid','errcphone',getform.cphone)


			  if ( !(emailFilter.test(getemail)) )
			{ 
				  validatestyle('invalid','errcemail',getform.cemail)
			}
			  else
				  validatestyle('valid','errcemail',getform.cemail)

			  if(errorflag2 && getemail!='')
				{
						$.post("submitform.php", { formtype: "partner_community", name: getform.cname.value, street: getform.cstreet.value, city: getform.ccity.value, organization: getform.corganization.value, title: getform.ctitle.value, state: getform.cstate.value, zip: getform.czip.value, phone: getform.cphone.value, email: getform.cemail.value, comments: getform.ccomments.value  },
						   function(data){
							if(data=='SUCCESS'){
								$('#signup_comm').html("");
								if(getlanguage=="es")
									$('#signup_comm').append("<strong>ˇGracias por tu interés en convertirte un Socio Cuenta con Manhattan! Un representante de Cuenta con Manhattan se comunicará contigo muy pronto.</strong>");
								else
									$('#signup_comm').append("<strong>Thank you for your interest in becoming a Bank On Manhattan Partner! A Bank On Manhattan representative will contact you shortly..</strong>");

							}
							if(data=='FAILED')
							{
								if(getlanguage=="es")
									$('#signup_comm').prepend("<strong>LO SENTIMOS, hubo un error. Por favor intenta nuevamente.</strong>");
								else
									$('#signup_comm').prepend("<strong>SORRY, there is some Error. Please try again.</strong>");
							}
						   });
				}
		  return false;
		});



		$('#calcsavingbtn').click(function() {
			var getinfo = $('#savingcalc_ans').html();
			calcSavings(document.formSavCalc, "savingcalc_ans") ;
		});



// Participating bank us script
		$(".participating_logo").click(function() {
			var tabpartner = $(this).attr('id');
			var enablepartnerbox="";

			//$("#participatingpages").children("div").hide();
			//$("#"+tabpartner+"_box").fadeIn('fast');
			$("#participatingpages").children("div").fadeIn('fast');



			$('html, body').animate({
					scrollTop: $("#"+tabpartner+"_box").offset().top
					}, 1000);


		});

		$(".icon_top").click(function() {
			$('html, body').animate({
					scrollTop: $(".privacy_txt").offset().top
					}, 1000);


		});



//  END Participating bank  page script


// bank locator
	$('#errrecac').hide();
	$('#errloc').hide();
	$('#errdeposite').hide();
	$('#err_ac').hide();
	$('#errfee').hide();

});

/* END Document Ready */






function validatestyle(errstatus, errid, fieldname)
{
	if(errstatus=='invalid')
	{
				  $("#"+errid).fadeIn();  errorflag = false; errorflag2 = false; fieldname.style.borderColor  = "#FF3333"; 
	}
	else
	{
				  $("#"+errid).fadeOut(); fieldname.style.borderColor  = "#59B0E3";
	}
}



function newsprocess(){
			   $.post("about-us/getnews-list.php", 
			   function(data){
				$('#leftnav_tab4_txt').html("");
				$('#leftnav_tab4_txt').append(data);

					$("#newslist li a").click(
					function() {

						var getnews = $(this).attr('title');

						$.post("about-us/getnews.php", { news: getnews },
						   function(data){
							$('#leftnav_tab4_txt').html("");
							$('#leftnav_tab4_txt').append(data);
						   });
					});
			   });

};


	function english()
	{		
		document.setLang.language.value = "en";
		document.setLang.next.value = "../../index";
	  	document.setLang.submit();
	}
	function espanol()
	{		
		document.setLang.language.value = "es";
		document.setLang.next.value = "../../index";
	  	document.setLang.submit();
	}


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function checkbankloc(formobj) {
		validchecked = true;

		if (formobj.smallFee[0].checked==false && formobj.smallFee[1].checked==false ) {
			$('#errfee').fadeIn();
			validchecked = false;
		}
		else
			$('#errfee').fadeOut();


		if (formobj.closed[0].checked==false && formobj.closed[1].checked==false ) {
			$('#err_ac').fadeIn();
			validchecked = false;
		}
		else
			$('#err_ac').fadeOut();


		if (formobj.openingDeposit[0].checked==false && formobj.openingDeposit[1].checked==false  && formobj.openingDeposit[2].checked==false  && formobj.openingDeposit[3].checked==false ) {
			$('#errdeposite').fadeIn();
			validchecked = false;
		}
		else
			$('#errdeposite').fadeOut();

		if (formobj.zipcode.value=="" || formobj.miles.value=="" || formobj.miles.value<=0 ) {
			$('#errloc').fadeIn();
			validchecked = false;
		}
		else
			$('#errloc').fadeOut();

		var chks_ac = document.getElementsByName('actype[]');
		if (chks_ac[0].checked==false && chks_ac[1].checked==false  && chks_ac[2].checked==false  && chks_ac[3].checked==false ) {
			$('#errrecac').fadeIn();
			validchecked = false;
		}
		else
			$('#errrecac').fadeOut();


		return validchecked;
}


