$(document).ready(function(){
  $("form.main-form input[type!='image'][type!='submit']").addClass("input-text");
  $("form.main-form input[type='submit']").addClass("input-button");

  var imagesList=[
    '/xtpl/assets/i/buttons/page.n_bg.png',
    '/xtpl/assets/i/buttons/page.p_bg.png',
    '/xtpl/assets/i/buttons/page.p.png',
    '/xtpl/assets/i/buttons/page.n.png'];
  var aImages = [];
  for(var i=0,len=imagesList.length;i<len;i++) { aImages[i]=new Image(); aImages[i].src=imagesList[i]; }
});

/*
  patches in script.js
  
 +if($(".model-gallery .gallery_view .model-item-view").length>1)
  $(".model-gallery .gallery_view").jCarouselLite({
  
*/

/// legacy, forms.js
  var tf = new Array()
  var rf = new Array()
  var sf = new Array()
  var sb = null

  function reg_sb (fstr)
  {  sb=document.getElementById(fstr) }

  function reg_text (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    tf2 = fstr.split (' ')
    for(i=0;i<tf2.length;i++) tf.push(tf2[i])
    validate();
  }

  function reg_select (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    sf2 = fstr.split (' ')
    for(i=0;i<sf2.length;i++) sf.push(sf2[i])
    validate();
  }

  function reg_radio (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    rf2 = fstr.split (' ')
    for(i=0;i<rf2.length;i++) rf.push(rf2[i])
    validate();
  }

  function unreg_text (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    tf2 = fstr.split (' ')
    for(i=0;i<tf2.length;i++)
      for(j=0;j<tf.length;j++)
      if (tf[j] == tf2[i]) tf[j] = ""
    devalidate(fstr)
  }
  function unreg_select (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    sf2 = fstr.split (' ')
    for(i=0;i<sf2.length;i++)
      for(j=0;j<sf.length;j++)
      if (sf[j] == sf2[i]) sf[j] = ""
    devalidate(fstr)
  }

  function unreg_radio (fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    rf2 = fstr.split (' ')
    for(i=0;i<rf2.length;i++)
      for(j=0;j<rf.length;j++)
      if (rf[j] == rf2[i]) rf[j] = ""
    devalidate(fstr)
  }

  function validate()
  {
    var ok = true

    if (tf)
    {
      for (c = 0; c != tf.length; c++) if (tf[c] != "")
      {
        var input = (document.getElementsByName(tf[c]))[0]
        var label = document.getElementById('L'+tf[c])
        if (input && label)
        {
          var value = input.value
          value = value.replace (/^\s+/g, "")
          value = value.replace (/\s+$/g, "") 
          if (value == '') ok = false
          if (label) label.className = value != '' ? "valid" : "rq"
        }
      }
    }
    //
    if (rf)
    {
      for (c = 0; c != rf.length; c++) if (rf[c] != "")
      {
        var inputs = document.getElementsByName(rf[c])
        var label = document.getElementById('L'+rf[c])
        if (inputs && label)
        {
          var local_ok=false
          for (i=0;i<inputs.length;i++) if (inputs[i].checked) local_ok=true;
          if (!local_ok) ok = false
          if (label) label.className = local_ok ? "valid" : "rq"
        }
      }
    }
    
    if (sf)
    {
      for (c = 0; c != sf.length; c++) if (sf[c] != "")
      {
        var input = (document.getElementsByName(sf[c]))[0]
        var label = document.getElementById('L'+sf[c])
        if (!input.selectedIndex) ok = false
        if (label) label.className = input.selectedIndex ? "valid" : "rq"
      }
    }

    if (sb) sb.disabled = !ok
  }

  function devalidate(fstr)
  {
    fstr = fstr.replace (/\s+$/g, "")
    f1 = fstr.split (' ')
    if (f1)
    {
      for (c = 0; c != f1.length; c++) if (f1[c] != "")
      {
        var label = document.getElementById('L'+f1[c])
        label.className = "valid"
      }
    }
  }

if ((navigator.appName.indexOf("Internet Explorer") != -1) &&
(navigator.userAgent.indexOf("Opera") == -1)){               
  bw_type = "ie";                                          
}else if (navigator.appName.indexOf("Netscape") != -1){      
  bw_type = "nn";                                          
  if (parseInt(navigator.appVersion) >= 5){                
    bw_type += "6";                                      
  }                                                        
}else if (navigator.userAgent.indexOf("Opera") != -1){       
  bw_type = "op";                                          
}else{                                                       
  bw_type="other";                                         
}                                                            

var arr=new Array();
function refresh_years(mid)
{
  m=arr[mid];
  s=document.getElementById('f_uc').uc_year;
  s.selectedIndex=0;
  if(bw_type=="op") for(i=s.options.length;i>0;i--) s.options.remove(i);
  else s.options.length=1;
  for(i=1;i<m.length;i++)
  {
    var o = document.createElement("OPTION");
    if(bw_type=="op") s.options.add(o);
    o.innerText = m[i];
    o.Value = m[i];
    if(bw_type!="op") s.options[i]=new Option(m[i],m[i]);
  }
}
