/* $Id: formscripts.js,v 1.4 2009/10/14 18:16:21 josilver Exp $ */  

function changeDemo(scrn)
{
    switch(scrn)
    {
        case 1:
          document.getElementById('scrn').src="/images/billpay/scrn_login.gif";
          document.getElementById('link-Policy').className='demo-on';
          document.getElementById('link-Payment').className='demo-off';
          document.getElementById('link-Confirmation').className='demo-off';
          
          break;    

        case 2:
          document.getElementById('scrn').src="/images/billpay/scrn_payment.gif";
           document.getElementById('link-Policy').className='demo-off';
          document.getElementById('link-Payment').className='demo-on';
          document.getElementById('link-Confirmation').className='demo-off';
          
          break;

        case 3:
          document.getElementById('scrn').src="/images/billpay/scrn_confirmation.gif";
           document.getElementById('link-Policy').className='demo-off';
          document.getElementById('link-Payment').className='demo-off';
          document.getElementById('link-Confirmation').className='demo-on';
          
          break;


      
    }

}

function validate(thisform) {

if (document.apply)
{

if (apply.position.value=='') {
alert('Position is a required field. Please try again.');
return false;
}

else if (apply.name.value=='') {
alert('Your NAME is a required field. Please try again.');
return false;
}

else if (apply.email.value=='') {
alert('Your EMAIL is a required field. Please try again.');
return false;
}

else if (apply.filename.value=='') {
alert('Your Resume File is required. Please try again.');
return false;
}
}

else if (document.agentfinder)
{

searchVal=thisform.searchfor.value;
var iChars = "!@^_=+?*|\:<>[]{}`\;()&$#%";
typeVal= -1;
for (i=thisform.typesearch.length-1; i > -1; i--)  {
   if (thisform.typesearch[i].checked)  {
      typeVal = i;
   }
}
if (typeVal == -1)  {
   alert('You must select the type of search');
   thisform.searchfor.focus();
   return false;
}
if ( thisform.typesearch[typeVal].value == "agent")  {
  if (searchVal != "")  {
    if(searchVal.length > 60)  {
      alert('Agent name must be less than 60 characters long.')
      thisform.searchfor.focus();
      return false;
    }
    for (var i = 0; i < searchVal.length; i++) {
      if (iChars.indexOf(searchVal.charAt(i)) != -1)  {
         alert('Agent name must contain letters and numbers only.');
         thisform.searchfor.focus();
         return false;
      }
    }
  }
  else  {
        alert('Please type an agent name to search.');
        thisform.searchfor.focus();
        return false;
  }
  return true;
}
else if (thisform.typesearch[typeVal].value == "town")  {
  if (searchVal != "")  {
    if(searchVal.length > 60)  {
      alert('Town name must be less than 60 characters long.')
      thisform.searchfor.focus();
      return false;
    }
    for (var i = 0; i < searchVal.length; i++) {
      if (iChars.indexOf(searchVal.charAt(i)) != -1)  {
         alert('Town name must contain letters and numbers only.');
         thisform.searchfor.focus();
         return false;
      }
    }
  }
  else  {
        alert('Please type a town to search.');
        thisform.searchfor.focus();
        return false;
  }
  return true;
}
else if (thisform.typesearch[typeVal].value == "zip")  {
  if (searchVal != "")  {
    if(searchVal.length != 5)  {
      alert('Zip Code must contain 5 digits only');
      thisform.searchfor.focus();
      return false;
    }
    var regex = /[0-9]{5}/;
    if (regex.test(searchVal) == false)  {
      alert('Zip Code must contain 5 digits only');
      thisform.searchfor.focus();
      return false;
    }
  }
  else  {
        alert('Please type a zip code to search');
        thisform.searchfor.focus();
        return false;
  }
  return true;
}
else  {
  alert('Not a valid search type.');
  return false;
}

}

return true;
}
  
    function linkia()
     {
       window.open('http://www.safetyinsurance.com','name1','width=700,height=600,resizable=yes');
      }
    function linkam()
     {
       window.open('http://www3.ambest.com/ratings/profile.asp?ambnum=18080&RatingCode=10818080','name1','width=700,height=600,resizable=yes');
      }
      
      function openFrame(targ)
      {
      var page
      
      if (targ=='billing')
      {
      page="/inquiry/billing.pl?sw=2";
      }
      
      else if (targ=='claim')
      {
      page="/inquiry/claims.pl?switch=1";
      }
      
      else
      {
      page="IA_home.html";
      }
      
      
      var newWin=window.open('','name1','width=700,height=600,resizable=yes');
     
       newWin.document.write ("<base href='https://www.insureanswer.com'>");      
       newWin.document.write ("<frameset rows=\'45,46,*\' border=0 frameborder=0>");
       newWin.document.write ("<frame name='ia_banner' src='banner.pl?agent=none' name='banner' border='0' cellspacing='0' scrolling='no' marginwidth='0' marginheight='0'>");
       newWin.document.write ("<frame name='ia_nav' src='IA_nav.html' name='nav' border='0' cellspacing='0' scrolling='no' marginwidth='0' marginheight='0'>");
       newWin.document.write ("<frame name='ia_main' src='"+page+"' name='body' border='0' cellspacing='0' marginwidth='0' marginheight='0'>");
       newWin.document.write("</frameset>");
       newWin.document.close();
       newWin.focus();
               
        }

    function searchType()
    {
    
    if (isNaN(document.agentfinder.searchfor.value)==true)
    {
    document.agentfinder.typesearch.value='town';
    }
    else
    {
    document.agentfinder.typesearch.value='zip';
    }
    }
      
      

