var old_action;

function change_action(){
  rb1 = document.ca.ca_type[1];
  
  if(rb1 && rb1.checked){
    old_action = document.ca.action;
    document.ca.action = 'http://'+location.host+'/imagelib/cart/checkout.html';
  }
  else{ 
    if(old_action) document.ca.action = old_action;
  }
}

//////////////////////////////////////////////////////////////////////////////

function checkout(){
  obj = document.getElementById('accept');
  mc = document.getElementById('mcmail');
  msg = '';
  
  if(mc && invalid_email(mc.value)) msg = 'Please, put correct email\n';
  if(!obj.checked) msg += 'Please, accept terms and conditions';
   
  if(msg){
    alert(msg);
    return false;
  }
}

//////////////////////////////////////////////////////////////////////////////

function show_price(){
  obj = document.getElementById('priceblock'); 
  obj.style.display = 'block';
}

//////////////////////////////////////////////////////////////////////////////

function hide_price(){
  obj = document.getElementById('priceblock'); 
  obj.style.display = 'none';
}

//////////////////////////////////////////////////////////////////////////////

function check_radio(){
  rb2 = document.ca.ca_type[1];
  buy = document.getElementById('buyitnow');
       
  if(rb2 && rb2.checked){
    show_login_form();
    buy.style.display = 'none';
  }
  else{
    hide_login_form();
    buy.style.display = 'block';  
  }
}
    
//////////////////////////////////////////////////////////////////////////////

function display_login_form(){                       
  if(document.getElementById && document.getElementById('loginform')){
    obj = document.getElementById('loginform');

    if(obj.style.display == 'none') show_login_form(); 
    else hide_login_form();
  }
}

//////////////////////////////////////////////////////////////////////////////

function show_login_form(){                       
  if(document.getElementById && document.getElementById('loginform')){
    obj = document.getElementById('loginform');
    obj.style.display = 'block';
      
    if(document.images) document.images['arrow_login'].src = 'http://'+location.host+'/data/img/arrowd.gif'; 
  }    
}

//////////////////////////////////////////////////////////////////////////////

function hide_login_form(){                       
  if(document.getElementById && document.getElementById('loginform')){
    obj = document.getElementById('loginform');
    obj.style.display = 'none';
      
    if(document.images) document.images['arrow_login'].src = 'http://'+location.host+'/data/img/arrowr.gif'; 
  }    
}

//////////////////////////////////////////////////////////////////////////////

function display_lb_form(){                       
  if(document.getElementById && document.getElementById('lbform')){
    obj = document.getElementById('lbform');

    if(obj.style.display == 'none'){
      obj.style.display = 'block';
      
      if(document.images)
        document.images['arrow_lb'].src = 'http://'+location.host+'/data/img/arrowd.gif'; 
    } 
    else{
      obj.style.display =  'none';
      
      if(document.images)
        document.images['arrow_lb'].src = 'http://'+location.host+'/data/img/arrowr.gif'; 
    }
  }
}

//////////////////////////////////////////////////////////////////////////////

function select_all(myForm, name){
  var selection = true;

  for (i = 0; i < myForm.elements.length; i++){
     if (myForm.elements[i].name==name){
       if(myForm.elements[i].checked == false)
         selection = myForm.elements[i].checked;
    }
  }

  for (i = 0; i < myForm.elements.length; i++){
    if (myForm.elements[i].name==name) myForm.elements[i].checked = !selection;
  }
  return false;
}

//////////////////////////////////////////////////////////////////////////////

function check_country(){
 cid = document.getElementById('country_id'); 
 
 found = 0;
 eu_countries = new Array(15,24,63,64,65,82,89,75,193,93,109,81,142,150,215,115,117,135,141,170,192,214,220,227);
 
 for (i=0; i<24; i++){
   if(eu_countries[i] == cid.options[cid.selectedIndex].value) found = 1;  
 }
 
 rb = document.getElementById('redblock'); 
 rb.style.display = (found) ? 'block' : 'none';
 
 vf = document.getElementById('vatform'); 
 vf.style.display = (found) ? 'block' : 'none';
}

//////////////////////////////////////////////////////////////////////////////

function action_form(myForm, action){  
  myForm.act.value = action;
  myForm.submit(); 
  return false;
}

//////////////////////////////////////////////////////////////////////////////

function jumpMenu(myForm, selObj) {
  myForm.act.value = 'change';
  myForm.id.value = selObj.options[selObj.selectedIndex].value;
  myForm.submit(); 
  return false;
}

//////////////////////////////////////////////////////////////////////////////

function redirect_page(url){
  if(url) window.location = 'http://'+location.host+'/'+url
  //alert('http://'+location.host+'/'+url);
}

//////////////////////////////////////////////////////////////////////////////

function login_onfocus(obj){
  var f=obj.form;
  if(f.pass.value == f.pass.defaultValue) f.pass.value = '';
  if(f.email.value == f.email.defaultValue) f.email.value = '';
}

