
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': webjuice=1; 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);
	
	document.quoteform.method="get";
	
	window.open(siteURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
	
	}

	else if (webjuice==1)
	{
	var z = document.getElementById('zipcode').value;
		
		if (z=="") {alert("Please enter your zipcode"); return false;}
		else 
		{
			if (!document.getElementById('currentlyInsuredYes').checked)
			{
			url = 'https://www.insuranceratesguide.com/forms/wjquotes.php?zipcode=' + z;
			document.location.href = url;
			return false;
			}
			else
			{
				
			document.quoteform.action="javascript:quote(document.getElementById('campaign_name').value,'646')";	
			document.forms["quoteform"].submit();
			return false;
			}
		}
	return false;

	}

	else {//NORMAL LEAD
	
	document.quoteform.action="javascript:quote(document.getElementById('campaign_name').value,'646')";
	
	}
	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="";
	}
}
