//-----------------------------------------------------------------------------------------------------
//gen functions
//-----------------------------------------------------------------------------------------------------
function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//-----------------------------------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//-----------------------------------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}

function refreshCaptcha(imgid)
{
	var img = new Image();
	img.src = 'captcha/show_captcha.php?hash='+parseInt(Math.random() * 10000000000);
	document.getElementById(imgid).src = img.src;
}


$(document).ready(function() {
	$('#biz_account').hover(function(){
			$(this).stop().animate({height: "138px", marginTop: "0px"}, 400);
		},
		function(){
			$(this).stop().animate({height: "29px", marginTop: "109px"}, 400);
		}
		);
	$('#pers_account').hover(function(){
			$(this).stop().animate({height: "138px", marginTop: "0px"}, 400);
		},
		function(){
			$(this).stop().animate({height: "29px", marginTop: "109px"}, 400);
		}
		);
	$('#loan').hover(function(){
			$(this).stop().animate({height: "138px", marginTop: "0px"}, 400);
		},
		function(){
			$(this).stop().animate({height: "29px", marginTop: "109px"}, 400);
		}
		);
	$('#community').hover(function(){
			$(this).stop().animate({height: "138px", marginTop: "0px"}, 400);
		},
		function(){
			$(this).stop().animate({height: "29px", marginTop: "109px"}, 400);
		}
		);
});
//Function for find the position of the scrolling image in all browsers
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function slideDiv(pageURL, index)
{
	$('#menu > a').addClass('mnu');
	if(index != -1)
		$('#menu > a')[index].className = 'mnu_o';
	$('#slide_blk').slideUp(1000, function()
	{
			 $.ajax({
			   type: "GET",
			   data: "page="+pageURL,
			   url: "get_page_content.php"+'?hash='+parseInt(Math.random() * 10000000000),
			   success: function(msg){
				    arrResult = msg.split("<==>");
					$('#slide_blk').html(arrResult[0]);
					$('#slide_blk').slideDown(1000, function(){
							if(pageURL == 'locations.php')
								initialize('33.206356', '-87.565614', '<b>16780 Jordan Street</b><br>Chatom, Alabama 36518<br><b>Phone 251.847.2251</b>');
							if(pageURL == 'business_accounts.php' || pageURL == 'personal_accounts.php')
							{
								document.getElementById('compare_ids').value = '';
								document.getElementById('num_items').value = '0';
								$('#lft_mnu > li').hover(function(){
										$(this).css({backgroundColor: "#500005"});
									    $(this).css("color", "#FFFFFF");
										$(this).animate({opacity:"0.6"}, 500);
									},
									function(){
										$(this).css({backgroundColor: "#111111"});
										$(this).css("color", "#00C4EA");
										$(this).animate({paddingLeft:"10px", width:"240px",opacity:"1"}, 500);
									}
									);
									arrTemp = findPos(document.getElementById('acct_content'));
									cntLft = arrTemp[0] + 100;
									cntTop = arrTemp[1] + 50;
									$('#flying_div1').css({left: cntLft+'px', top: cntTop+'px'});
									$('#flying_div2').css({left: cntLft+'px', top: cntTop+'px'});
									$('#flying_div3').css({left: cntLft+'px', top: cntTop+'px'});
									arrResult1 = arrResult[1].split("||");
									changeContent(arrResult1[0], arrResult1[1]);
							}

						});
			   }
			});
		});
}
function validateContact()
{
	obj = document.frmContact;
	trimFields();
	if(obj.first_name.value == '')
	{
		alert("Please enter your First Name.");
		obj.first_name.focus();
		return;
	}
	if(obj.last_name.value == '')
	{
		alert("Please enter your Last Name.");
		obj.last_name.focus();
		return;
	}
	if(obj.email.value == '')
	{
		alert("Please enter your Email.");
		obj.email.focus();
		return;
	}
	if(!chkEmail(obj.email.value))
	{
		alert("Please enter a valid Email.");
		obj.email.focus();
		obj.email.select();
		return;
	}
	if(obj.confirm_email.value == '')
	{
		alert("Please Re-enter your Email.");
		obj.confirm_email.focus();
		return;
	}
	if(obj.confirm_email.value != obj.email.value)
	{
		alert("Please make sure that Email should be same as \"Re-enter Email\".");
		obj.confirm_email.focus();
		obj.confirm_email.select();
		return;
	}
	if(obj.comment.value == "")
	{
		alert("Please enter your Comments/Questions.");
		obj.comment.focus();
		return;
	}
	if(obj.captcha.value == "")
	{
		alert("Please type the Alphanumeric values shown.");
	}
	params = 'first_name='+obj.first_name.value;
	params+= '&last_name='+obj.last_name.value;
	params+= '&email='+obj.email.value;
	params+= '&subject='+obj.subject.value;
	params+= '&comment='+obj.comment.value;
	params+= '&captcha='+obj.captcha.value;
	$('#sloader_blk').css("display", "block");
	 $.ajax({
	   type: "POST",
	   data: params,
	   url: "submit_contact.php",
	   success: function(msg){
			if(msg == 'CAPTCHA_ERROR')
			{
				document.getElementById('submitmsg_blk').innerHTML = 'Sorry the Captcha Number you entered is incorrect.<br>Please enter the new number shown.';
			}
			else
			{
				document.getElementById('submitmsg_blk').innerHTML = msg;
				obj.first_name.value = '';
				obj.last_name.value = '';
				obj.email.value = '';
				obj.confirm_email.value = '';
				obj.subject.value = '';
				obj.comment.value = '';
				obj.captcha.value = '';
			}
			$('#sloader_blk').css("display", "none");
	   	}
	   });


}