//////////////////////////////////////////////////////////////////////////////

function login_onblur(obj){
  var f=obj.form;
  if(f.pass.value == '') f.pass.value = f.pass.defaultValue;
  if(f.email.value == '') f.email.value = f.email.defaultValue;
}

//////////////////////////////////////////////////////////////////////////////

function change_form(){

  content = '';
  add_content = document.getElementById('additional');
 
  type1 = document.getElementById('isearch');
  type2 = document.getElementById('msearch'); 
 
  if(type1 && type1.checked) content += '<input type=hidden name=is value=1>';
  if(type2 && type2.checked) content += '<input type=hidden name=ms value=1>';
     
  add_content.innerHTML = content;
}

////////////////////////////////////////////////////////////////////////////// 

function on(i){
  obj = document.getElementById(i);
  obj.style.border = "solid 1px #035d03";
}

//////////////////////////////////////////////////////////////////

function off(i){
  obj = document.getElementById(i);
  obj.style.border = "solid 1px #ffffff";
}

//////////////////////////////////////////////////////////////////

var cart_old_text;
var bin_old_text; 

function replace_cart_text(id){
   
 objname = 'carttext';
 
 if(id) objname += id;
 
 obj = document.getElementById(objname); 
 content = obj.innerHTML;

 rep_location = content.indexOf('add to cart');
 
 if(rep_location > 0){
   content = content.replace('add to cart', 'remove from cart')
   content = content.replace('add', 'del');
 }
 else{
   content = content.replace('remove from cart', 'add to cart')
   content = content.replace('del', 'add');
 }
 obj.innerHTML = content;   
}

////////////////////////////////////////////////////////////////// 

function replace_bin_text(){

 obj = document.getElementById('bintext'); 
 content = obj.innerHTML;

 alert(content);
 
 rep_location = content.indexOf('add to lightbox');
       
 if(rep_location > 0){
   content = content.replace('add to lightbox', 'remove from lightbox')
   content = content.replace('add', 'del');
   content = content.replace('plus', 'minus'); 
 }
 else{
   content = content.replace('remove from lightbox', 'add to lightbox')
   content = content.replace('del', 'add');
   content = content.replace('minus', 'plus'); 
 }
 
 obj.innerHTML = content;
 
}

////////////////////////////////////////////////////////////////// 

function hide_img(type, id){

  obj = document.getElementById('textgreen'); 
  
  if(type=='bin'){
    if(obj){
      if(document.layers) obj.style.visibility="show";
      else obj.style.visibility="visible";
      obj.innerHTML = 'Item <b>'+id+'</b> has been added to your lightbox';
    }
    bin = document.getElementById('bin'+id);
    bin.style.visibility = 'hidden';
    
    if(document.layers) bin.style.visibility="hide";
    else bin.style.visibility="hidden";
  }
  else{
    if(obj){
      obj.style.visibility = 'visible';
      
      if(document.layers) obj.style.visibility="show";
      else obj.style.visibility="visible";
                    
      obj.innerHTML = 'Item <b>'+id+'</b> has been added to your cart';
    }
    ct = document.getElementById('ct'+id);
    if(document.layers) ct.style.visibility="hide";
    else ct.style.visibility="hidden";
  }
}

////////////////////////////////////////////////////////////////// 

function reload_main(url){
  parent.location = 'http://'+location.host+'/'+url;
}

////////////////////////////////////////////////////////////////// 

function invalid_email(email_address){
  if (email_address.length < 5) return true
    
  at_location  = email_address.indexOf("@");
  dot_location = email_address.lastIndexOf(".");
    
  if((at_location == 0)||(dot_location - at_location < 2)||(email_address.length - dot_location < 2)) return true
  return false
}

////////////////////////////////////////////////////////////
    
function its_empty (str_value){
    return (str_value == "" || str_value == null)
}

////////////////////////////////////////////////////////////

function show_window(path){
  path = 'http://'+location.host+'/'+path;
  pw = window.open(path, 'popwindow', 'width=500, height=600, scrollbars=yes');
  pw.focus(); 
  return false;
}

//////////////////////////////////////////////////////////// 

function checkFlash() {
  var flash_versions = 20; var flash_installed = 0; var flash_version = '0.0'; var java_installed = 0;
  if (navigator.plugins && navigator.plugins.length) {  // Netscape style plugin detection
    for (x = 0; x < navigator.plugins.length; x++) {
      if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
        flash_version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
        flash_installed = 1;
        break;
      }
    }
    
    for (x = 0; x < navigator.plugins.length; x++) {
      if (navigator.plugins[x].name.indexOf('Java(TM)') != -1) {
        java_installed = 1;
        break;
      }
    }
  }
  else if (window.ActiveXObject) {  // ActiveX style plugin detection
    for (x = 2; x <= flash_versions; x++) {
      try {
        oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
        if (oFlash) {
          flash_installed = 1;
          flash_version = x + '.0';
        }
      }
      catch(e) { }
    }
  }
  return flash_installed;
}
  
