// JavaScript Document



//user-contact-form.php validation

function submitContactForm(button)

{	

	document.forms["contact_info"].button_clicked.value = button;

	var valid = validateform('contact_info', 'user[name]', 'Name','user[city]', 'City','user[postal]', 'Postal Code' ,'user[residential]', 'Residential #','user[email]', 'Email');

	if(valid){

		document.forms["contact_info"].submit();

	}

}

function submitQuoteForm(form)

{	



		document.forms[form].submit();

	

}

function submitAutoWholeForm(form)

{	



	var valid = validateform(form, 'user[name]', 'Name','user[city]', 'City', 'user[residential]', 'Residential #','user[email]', 'Email','data[month]', 'Birth Month','data[day]', 'Birth Day', 'data[year]', 'Birth Year');

	if(valid){

		document.forms[form].submit();

	}

}

function submitBusinessForm()

{	



	var valid = validateform('commercial_quote', 'data[business_name]', 'Business Name', 'data[phone]', 'Phone (office)','data[email]', 'Email');

	if(valid){

		document.forms['commercial_quote'].submit();

	}

}





// GET Quote.... from old page. //

function getQuote () {

	var myTextField = document.getElementById('request_dropdown');

	if (myTextField.value == "auto") {

	//window.location = "http://www.insuranceondemand.ca/armour/quote/QuoteEditor.aspx?QuoteType=autoquote";

		pageTracker._trackPageview("/armour/app/memberonly/login.aspx?loginType=Auto");

		window.open ("http://www.insuranceondemand.ca/armour/autoinsurance.aspx");

	} else if (myTextField.value == "home") {

		window.open ("http://www.insuranceondemand.ca/armour/homeinsurance.aspx");

		 pageTracker._trackPageview("/armour/app/memberonly/login.aspx?loginType=Home");

	} else if (myTextField.value == "condo") {

		window.open ("http://www.insuranceondemand.ca/armour/condoinsurance.aspx");

		pageTracker._trackPageview("/armour/app/memberonly/login.aspx?loginType=Condo");

	} else if (myTextField.value == "tenants") {

		//window.open ("http://www.insuranceondemand.ca/armour/tenantinsurance.aspx");

		window.open ("http://www.insuranceondemand.ca/armour/tenantinsurance.aspx");

		pageTracker._trackPageview("/app/memberonly/login.aspx?loginType=Tenants");

	} else if (myTextField.value == "travel") {

		window.open ("https://www.travelunderwriters.com/consumerexpress-app/VerifyPartner.b2c?pc=ARM000");

		//window.location="http://www.armourinsurance.ca/request_a_quote/";

		//return false;

	} else if (myTextField.value == "farm") {

		window.location="http://www.armourinsurance.ca/request_a_quote/";

	}

}



	function str_replace(a,b,c){

		return c.split(a).join(b);

	}



	function writeEmail(em, clickable2){

		em = str_replace("[64]","@", em);

		em = str_replace("[46]",".", em);

		em = str_replace("[canada]","ca", em);

		em = str_replace("[commercial]","com", em);

		if(clickable2 == true){

			document.write("<a href='mailto:"+em+"'>"+em+"</a>");

		} else {

			document.write(em);

		}

	}

// End of GET Quote.... from old page. //



// Start of POPUP SCRIPT //

//SETTING UP OUR POPUP

//0 means disabled; 1 means enabled;

var popupStatus = 0;



//loading popup with jQuery magic!

function loadPopup2(){

//loads popup only if it is disabled

if(popupStatus==0){

$("#backgroundPopup2").css({

"opacity": "0.7"

});

$("#backgroundPopup2").fadeIn("slow");

$("#popupContact2").fadeIn("slow");

popupStatus = 1;

}

}



//centering popup

function centerPopup2(){

//request data for centering

var windowWidth = document.documentElement.clientWidth;

var windowHeight = document.documentElement.clientHeight;

var popupHeight = $("#popupContact2").height();

var popupWidth = $("#popupContact2").width();

//centering

$("#popupContact2").css({

"position": "absolute",

"top": windowHeight/2-popupHeight/2,

"left": windowWidth/2-popupWidth/2

});

//only need force for IE6



$("#backgroundPopup2").css({

"height": windowHeight

});



}



function loadPopup3(){

//loads popup only if it is disabled

if(popupStatus==0){

$("#backgroundPopup3").css({

"opacity": "0.7"

});

$("#backgroundPopup3").fadeIn("slow");

$("#popupContact3").fadeIn("slow");

popupStatus = 1;

}

}



