$(document).ready(function(){

    // start colorbox
  $("a[rel='colorbox-group']").colorbox({slideshow:true});   
  $(".contactus").colorbox({width:"560px", height:"80%", iframe:true});
      
   $(".external").click(function(){      
     window.open($(this).attr("href"));
     return false;      
    });
  
  // Google analytics refer
  $(".externalrefer").click(function(){      
    var url = location.href;
    var externalrefer= $(this).attr("href");   
              // 
      _gaq.push(['_trackEvent', 'External reference', externalrefer, url]);
    
    window.open(externalrefer);
    return false;
  });
  // end google analytics
  
  
  
  
  
  $('#countryselector').change(function() {
    
    var country = $(this).val();
    var place =  $('#placeselector').val();
    var type =   $('#typeselector').val();
    var quantity =  $('#quantityselector').val();
    var query = "?c="+country + "&pl=" +place + "&t=" + type + "&q=" + quantity;    
    
    window.location.replace(query);
    return false;
  });  
  
    $('#placeselector').change(function() {
      
    var country = $('#countryselector').val();
    var place =  $(this).val();
    var type =   $('#typeselector').val();
    var quantity =  $('#quantityselector').val();
    var query = "?c="+country + "&pl=" +place + "&t=" + type + "&q=" + quantity;    
    
    window.location.replace(query);
    return false;      
    
  });  
  
      $('#typeselector').change(function() {
        var country = $('#countryselector').val();
        var place =   $('#placeselector').val();
        var type =   $(this).val();
        var quantity =  $('#quantityselector').val();
        var query = "?c="+country + "&pl=" +place + "&t=" + type + "&q=" + quantity;    
    
    window.location.replace(query);
    return false;         
 
  });
  $('#quantityselector').change(function() {
    var country = $('#countryselector').val();
    var place =   $('#placeselector').val();
    var type =   $('#typeselector').val();
    var quantity =  $(this).val();
    var query = "?c="+country + "&pl=" +place + "&t=" + type + "&q=" + quantity;    
    
    window.location.replace(query);
    return false;  
    
   
  });
    
  
  $(window).resize(function()
  {
    setBackground();
  });      
  setBackground();
});
function setBackground()
  {
  // get BROWSER Height / width
    var browserwidth = $(window).width();

    var maxWidth = (browserwidth - 960)/2;
    var maxLoginWidth = 265;
    var maxContentWidth = 960;
    var loginWidth = (maxLoginWidth + maxWidth);
    var contentWidth = (browserwidth );



    if(browserwidth <= 960)
    {
 
      $("#loginholder").css({ 'width' : maxLoginWidth });
      $("#header").css({ 'width' : maxContentWidth });
       $("#footer").css({ 'width' : maxContentWidth });
    }
    
    if(browserwidth > 960)
    {
      $("#loginholder").css({ 'width' : loginWidth });
      $("#header").css({ 'width' : contentWidth });
      $("#footer").css({ 'width' : contentWidth });
    }    
  }
// login
jQuery(document).ready(function(){



  jQuery("#loginform").validate({
    submitHandler: function(form) {
      jQuery("#loginform").hide();
      jQuery("#loginformLoader").show();
      jQuery("#loginform #submit").attr("enabled", false);
      
      var url = "/base/forms/login";
      
    jQuery.post(url, { username: jQuery("#loginform #username").val(),
                       password: jQuery("#loginform #password").val()                       
                      },
                   function(data){
                   
                   jQuery("#loginformLoader").hide();
                   
                    if(data == 0){
                      jQuery("#loginformMessage").show().html("Error");
                    }
                    if (data == 1) {                      
                      // hide form after 2 sek.                      
                            $(function() {
                                setTimeout(function(){                                                                                                               
                                  window.location.href = '/';                           
                                    }, 100);
                            });                     
                           
           
                           }      
                     /* error on login */
                     if (data == 2) {
                       jQuery("#loginform").show();   
                       jQuery("#form-error").show();   

                     }
                    
                   }); /* end post */
        

      }
      }); /* end validate */
    });

// logout
jQuery(document).ready(function(){
  
  jQuery("#logoutform").validate({
    submitHandler: function(form) {
      jQuery("#logoutform").hide(); 
      
      var url = "/base/forms/logout";
      
      
    jQuery.post(url, 
                function(data){                  
                                 
                    if(data == 0){
                          jQuery("#loginformMessage").show().html("Error");
                    }
                    if (data == 1) {                      
                      // hide form after 2 sek.                      
                            $(function() {
                                setTimeout(function(){                                                                                                               
                                        window.location.href = '/';                           
                                    }, 100);
                            });             
                           }    
                    
                   }); /* end post */
        

      }
      }); /* end validate */
    });


// contact form
jQuery(document).ready(function(){

  jQuery("#contact").validate({

    submitHandler: function(form) {
      jQuery("#contact").hide(); 
      jQuery("#contactload").show(); 
      
      var id = $("#pageid").val();
      
      var url = "/base/forms/simplepost/"+id;
      
          jQuery.post(url, { 
            Company: jQuery("#txtCompany").val(),
            Contact: jQuery("#txtName").val(), 
            Telephone: jQuery("#txtTelephone").val(),
            Email: jQuery("#txtEmail").val(),
            Reference: jQuery("#txtAbout").val(),
            Message: jQuery("#txtMessage").val()
          },
      function(data){                                                                          
        jQuery("#contactload").hide(); 
        if(data == 0){
          jQuery("#contacterror").show();
        }
        if (data == 1) {                      
          // hide form after 5 sek.     
             jQuery("#contactconfirm").show();
          $(function() {
            setTimeout(function(){                                                                                                               
             parent.$.fn.colorbox.close();                         
            }, 5000);
          });             
        }                        
      }); /* end post */        

      }
      }); /* end validate */
    });

