/*
 * $Author: dbibbens $
 * $Revision: 1.42 $
 * $Date: 2009/04/30 19:06:02 $ 
 * $Source: /home/cvs/insurance/auto/local/lib/functions.js,v $
 */

var selected = false;

function change_state(aid, subid)
{
  var select = document.getElementById('state');
  var zipcode = document.getElementById('zipcode');
  
  if(select && select.selectedIndex > 0 && 
     (
      aid == 'amgx007' ||
      aid == 'amgx091' ||
      aid == 'amgx123' ||
      aid == 'amgx147' ||
      aid == 'amgx432' ||
      aid == 'amgx453' ||
      aid == 'amgx459' ||
      aid == 'amgx478' ||
      aid == 'amgx502' ||
      aid == 'amgx503' ||
      aid == 'amgx505' ||
      aid == 'amgx597' ||
      aid == 'amgx619' ||
      aid == 'amgx624' ||
      aid == 'amgx625' ||
      aid == 'amgx629' ||
      aid == 'amgx632' ||
      aid == 'amgx639' ||
      aid == 'amgz001'
      )) {
    var state = select.options[select.selectedIndex].value;
    document.location = 'zipmake.xsl?state=' + state + '&aid=' + aid;

    return true;
  }

  if(select && select.selectedIndex > 0) {
    var state = select.options[select.selectedIndex].value;
    if(subid && subid != '') {
      document.location = 'results.xsl?state=' + state + '&aid=' + aid + '&sub-id=' + subid;
    } else {
      document.location = 'results.xsl?state=' + state + '&aid=' + aid;
    }
  } 
  
  if(zipcode && zipcode.value.length == 5) {
    if(subid && subid != '') {
      document.location = 'results.xsl?zipcode=' + zipcode.value + '&aid=' + aid + '&sub-id=' + subid;
    } else {
      document.location = 'results.xsl?zipcode=' + zipcode.value + '&aid=' + aid;
    }
  }
  
  return true;
}

function adj_change_state(aid, subid) 
{
  var select = document.getElementById('state');
  var state = select.options[select.selectedIndex].value;

  if(state) {
    var url = 'results.xsl?state=' + state + '&aid=' + aid + '&sub-id=' + subid;
    openWin(url, (screen.width * 0.7), (screen.height * 0.6));
  }
}

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);
}