function resetFocus()  {
   document.agentfinderform.searchfor.focus();
}

function close_dropdown()  {
  document.agentfinderform.radius.disabled=true;
  document.agentfinderform.searchfor.focus();
}
function open_dropdown()  {
  document.agentfinderform.radius.disabled=false;
  document.agentfinderform.searchfor.focus();
} 

// Disable all submit buttons in a form (to prevent double clicks)
function disable_submit( formObj )
 {
  for (var i = 0; i < formObj.childNodes.length; i++) {
    var childObj = formObj.childNodes[i];
    if (childObj.childNodes.length) {
      // Recursively search for submit buttons
      disable_submit( childObj );
     }
    if ((childObj.tagName == 'INPUT') && (childObj.type == 'submit')) {
      childObj.onclick = disable_link;
      childObj.style.backgroundPosition = "-152px 0";
      childObj.style.color = "#999999";
     }
   } 
 } // End of disable_submit()

// Used in disable_submit() - Disable onClick() function
function disable_link() {
  return false;
 }

//
// Print test background
//
function test_background( objID )
 {
  var o = document.getElementById( objID ); 
  if (o) {
    o.style.background = "url('/images/test_bkgnd.png')";
   }
 }

/*
 * cancel_confirm() - Force user to confirm cancelling a transaction
 */
function cancel_confirm()
 {
  return confirm( "Click OK to end this transaction." );
 }

function swapImage(imageID,source)
{
source='/images/menu_' + imageID + source + '.gif';
document.getElementById(imageID).src = source;

/*IE 6 Fix for Select displaying over submenu*/
if (typeof document.body.style.maxHeight == "undefined") {
    if ((imageID == 'driversafety') && document.getElementById('radius')) {

        if (document.getElementById('radius').style.visibility != 'hidden') {
            document.getElementById('radius').style.visibility = 'hidden';
            document.getElementById('searchFields').style.marginTop = '10px';
          

        }
        else {
            document.getElementById('radius').style.visibility = 'visible';
           }


    }
}
}

function setFooter() {
if (document.getElementById) {
var windowHeight=getWindowHeight();
if (windowHeight>0) {
var contentHeight=
document.getElementById('page-wrapper').offsetHeight;

var footerElement=
document.getElementById('footer');
var footerHeight=footerElement.offsetHeight;
if (windowHeight-(contentHeight+footerHeight)>=0) {
footerElement.style.position='relative';
footerElement.style.top=(windowHeight-
(contentHeight+footerHeight))+'px';
}
else {
footerElement.style.position='static';
}
}
}
}

function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=
document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}


/*adjust height to position footer at bottom*/
function adjustFooter()
{
    if (!(document.getElementById('home'))) {
        var contentHeight = document.getElementById('main-content').offsetHeight
        var pageHeight = document.documentElement.clientHeight
        var nonbodyHeight = 230;
        pageHeight = (pageHeight - nonbodyHeight);
        diffHeight = (pageHeight - contentHeight);

        if (document.all) {

            if (diffHeight > 0) {

                /*document.getElementById('main-content').style.height=pageHeight+'px';*/
                document.getElementById('footer').style.marginTop = diffHeight + 'px';
            }
        }
        else {

            pageHeight = (pageHeight - 10);
            document.getElementById('main-content').style.minHeight = pageHeight + 'px';
        }
    }
}




function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return ""
}

function setCookie() {
    
        var expiredays = 60;
        var c_name = 'username';
        var c_value = document.getElementById('mylogin_username').value
        var exdate = new Date();

            
       if (document.getElementById('remember_me').checked==true) {

        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + escape(c_value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
      
    }
           
        else {
           exdate.setTime(exdate.getTime() - 1);
           document.cookie = c_name += "=; expires=" + exdate.toGMTString()

    }
        
    
    
    
}

function checkCookie() {
    var username = getCookie('username');
    if (document.getElementById('mylogin_username') && document.getElementById('remember_me')  )
    {
    if (username != null && username != "") {
        document.getElementById('mylogin_username').value = username;
        document.getElementById('remember_me').setAttribute('checked', 'checked');
        
    }
    }
    
}


				
