/*
 * $Author: dbibbens $
 * $Revision: 1.18 $
 * $Date: 2010/06/11 19:13:04 $ 
 * $Source: /home/cvs/americaninsurancesite.com/local/lib/functions.js,v $
 */

var selected = false;

function change_state(aid, subid)
{
    var select = document.getElementById('state'); 
    var state = select.options[select.selectedIndex].value;
    var type = document.getElementsByName("type");
    var checked = false;

    for(var i = 0; i < type.length; i++) {
	if(type[i].checked) {
	    checked = true;
	}
    }
    
    if(!state) {
	alert("Please select a state.");
	return false;
    }
    
    if(aid == 'WEB' && subid == '116236-236'){
	checked = true;
    }

    if(!checked) {
	alert("Please select an insurance type.");
	return false;
    }
    
    if(state && checked) {
	concat_aid(aid);
	document.getElementById("form").submit();
	return true;
    }
}

function adj_change_state(select, aid) 
{
  var state = select.options[select.selectedIndex].value;
  if(state) {
    window.moveTo(0,0);
    window.resizeTo(screen.width,screen.height);
    document.location = 'results.xsl?state=' + state + '&aid=' + aid;
  }
}

function openWin(url, width, height) 
{
  var features = "toolbar=yes,location=yes,directories=no,status=yes," + 
    "menubar=yes,marginwidth=0,marginheight=0,resizable=yes,scrollbars=" +
    "yes,width=" + width + ",height=" + height;
  
  if(!selected) {
    popup_win(url, 'results', features);
  }
}

function popup_win(url, name, features) 
{
  window.open(url, name, 'screenX=0,screenY=0,left=0top=0,' + 
			  features);
}

function concat_aid(aid_value)
{
  var aid = document.getElementById('aid');
  var type = document.getElementsByName('type');

  aid.value = aid_value;

  for(var i = 0; i < type.length; i++) {
    if(type[i].checked) {
      aid.value = aid.value + '-' + type[i].value;
    }
  } 
}
