var SECURE = '';

// the region select function has a hard-coded url. Please change
function RegionSelect() {
  URI = window.location.host;
  region_win = window.open('http://www.fila.com/region_select_form.jsp?host='+URI,'region_window','width=400,height=300,top=100,left=100,scrollbars=yes');
  region_win.focus();
}    


function LoginForm(PAGE_SWITCH) {
  // populate with the form

  if (PAGE_SWITCH == 'checkout' || PAGE_SWITCH == 'myaccount') {
  loginform  = '<form method="post" action="" onsubmit="DoLogin();return false">';
  loginform += '  <table id="ajax_login_table" cellspacing="0" cellpadding="0" border="0">';
  loginform += '    <tr><th>Username</th></tr>';
  loginform += '    <tr><td><input tabindex="90" type="text" id="username" name="username" maxlength="60" value="" /></td></tr>';
  loginform += '    <tr><th>Password</th></tr>';
  loginform += '    <tr><td><input tabindex="91" type="password" id="passwd" name="passwd" maxlength="20" value="" /></td></tr>';
  loginform += '    <tr><td><input tabindex="92" type="submit" class="submit_button" id="go_login" name="go_login" value="Login" /></td></tr>';
  loginform += '    <tr><td><a href="" onclick="LoginForm(\'checkout\');return false" title="close">close</a></td></tr>';
  loginform += '    <tr><td id="login_message"></td></tr>';
  loginform += '  </table>';
  loginform += '</form>';

  $('floating_ledger_content').innerHTML = loginform;
  Effect.toggle('floating_ledger_content','slide');
  } else {
    // this is for dev testing
    if (SECURE == '') {
      SECURE = 'secure.fila.com';
    }
    window.location.href= 'https://' + SECURE + '/login';
  } // end else


}

function DoLogin() {
  if ($('username').value == '' || $('passwd').value == '') {
    $('login_message').innerHTML = '<span class="error_message">please enter a username and password</span>';
  } else {
    url = '/ajax/login';
    poststring  = 'username=' + $('username').value;
    poststring += '&password=' + $('passwd').value;

    new Ajax.Request(url, { method: 'post', parameters: poststring, onSuccess: LoginSuccess, onFailure: LoginFailure });
  } // end else
} // end function DoLogin()

function LoginFailure(OBJ) {
  $('login_message').innerHTML = OBJ.responseText;
}

function LoginSuccess(OBJ) {
  // match for success
  if (OBJ.responseText.match(/success/)) {
    window.location.reload();
  } else {
    $('login_message').innerHTML =  OBJ.responseText;
  }
}

function copyAddress() {

  if (document.forms['checkout_form'].same_shipping.checked == true) {
     document.forms['checkout_form'].billing_fname.value = document.forms['checkout_form'].shipping_fname.value;
     document.forms['checkout_form'].billing_lname.value = document.forms['checkout_form'].shipping_lname.value;
     document.forms['checkout_form'].billing_address1.value = document.forms['checkout_form'].shipping_address1.value;
     document.forms['checkout_form'].billing_address2.value = document.forms['checkout_form'].shipping_address2.value;
     document.forms['checkout_form'].billing_city.value = document.forms['checkout_form'].shipping_city.value;
     document.forms['checkout_form'].billing_state.selectedIndex = document.forms['checkout_form'].shipping_state.selectedIndex;
     document.forms['checkout_form'].billing_zip.value = document.forms['checkout_form'].shipping_zip.value;
     document.forms['checkout_form'].billing_country.selectedIndex = 2;
   }
}

function StoreLocator(POSTALCODE) {
  if (POSTALCODE.length > 0 && POSTALCODE != 'ZIP CODE') {
  LOCATOR_URL = "http://locator.fila.com/index.php?fsl_radius=25&fsl_zip="+POSTALCODE;
  locator_win = window.open(LOCATOR_URL,'loc_win','width=655,height=640,top=10,left=20,scrollbars=yes');
  locator_win.focus();
  } else {
    alert ('Please enter a ZIP code');
  }
}


function OpenLocator() {
  LOCATOR_URL = 'http://locator.fila.com/';
  locator_win = window.open(LOCATOR_URL,'loc_win','width=655,height=700,top=10,left=20,scrollbars=yes');
  locator_win.focus();
}

/* functions for flash to go to these urls */

function goMen() {
  window.location.href = regUrl + '/men';
}

function goWomen() {
  window.location.href = regUrl + '/women';
}

function goKids() {
  window.location.href = regUrl + '/kids';
}

function goAccessories() {
  window.location.href = regUrl + '/accessories';
}

var catnav = 0;
var sportnav = 0;

function CatSlide() {
  jQuery("#category_nav").slideDown();
  jQuery("#sport_nav").slideUp();
  catnav=1;
  sportnav=0;
} // end CatSlide()

function SportSlide() {
  jQuery("#sport_nav").slideDown();
  jQuery("#category_nav").slideUp();
  catnav=0;
  sportnav=1;
} // end SportSlide()

function setLeftNav() {
  // see which one to open, and which one to close
  var tcat=$('category_nav');
  var tspt=$('sport_nav');
  if(tcat&&tspt){
  if (catnav == 1) {
    tcat.style.display = "block";
    tspt.style.display = "none";
  } 
  else if (sportnav == 1) {
    tspt.style.display = "block";
    tcat.style.display = "none";
  }
  else {
    tcat.style.display = "block";
    tspt.style.display = "none";
  }
  } else if(tcat){
    catnav = 1;
    tcat.style.display = "block";
  }
} // end setLeftNav()

function btnSelect(BTN,IMAGE) {
   $(BTN).src = IMAGE;
} // end function btnSelect()


function shipDetails() {
  detail_win = window.open('/content/html/us/eng/shipping_promo_details.html','detailwin','width=410,height=300,top=100,left=100');
  detail_win.focus();
} // end function shipDetails()

function goBag() {
  window.location.href = '/bag';
}

function disableAgain() {
  $('go_finalize').disabled = true;
  return true;
}

function ShowArticle(URL) {
  article_window = window.open('http://www.fila.com/show_article.jsp?url=' + URL, 'article_window','width=500,height=600,scrollbars=yes');
  article_window.focus();
}

function ShowConditions(URL,winWidth,winHeight) {
		conditions_win = window.open(URL, 'fila_conditions', 'top=120,left=120,height='+winHeight+',width='+winWidth+',location=no,resizable=no,scrollbars=no,status=no');
		conditions_win.focus();
}

function CheckSearch(TERM) {
	var cleaned = $('search_term').value.stripScripts().stripTags();
  if (cleaned == TERM) {
    alert('Please enter a search term');
    return false;
  } else if (cleaned == '') {
    alert('Please enter a search term');
    return false;
  } else {
    return true;
  }
} // end CheckSearch()

function debug_window(content) {
  debug_win = window.open('','debug_window','width=600,height=400,scrollbars=yes');
  debug_win.document.write('<pre>'+content+'</pre>');
  debug_win.focus();
}

function NewsletterSignUp(localeSignifier,optInEmail) {
  FORMURL = localeSignifier + '/newsletter?subscribeEmail=' + optInEmail;
  email_newsletter_win = window.open(FORMURL, 'opt_in_email', 'width=410,height=380,scrollbars=no');
  email_newsletter_win.focus();
}

function NewsletterManage(localeSignifier) {
  FORMURL = localeSignifier + '/newsletter';
  email_newsletter_win = window.open(FORMURL, 'opt_in_email', 'width=410,height=380,scrollbars=no');
  email_newsletter_win.focus();
}