function validateStatement()
{
	obj = document.frmStatement;
	trimFields();
	if(obj.date.value == '')
	{
		alert("Please enter the Date.");
		obj.date.focus();
		return;
	}
	if(obj.full_name.value == '')
	{
		alert("Please enter your Full Name.");
		obj.full_name.focus();
		return;
	}
	if(obj.account_number1.value == '')
	{
		alert("Please enter at least Account Number1.");
		obj.account_number1.focus();
		return;
	}
	if(obj.account_number1.value != '' && obj.account_type1.value == '')
	{
		alert("Please enter the Account Type1.");
		obj.account_type1.focus();
		return;
	}
	if(obj.account_number2.value != '' && obj.account_type2.value == '')
	{
		alert("Please enter the Account Type2.");
		obj.account_type2.focus();
		return;
	}
	if(obj.account_number3.value != '' && obj.account_type3.value == '')
	{
		alert("Please enter the Account Type3.");
		obj.account_type3.focus();
		return;
	}
	if(obj.email_address.value == '')
	{
		alert("Please enter your Email Address.");
		obj.email_address.focus();
		return;
	}
	if(!chkEmail(obj.email_address.value))
	{
		alert("Please enter a valid Email Address.");
		obj.email_address.focus();
		obj.email_address.select();
		return;
	}
	if(obj.customer_name.value == '')
	{
		alert("Please enter your Full Name.");
		obj.customer_name.focus();
		return;
	}
	if(obj.full_name.value != obj.customer_name.value)
	{
		alert("Full Name must be same as Customer Name.");
		obj.customer_name.focus();
		return;
	}
	params = 'date='+obj.date.value;
	params+= '&full_name='+obj.full_name.value;
	params+= '&account_number1='+obj.account_number1.value;
	params+= '&account_number2='+obj.account_number2.value;
	params+= '&account_number3='+obj.account_number3.value;
	params+= '&account_type1='+obj.account_type1.value;
	params+= '&account_type2='+obj.account_type2.value;
	params+= '&account_type3='+obj.account_type3.value;
	params+= '&email_address='+obj.email_address.value;
	params+= '&home_phone='+obj.home_phone.value;
	params+= '&business_phone='+obj.business_phone.value;
	params+= '&cell_phone='+obj.cell_phone.value;
	params+= '&customer_name='+obj.customer_name.value;
	$('#loader_blk')[0].innerHTML = '<img src="images/ajax-loader.gif" style="vertical-align:middle"> Please wait...';
	 $.ajax({
	   type: "POST",
	   data: params,
	   url: "submit_request.php",
	   success: function(msg){
				document.getElementById('submitmsg_blk').innerHTML = msg;
				$('#loader_blk')[0].innerHTML = '<a href="javascript:void(0)" onclick="validateStatement()"><img src="images/btn_submit1.gif" style="border:0px" alt="Submit" title="Submit"></a> <a href="javascript:void(0)" onclick="self.location=\'index.php\'"><img src="images/btn_cancel.gif" style="border:0px" alt="Cancel" title="Cancel"></a>';
				obj.full_name.value = '';
				obj.account_number1.value = '';
				obj.account_number2.value = '';
				obj.account_number3.value = '';
				obj.account_type1.value = '';
				obj.account_type2.value = '';
				obj.account_type3.value = '';
				obj.email_address.value = '';
				obj.home_phone.value = '';
				obj.business_phone.value = '';
				obj.cell_phone.value = '';
				obj.customer_name.value = '';
				window.scrollTo(0,0);
			}
	   });

}
function validateOptin()
{
	obj = document.frmOptin;
	trimFields();
	if(obj.is_agree.checked == false)
	{
		alert("Please accept the above Terms and Conditions.");
		obj.is_agree.focus();
		return;
	}
	if(obj.printed_name.value == '')
	{
		alert("Please enter your Printed Name.");
		obj.printed_name.focus();
		return;
	}
	if(obj.date.value == '')
	{
		alert("Please enter the Date.");
		obj.date.focus();
		return;
	}
	if(obj.account_number.value == '')
	{
		alert("Please enter your Account Number.");
		obj.account_number.focus();
		return;
	}
	params = 'date='+obj.date.value;
	params+= '&printed_name='+obj.printed_name.value;
	params+= '&account_number='+obj.account_number.value;
	$('#loader_blk')[0].innerHTML = '<img src="images/ajax-loader.gif" style="vertical-align:middle"> Please wait...';
	 $.ajax({
	   type: "POST",
	   data: params,
	   url: "submit_option.php",
	   success: function(msg){
				document.getElementById('submitmsg_blk').innerHTML = msg;
				$('#loader_blk')[0].innerHTML = '<a href="javascript:void(0)" onclick="validateOptin()"><img src="images/btn_submit1.gif" style="border:0px" alt="Submit" title="Submit"></a> <a href="javascript:void(0)" onclick="self.location=\'index.php\'"><img src="images/btn_cancel.gif" style="border:0px" alt="Cancel" title="Cancel"></a>';
				obj.printed_name.value = '';
				obj.account_number.value = '';
				window.scrollTo(0,0);
			}
	   });

}
function confirmation()
{
	if(confirm("Capstone Bank has no control over information at any site hyperlinked to from this site.Capstone Bank makes no representation concerning and is not responsible for the quality, content,nature, or reliability of any hyperlinked site and is providing this hyperlink to you only as a convenience.The inclusion of any hyperlink does not imply any endorsement, investigation, verification or monitoring by Capstone Bank of any information in any hyperlinked site.  In no event shall Capstone Bank be responsible for your use of a hyperlinked site.\n\n\t\t\t\t\t\t\tDo you want to continue?"))
	{
		window.open('http://www.then9neagency.com','mywindow','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,		resizable=yes')
		return true;

	}
	return false;
}

