
function showModels(s) {
   $('.models').each(function(z) {
      z.hide();
   });
   $('#models_'+s.value).show();
}

function showSeries(s) {
   $('.series').each(function(z) {
      z.hide();
   });
   $('#series_'+s.value).show();
}

	 function validate_form () {
	  if (!document.getElementsByTagName) return true;
	  
	  var reqfields = Array();
	  var ri = 0;
	  
     var labels=document.getElementsByTagName("label");
     var inputs=document.getElementsByTagName("input");
     
     for (var i=0; i < inputs.length; i++) {
      for (var i2=0; i2 < labels.length; i2++) {
       if (labels[i2].htmlFor == inputs[i].id && labels[i2].className == "req" && labels[i2].parentNode.className !== "hide") {
         if (inputs[i].value == "") {
         	inputs[i].style.borderColor='red';
         	reqfields[ri] = labels[i2].innerHTML;
         	ri++;
         } else inputs[i].style.borderColor = '#bac2c5';
       }
      }
     }
     if (reqfields.length > 0) {
     	error = "Lūdzu aizpildiet arī šos laukus:\n";
     	for (var i=0; i < reqfields.length; i++) {
     		error = error + " - " + reqfields[i].replace(":","") +"\n";
     	}
     	alert(error);
     } else {
      return true;
     }
     return false;
	 } 
	 
$(function(){

	
	/*$(".largeImg a").livequery(function(){ $(this).fancybox({
		'titlePosition' 	: 'over',
		'centerOnScroll': false,
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '<a style="float: right; color: white;font-weight:bold;" href="javascript:$(window).trigger(\'hashchange\')">Back to ad</a></span>';
		},
		'onClosed'		: function() {
	      $.bbq.removeState();
	   }
   });
   });
   */
	
	$('.filterbox input[type=text]').each(function() {
	  if ($(this).val() == '') {
	     if ($(this).hasClass('from')) {
	        $(this).val('From...');
	        $(this).addClass('label');
	     }
	     if ($(this).hasClass('to')) {
	        $(this).val('To...');
	        $(this).addClass('label');
	     }
	     var orig = '';
	     $(this).focus(function() {
	        if ($(this).val() == 'From...' || $(this).val() == 'To...') {
	           orig = $(this).val();
	           $(this).removeClass('label');
	           $(this).val('');
	        }
	     })
	     $(this).blur(function() {
	        if ($(this).val() == '' || $(this).val() == ' ') {
	           $(this).val(orig);
	           $(this).addClass('label');
	        }
	     })
	  }
	});
	
	
   $('a[rel=noSpam]').each(function(m) {
      var array = $(this).attr("title");
      array = array.split(" ");
      var email = array[2]+"@"+array[1]+"."+array[0];
      $(this).html(email);
      $(this).attr("href",'mailto:'+email);
      $(this).attr("title",'');
   });   
   
   // jquery bbq && hashchange
   $(window).bind( 'hashchange', function(e) {
      var url = $.deparam(e.fragment);
      //console.log("/modules/catalog/ajaxform.php?id="+url.id+"");
      if (url.id) {
         id = parseInt(url.id);
         openObject(id);
      }
   });
   setTimeout ("$(window).trigger( 'hashchange' )",300);
   
   //openObject(12);
   
    jQuery('#mycarousel').jcarousel();
    
    $('a[rel=gallery]').fancybox({
	      'onClosed'		: null,
	      titleFormat			:	function(title, currentArray, currentIndex, currentOpts) {
		      return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		   }
      });
      
    $('#sendRequest input[name=otherid]').val($('#sendRequest input[name=userid]').val());
});

function openObject(id) {
      $.fancybox({
         href: "/modules/catalog/ajaxform.php?id="+id+"",
         overlayOpacity: 0.8,
         overlayColor: '#fdd518',
         autoDimensions: true,
         autoScale: false,
         padding: 0,
         margin: 0,
         scrolling: false,
         titleShow: false,
         centerOnScroll: false,
	      'onClosed'		: function() {
	         $.bbq.removeState();
	      }
      });
      
      $('#hashchange').live('click', function() {
         $(window).trigger('hashchange');
         return false;
      });
}

function showImg(img) {
   $('.largeImg').hide();
   $('#'+img).show();
}

function changeCat(cat,cid) {
      $('#search').block({ 
         message: '<img src="/img/indicator3.gif" alt="" />',
         css: { 'border':'0','background':'none'} 
      });
      
      conf = { 
         cid: cat,
         maincid: cid,
         lng: 'en'
      };
      
      $.get("/modules/catalog/ajaxform.php",conf,function(data){
         $('#search').unblock();
         $("#searchbox").html(data);
      });
      
}

var win=null;
function printIt(printThis)
{
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><link rel="stylesheet" href="//default.css.php"><link media="print" rel="stylesheet" href="//print.css">');
	//win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
	win.document.write(printThis);
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print();
	win.close();
}

