// JavaScript Document
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
setInterval( "slideSwitch()", 5000 );
});

function ValidateClick() {
form_product=document.quoteform.type.value; //selected product
aff_id=document.quoteform.affil.value; //lead affiliate id
zipcode=document.quoteform.zipcode.value; //zipcode

siteURL ="";
var siteURL ="https://www.insuranceratesguide.com/forms";
//siteURL = siteURL + "/" + form_product + "?a=" + aff_id +"&t=" +;
getfield = [];//array with values in form fields
getfield[0] = aff_id;
getfield[1] = form_product;
getfield[2] = zipcode; //zip code
webjuice=0;
form_behavior=0; //0: Normal - 1: BW Ads.
prod_id=0;

switch (form_product) {
case 'auto': /*BROKERS*/ form_behavior=1; prod_id=300; break;
case 'home': break;
case 'health':/*BROKERS*/ form_behavior=1; prod_id=200; break;
case 'life':/*BROKERS*/ form_behavior=1; prod_id=260; break;
case 'condo': break;
case 'renters': break;
case 'annuity': break;
}
	if (form_behavior==1){//BW
	siteURL = siteURL + "/" + form_product + "/?a=" +aff_id+ "&t=646&c="+document.getElementById('campaign_name').value+"&zip="+zipcode;
	var form_zip = document.createElement("input");
	form_zip.setAttribute("type","hidden"); //Type of field - can be any valid input type like text,file,checkbox etc.
	form_zip.setAttribute("name","zip");
	form_zip.setAttribute("value",zipcode);
	document.getElementById('quoteform').appendChild(form_zip);
	var form_prod = document.createElement("input");
	form_prod.setAttribute("type","hidden"); //Type of field - can be any valid input type like text,file,checkbox etc.
	form_prod.setAttribute("name","prodid");
	form_prod.setAttribute("value",prod_id);
	document.getElementById('quoteform').appendChild(form_prod);

		if (form_product=='auto'){
		var z = document.getElementById('zipcode').value;
			if (z=="") {alert("Please enter your zipcode"); return false;}
			else {
			var form_prod = document.createElement("input");
			form_prod.setAttribute("type","hidden"); //Type of field - can be any valid input type like text,file,checkbox etc.
			form_prod.setAttribute("name","maxads");
			form_prod.setAttribute("value","5");
			document.getElementById('quoteform').appendChild(form_prod);
				
				if (document.getElementById('currentlyInsuredYes').checked)	{
				theme_id='646';
				var url;
				var qt = document.getElementById('type').value;
					if (qt != '') {
					var affil = 1;
					var af = document.getElementById('affil');
						if (af) {
						affil = af.value;
						}
					var z = document.getElementById('zipcode').value;
					url = 'https://www.insuranceratesguide.com/forms/'+ qt+ '?a='+ affil+ '&t='+ theme_id +'&c='+ document.getElementById('campaign_name').value;
						if (/^\d{5}$/.test(z)) {
						url += '&zip='+ z;
						}					
					}
				siteURL= 'http://www.insuranceratesguide.com/auto-results.html?type=auto&affil=99728&prodid=300&maxads=5&zip=' +z+ '&zipcode=' +z;
				}
				else {
				siteURL= 'http://www.insuranceratesguide.com/auto-results.html?type=auto&affil=99728&prodid=300&maxads=5&zip=' +z+ '&zipcode=' +z;
				}
			}
		}
 
	document.quoteform.method="get";
	//window.open(siteURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
	}
	else {//NORMAL LEAD 
	document.quoteform.action="javascript:quote(document.getElementById('campaign_name').value,'646')";
	}
	if (form_product=='auto'){
	//window.open(siteURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
	
if (document.getElementById('currentlyInsuredYes').checked)	{

	

	document.quoteform.action="javascript:quote(document.getElementById('campaign_name').value,'646')";
	return true;
	TheNewWin =window.open(siteURL,'Get Additional Quotes','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'); 
	TheNewWin.blur();
	}
		else
		{
		document.forms["quoteform"].action='auto-results.html';
		}
	}
	document.forms["quoteform"].submit();
	return true;
}

function quote(affil_name,theme_id)
{
	var url;
	var qt = document.getElementById('type').value;
	if (qt != '')
	{
		var affil = 1;
		var af = document.getElementById('affil');
		if (af)
		{
			affil = af.value;
		}
		var z = document.getElementById('zipcode').value;

		url = 'https://www.insuranceratesguide.com/forms/'+ qt+ '?a='+ affil+ '&t='+ theme_id +'&c='+ affil_name;
		if (/^\d{5}$/.test(z))
		{
			url += '&zip='+ z;
		}
		//document.location.href = url;
		window.location.assign(url);
		return false;
	}
	return false;
}

function toggleAutoInsurance()
{
	var qt = document.getElementById('type').value;
	if (qt != 'auto')
	{
		document.getElementById('auto_insurance').style.display="none";
	}
	else
	{
		document.getElementById('auto_insurance').style.display="";
	}
}