//centering popup

function centerPopup3(){

//request data for centering

var windowWidth = document.documentElement.clientWidth;

var windowHeight = document.documentElement.clientHeight;

var popupHeight = $("#popupContact3").height();

var popupWidth = $("#popupContact3").width();

//centering

$("#popupContact3").css({

"position": "absolute",

"top": windowHeight/2-popupHeight/2,

"left": windowWidth/2-popupWidth/2

});

//only need force for IE6



$("#backgroundPopup3").css({

"height": windowHeight

});



}



//disabling popup with jQuery magic!

function disablePopup2(){

//disables popup only if it is enabled

if(popupStatus==1){

$("#backgroundPopup2").fadeOut("slow");

$("#popupContact2").fadeOut("slow");

popupStatus = 0;

}

}

//disabling popup with jQuery magic!

function disablePopup3(){

//disables popup only if it is enabled

if(popupStatus==1){

$("#backgroundPopup3").fadeOut("slow");

$("#popupContact3").fadeOut("slow");

popupStatus = 0;

}

}



$(document).ready(function(){

//following code will be here

//LOADING POPUP

//Click the button event!

$("#button2").click(function(){

//centering with css

centerPopup2();

//load popup

loadPopup2();

});



$("#button3").click(function(){

//centering with css

centerPopup3();

//load popup

loadPopup3();

});



//CLOSING POPUP

//Click the x event!

$("#popupContactClose2").click(function(){

disablePopup2();

});



//Click out event!

$("#backgroundPopup2").click(function(){

disablePopup2();

});



$("#popupContactClose3").click(function(){

disablePopup3();

});



//Click out event!

$("#backgroundPopup3").click(function(){

disablePopup3();

});



});



// End of POPUP SCRIPT //





//FAQ Slider Script //



var slider=function(){

	var array=[]; var speed=10; var timer=10;

	return{

		init:function(t,c){

			var s,ds,l,i,y;

			s=document.getElementById(t); ds=s.getElementsByTagName('div'); l=ds.length; i=y=0;

			for(i=0;i<l;i++){

				var d,did; d=ds[i]; did=d.id;

				if(did.indexOf("header")!=-1){

					y++; d.onclick=new Function("slider.process(this)");

				}else if(did.indexOf("content")!=-1){

					array.push(did.replace('-content','')); d.maxh=d.offsetHeight;

					if(c!=y){d.style.height='0px'; d.style.display='none'}

					else{d.style.display='block'}

				} 

			}

		},

		process:function(d){

			var cl,i; cl=array.length; i=0;

			for(i;i<cl;i++){

				var s,h,c,cd;

				s=array[i]; h=document.getElementById(s+'-header');

				c=s+'-content'; cd=document.getElementById(c); clearInterval(cd.timer);

				if(h==d&&cd.style.display=='none'){

					cd.style.display='block'; this.islide(c,1);

				}else if(cd.style.display=='block'){this.islide(c,-1)}

			}

		},

		islide:function(i,d){var c,m; c=document.getElementById(i); m=c.maxh; c.direction=d; c.timer=setInterval("slider.slide('"+i +"')",timer)},

		slide:function(i){

			var c,m,h,dist; c=document.getElementById(i); m=c.maxh; h=c.offsetHeight;

			dist=(c.direction==1)?Math.round((m-h)/speed):Math.round(h/speed);

			if(dist<=1){dist=1}

			c.style.height=h+(dist*c.direction)+'px'; c.style.opacity=h/c.maxh; c.style.filter='alpha(opacity='+(h*100/c.maxh)+')';

			if(h<2&&c.direction!=1){

				c.style.display='none'; clearInterval(c.timer);

			}else if(h>(m-2)&&c.direction==1){clearInterval(c.timer)}

		}

};}();



//End of FAQ Slider Script



// Form Validation



