﻿
    //<reference path="mootools.js">
    //<reference path="overlay.js">

    function getViewport(){
		
		var  width;
 		var  height;
 
	 	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
		 if (typeof window.innerWidth != 'undefined')
		 {
			  width = window.innerWidth,
			  height = window.innerHeight
		 }
		 
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		 else if (typeof document.documentElement != 'undefined'
			 && typeof document.documentElement.clientWidth !=
			 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   width = document.documentElement.clientWidth,
			   height = document.documentElement.clientHeight
		 }
		 
		 // older versions of IE
		 else
		 {
			   width = document.getElementsByTagName('body')[0].clientWidth,
			   height = document.getElementsByTagName('body')[0].clientHeight
		 }
		 
		 
		 var viewport = new Object();
		 viewport.width = width;
		 viewport.height = height;
		 
		 return viewport;
	};

	function translateEvent(e){
		var ev= (window.event)? window.event: e;
		if(!ev || !ev.type) return false;
		var ME= ev;
		
		if(ME.type.indexOf('key')!= -1){
			if(ME.type.indexOf('keypress')!= -1){
				ME.key= (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which);
			}
			else ME.key= ev.charCode;
			if(ME.key) ME.letter= String.fromCharCode(ME.key);
		}
		return ME;
	};


	function getStyleObject(objectId) {
	 
		if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
		} else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
		} else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
		} else {
			return false;
		}
	}; // getStyleObject


	String.prototype.trim = function()
	{
		return this.replace(/^\s+|\s+$/g,"");
	};

	function isValidZipCode(value) 
	{
   		var re = /^\d{5}([\-]\d{4})?$/;
   		return (re.test(value));
	};
	
	function PopUp()
	{  
		this.content = "";
		this.content2=null;
		this.innerDom = "";
		this.Height = "150px";
		this.Width = "300px";
		this.XboxClass = 'SimpleInputBoxClose';
		this.forceResize= function(){
			var winW = ""; var winH = "";
			
			var st = getStyleObject("simpleDlg");
			var viewport = getViewport();

			winW = viewport.width;
			winH = viewport.height;

				
			 if (document.layers)
			 {
				st.left=winW/2 - (this.Height.replace(/px/,"")/2 + 30);
				st.top= winH/2 - (this.Width.replace(/px/,"")/2 + 100);
			 }
			 else 
			 {
				st.left=winW/2 - (this.Height.replace(/px/,"")/2 + 30)+"px";
				st.top= winH/2 - (this.Width.replace(/px/,"")/2 + 100)+"px";
			 }
		}
	};
	
	PopUp.OK = "OK";
	PopUp.CANCEL = "CANCEL";
	
	PopUp.prototype.show = function(callback, w,h)
	{
		if(w && h){
			this.Height = h;
			this.Width = w;
		}
		var clb = callback;
	    
	    var a = new Overlay();
        a.show();
		
		this.innerDom = new Element('div').setProperty('id', 'innerDom');
	 
	 	var o = new Element('div').setProperty('id', 'simpleDlg').setStyles({
			position: 'absolute',
			left:window.screen.width/2 - (this.Width.replace(/px/,"")/2+ 30),
			top: window.screen.height/2 - (this.Height.replace(/px/,"")/2 + 100),
			width: this.Width,
			height:this.Height,
			zIndex: 9999,
			backgroundColor: '#FFF'
		});	
		
		if(this.content2 == null)
			o.innerHTML = this.content;
		 else
			o.appendChild(this.content2);
			
		var WW = this.Height;
		var HH = this.Width;
		var XClass = this.XboxClass;
		var resize = function(){
			var winW = ""; var winH = "";
			
			var st = getStyleObject("simpleDlg");
			var viewport = getViewport();

			winW = viewport.width;
			winH = viewport.height;

				
			 if (document.layers)
			 {
				st.left=winW/2 - (HH.replace(/px/,"")/2 + 30);
				st.top= winH/2 - (WW.replace(/px/,"")/2 + 100);
			 }
			 else 
			 {
				st.left=winW/2 - (HH.replace(/px/,"")/2 + 30)+"px";
				st.top= winH/2 - (WW.replace(/px/,"")/2 + 100)+"px";
			 }
		};

		window.onresize = resize;
		
		var f = function(){
			
			o.injectInside(document.body);
			SetFocusToFirstPossibleInput();
			this.closeButton = new Element('div').addClass(XClass).injectInside(o);
			this.closeButton.onclick = function(){CloseBox();};
			
			this.okButton = o.getElementById('_ok_');
			if(this.okButton){
				this.okButton.onclick = function(){preCallbackHook(o.getElementById('_zip_').value)};
				
			}
		
			window.scrollTo(0,0);
			resize();
		};
		  
		setTimeout(f,600);
			
		function SetFocusToFirstPossibleInput(){
			var firstInput = o.getElementsByTagName('input');
			if(firstInput){
				for(var i = 0;i<firstInput.length;i++){
					var type = firstInput[i].getAttribute("type");
					if(type == "text" || type == "button"){
						firstInput[i].focus();
						break;
					}
				}
			}
		};
		
		function preCallbackHook(msg)
	 	{
			if(clb){
			    var r = clb(msg);
				if(r)
					setTimeout(CloseBox,3000);
			}
		  	else{
				
				 setTimeout(CloseBox,3000);
			}
	 	};

        var CloseBox = function()
        {
        	a.hide()
	       	o.empty();
	       	o.remove();
			showSelects();
			document.body.onresize = null;
			if(window.ie6  === true) {
			$('selectBox').style.display = 'block';
			}
			 
        };
		
		this.close = function(){
			CloseBox();	
			
		};
	 	
	 	function hideSelects()
        {
	        var oSelects=document.getElementsByTagName("select");
	        for(var i=0;i<oSelects.length;i++)
	        oSelects[i].className+="hide";
        };



        function showSelects()
        {
	        var oSelects=document.getElementsByTagName("select");
	        for(var i=0;i<oSelects.length;i++)
	        oSelects[i].className=oSelects[i].className.replace("hide","");
        };

	};
	
	var PleaseWait2 = new Class({
		 
		initialize:function(txt){
			var outter = new Element('div');
			var span = new Element('div');
			span.setStyle('float','left');
			span.inject(outter);
			var div = new Element("div");
			div.setStyle('float','left');
			div.setProperty("id","dyn");
			div.inject(outter);
			var d = ["",".","..","..."];
			var i = 0;
			(function(){
				if(div && div.setText){
					div.setText(txt + " " + d[i]);
					i++;
					if(i > d.length -1)
					i = 0;
				}
			}).periodical(500);
			
			return outter;
		}
		
		
	});
	
	UserMessage.prototype =  new PopUp();
	UserMessage.prototype.constructor = UserMessage;  
	 
	function UserMessage(){this.XboxClass = 'SimpleInputBoxClose3'; this.Height = "50px";};

	UserMessage.prototype.show = function(clb)
	{
		 var div = new Element('div');
		 div.setStyle('height','50px');
		 div.addClass('boxContainer');
		 div2 = new Element('div');
		 div2.addClass("box");
		 div2.inject(div);
		 var pw = new PleaseWait2("Please wait while we retrieve your policy information");
		 pw.setStyle('padding','10px');
		 pw.inject(div2);
		 this.content2 = div; 
		 
		 PopUp.prototype.show.call(this,clb); 
	};
	
	
	
	
	CantSeePolicyHelp.prototype =  new PopUp();
	CantSeePolicyHelp.prototype.constructor = CantSeePolicyHelp;
	
	function CantSeePolicyHelp(){if(window.ie6  === true) {$('selectBox').style.display = 'none';}};

	CantSeePolicyHelp.prototype.show = function(agentid,clb)
	{
		 var div = new Element('div');
		 div.addClass('boxContainer');
		 div2 = new Element('div');
		 div2.addClass("box");
		 div2.inject(div);
		 var pw = new Element('div');
		 pw.setText("You must be listed as the policy owner to view the policy detail. If you are listed on the policy, but not the owner, you may still make an online payment.");
		 
		 var t1 = new Element("div");
		 t1.setText("If you have any questions, please ");
		 t1.setStyle('padding-top','10px');
		 
		 pw.setStyle('padding','5px');
		 
		 pw.inject(div2);
		 
		 var lnk = new Element("a");
		 lnk.setAttribute("href","/fbfs/contact/aol/agt1p4.cfm?AgID=" + agentid);
		 lnk.setText("contact your agent");
		 pw.adopt(t1);
		 pw.adopt(lnk);
		 
		 var t2 = new Element("div");
		 
		 t2.setText("or call a customer service representative Monday - Friday 8:00 a.m. - 4:30 p.m. Central Time at (800) 814-5570.");
		 pw.adopt(t2);
		 
		 this.content2 = div; 
		 
		 PopUp.prototype.show.call(this,clb); 
	};
	
	
	ProofOfInsuranceMessageBox.prototype =  new PopUp();
	ProofOfInsuranceMessageBox.prototype.constructor = ProofOfInsuranceMessageBox;
	
	function ProofOfInsuranceMessageBox(email,onOk){
		this.email = email
		this.onOk = onOk;
	    this.XboxClass = 'SimpleInputBoxClose2';
		if(window.ie6  === true) {
		$('selectBox').style.display = 'none';
		}
	};
	
	ProofOfInsuranceMessageBox.prototype.show = function(agentid,clb)
	{
		 var div = new Element('div');
		 div.setStyle('height','160px');
		 div.addClass('boxContainer');
		 div2 = new Element('div');
		 div2.addClass("box");
		 div2.inject(div);
		 var pw = new Element('p');
		 
		 pw.setText("You are requesting a copy of proof of insurance for your vehicle. If you would like us to " + 
									   "process this request please hit \"OK.\" If not, please hit \"Cancel.\" If you choose to " +
									   "continue, within 24 hours, you will receive your proof of insurance via e-mail at the address " +
									   "listed in your profile, " + this.email);
		 pw.setStyle('padding','4px');
		 
		 pw.inject(div2);
		 
		 var ok = new Element("input");
		 ok.setAttribute("type","button");
		 ok.setAttribute("value","  OK  ");
		 ok.setStyle('margin-right','5px');
		 
		 var cancel = new Element("input");
		 cancel.setAttribute("type","button");
		 cancel.setAttribute("value","Cancel");
		 cancel.setStyle('margin-right','5px');
		 
		 var btnDiv = new Element("div");
		 btnDiv.setStyle("float","right");
		 btnDiv.setStyle("padding-top","15px");
		 ok.inject(btnDiv);
		 cancel.inject(btnDiv);
		
		 ok.addEvent('click',this.onOk);
		 cancel.addEvent('click',function(){this.close()}.bind(this));
		  btnDiv.inject(pw);
		
		 
		 this.content2 = div; 
		 
		 PopUp.prototype.show.call(this,clb); 
	};
	
	

	SimpleInputBox.prototype =  new PopUp();
	SimpleInputBox.prototype.constructor = SimpleInputBox;
	
	function SimpleInputBox(){};
	 
	SimpleInputBox.prototype.show = function(clb)
	{
		this.content = "<div class='boxContainer'><div class='box'><div style='padding:10px;'>You can count on Farm Bureau Financial Services to help you make important decisions about your future.  We provide a variety of products and services throughout a 15-state area.  Please enter your ZIP code below to learn what's available in your area.</div><div id='searchform3'><strong>Enter your ZIP Code:&nbsp;</strong><input type='text' id='_zip_' name='_zip_' onkeypress ='if(event.keyCode==13)okButton.onclick()'/><a style='cursor:pointer;' target='_parent' class='button3' id='_ok_' name='_ok_'></a></div></div></div>";;
		
		PopUp.prototype.show.call(this,clb); 

	};
	
	
	
	
	
	
	OnlineClaimMessage.prototype =  new PopUp();
	OnlineClaimMessage.prototype.constructor = OnlineClaimMessage;
	function OnlineClaimMessage(){};
	OnlineClaimMessage.prototype.setContent= function(cnt){
	 	this.content=document.getElementById(cnt).innerHTML;
	};
	OnlineClaimMessage.prototype.show = function(clb){
		PopUp.prototype.show.call(this,clb); 
	};
	
	OnlineClaimMessage.prototype.toggle = function(c){
		alert(c);
		//alert(document.getElementById("simpleDlg").innerHTML); 
		//flipDiv(document.getElementById(c));
	};
	
	
	PleaseWait.prototype =  new PopUp();
	PleaseWait.prototype.constructor = UserMessage;
	
	function PleaseWait(){};

	PleaseWait.prototype.show = function(clb)
	{
		 this.content =  "<div class='boxContainer'><div class='box'><div style='padding:10px;'>Please wait...</div>";
		 
		 PopUp.prototype.show.call(this,clb); 
	};
	
	
	ThankYouForEmail.prototype =  new PopUp();
	ThankYouForEmail.prototype.constructor = ThankYouForEmail;
	
	function ThankYouForEmail(){ this.XboxClass = 'SimpleInputBoxClose1';};

	ThankYouForEmail.prototype.show = function(clb)
	{
		 this.content =  "<div class=\"box\" style=\"background-color:#e2dbc8; border:solid 10px #ffffff; height:195px;" + "background-image:url(/fbfs/images/emailthankyou.jpg); background-repeat:no-repeat; background-position:right; height:195px; width:400px;\">" +
"<div style=\"padding:10px; margin-right:200px; line-height:15px;\">Thank you for completing the e-mail registration form. " + 
"We look forward to providing you with valuable information to meet your financial goals." +
"<div id='searchform4' style='padding-top:20px;'><a style='cursor:pointer;' target='_parent' class='buttonx' id='_ok_' name='_ok_'></a></div></div></div></div>";
		
		 PopUp.prototype.show.call(this,clb); 
	};