function validateform() {

	valid = true;

	firstfield = "";

	errormsg = "Please complete the following fields: \n\n";

	var formName = validateform.arguments[0];



	if(typeof(formName) == "object"){

		var formObj = formName;

	} else {

		var formObj = document[formName];

	}



	for(i=1; i < validateform.arguments.length; i += 2) {

	    	var fieldName = validateform.arguments[i];



		if(typeof(formObj[fieldName]) != "undefined"){

			var fieldObj = formObj[fieldName];

		} else {

			alert("ScriptError: "+fieldName+" is missing in the form");

			return false;

		}

	

		var displayName = validateform.arguments[i+1];

		if (fieldObj.type == "text" || fieldObj.type == "select-one" || fieldObj.type == "password") {

			if (fieldObj.value == "") {

				valid = false;

				errormsg += "- "+displayName + "\n";

				if(firstfield == ""){

					firstfield = fieldObj;

				}

			}

		

			//Check to ensure a valid email address has been entered

			if ((fieldName == "email") || (fieldName == "user[email]")) {

			

				var emailFilter = /^.+@.+\..{2,3}$/;

				var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;

				emailAddress = fieldObj.value;

				if (!(emailFilter.test(emailAddress))) { 

					valid = false;

					errormsg += "- Please Enter a Valid Email Address\n";

					if(firstfield == ""){

						firstfield = fieldObj;

					}

				}

				if (emailAddress.match(illegalChars)) {

					valid = false;

					errormsg += "- Please Check your email address, it contains illegal characters.\n";

					if(firstfield == ""){

						firstfield = fieldObj;

					}

				}

			}

			//Check for valid second email address matches first email address

			if (fieldName == "email2") {

				emailAddress2 = fieldObj.value;

				if (!(emailAddress2 == emailAddress)) { 

					valid = false;

					errormsg += "- Please ensure your confirmation email address matches your email address.\n";

					if(firstfield == ""){

						firstfield = fieldObj;

					}

				}

			}

			if(fieldName == "password"){

				thepassword = fieldObj.value;

			}

			if(fieldName == "password2" && typeof(thepassword) != "undefined"){

				if(fieldObj.value != thepassword){

					errormsg += "- Please ensure your confirmation password matches the password.\n";

					if(firstfield == ""){

						firstfield = fieldObj;

					}

				}

			}

		} else if  (fieldObj.type == "checkbox"){

			if(!fieldObj.checked){

				valid = false;

				errormsg += "- "+displayName + "\n";

			}

		}

	}





	if (valid == false) {

		alert(errormsg);

		if(firstfield){

			firstfield.focus();

		}

	}

	return valid;



}



// End of Form Validation //





// Image Rollover

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}



//end of Image rollover



//Font Change - Unused



var max = 100;

	var min = 8;

	function changeFontSize(step){			

		var p = document.getElementsByTagName('p');

		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}



		p = document.getElementsByTagName('ul');

		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}



		p = document.getElementsByTagName('a');





		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}



		p = document.getElementsByTagName('div');



		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}



		p = document.getElementsByTagName('b');



		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}



		p = document.getElementsByTagName('strong');



		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}





		p = document.getElementsByTagName('option');



		for(i=0;i<p.length;i++) 

		{

			if(p[i].style.fontSize) 

			{

				s = parseInt(p[i].style.fontSize.replace("px",""));

			} else {

				s = 12;

			}

			if((s != max && step > 0) || (s != min && step < 0)) {

				s += step;

			}

			p[i].style.fontSize = s+"px"

		}

	}

	

	

// PNG Fix

/*



$(document).ready(function(){

		//pgnfix

		$(document).pngFix();

		//$('div.left_header').pngFix();

		//expandable

	});



*/

	function focusInput(name, $messsage) {

		if(!name._haschanged && name.value == $messsage){

			name.value='';

			name._haschanged=true;

		}

	}

	function blurInput(name, $messsage) {

		if(name._haschanged && name.value == ''){

			name.value=$messsage;

			name._haschanged=false;

		}

	}



	var firstTime = true;

	function achangeFontSize(element,step)

	{

		if (firstTime) {

			var el = document.getElementById('content_nocolumns');

			var curFont = 12;

			el.style.fontSize = (curFont) + 'px';

			firstTime = false;

			step = parseInt(step,10);

			var el = document.getElementById(element);

			var curFont = parseInt(el.style.fontSize,10);

			el.style.fontSize = (curFont+step) + 'px';

		}else if (!firstTime) {

			step = parseInt(step,10);

			var el = document.getElementById(element);

			var curFont = parseInt(el.style.fontSize,10);

			el.style.fontSize = (curFont+step) + 'px';

		}

	}





// in page template show hide



  function showhidefield(obj, field)

  {	

  txt = obj.options[obj.selectedIndex].value;

  

	  if((txt == "other") || (txt == "Detached")){



      document.getElementById(field).style.visibility = "visible";

    }

    else

    {

      document.getElementById(field).style.visibility = "hidden";

    }

  }
