
$(document).ready (function () {
   $('#cistRight').click (function () {
      if ( document.getElementById ('cistForm').style.display == 'none' ) {
         document.getElementById ('cistella').style.width = '253px';
         $('#cistForm').show ('slow');
         $('.BotigaCistProds').jScrollPane ({
            verticalDragMaxHeight: 100,
            showArrows: true
         });
      } else {
         $('#cistForm').hide ('slow');
         setTimeout ("document.getElementById ('cistella').style.width = '20px';", 700);
      }
   });
   $('.BotigaCataProdBbuy').click (function () {
      if ( document.getElementById ('cistForm').style.display == 'none' ) {
         document.getElementById ('cistella').style.width = '253px';
         $('#cistForm').show ('slow');
      }
   });
   $('#cistClosTop').click (function () {
      $('#cistForm').hide ('slow');
      setTimeout ("document.getElementById ('cistella').style.width = '20px';", 700);
   });
   $('#cistClosBot').click (function () {
      $('#cistForm').hide ('slow');
      setTimeout ("document.getElementById ('cistella').style.width = '20px';", 700);
   });
   $('.BotigaUsidHead').click (function () {
      set_vel (0);
      for (i = 1; i <= 3; i++) {
         hed = 'userHead'+i;
         img = 'userImag'+i;
         bod = 'userBody'+i;
         if ( hed == $(this).attr ('id') ) {
            if ( document.getElementById (bod).style.display == 'none' ) {
               $('#'+bod).slideDown ('slow');
               document.getElementById (img).src = '/img/fletxa_registre_act.png';
            } else {
               $('#'+bod).slideUp ('slow');
               document.getElementById (img).src = '/img/fletxa_registre.png';
            }
         } else {
            if ( document.getElementById (bod).style.display == 'block' ) {
               document.getElementById (bod).style.display = 'none';
               document.getElementById (img).src = '/img/fletxa_registre.png';
            }
         }
      }
      set_vel (1);
   });
});


function prod_imgs (num, act) {

   for (i = 0; i < num; i++) {
      if ( i != act ) {
         document.getElementById ('imgProd'+i).style.display = 'none';
         document.getElementById ('imgVel'+i).style.display = 'none';
      }
   }
   document.getElementById ('imgProd'+act).style.display = 'block';
   document.getElementById ('imgVel'+act).style.display = 'block';

}


function mark_pops (num, act) {

   for (i = 0; i < num; i++) {
      if ( i != act ) {
         document.getElementById ('markData'+i).style.display = 'none';
      }
   }

   lim = Math.round (screen.availWidth / 2) + 166;

   if ( myClickX > lim ) {
      tlef = lim - 300;
   } else {
      tlef = myClickX - 140;
   }
   ttop = myClickY - 180;
   document.getElementById ('markData'+act).style.top  = ttop+'px';
   document.getElementById ('markData'+act).style.left = tlef+'px';
   document.getElementById ('markData'+act).style.display = 'block';

}


function have_pos (obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent) {
      do {
         curleft += obj.offsetLeft;
         curtop  += obj.offsetTop;
      } while (obj = obj.offsetParent);
      return [curleft,curtop];
   } else {
      return [0,0];
   }
}

var myMouseX, myMouseY;
var myClickX, myClickY;

function getXYAbout (e) {
   myMouseX = (e||event).clientX;
   myMouseY = (e||event).clientY;
   if ( document.documentElement.scrollTop > 0 ) {
      myMouseY = myMouseY + document.documentElement.scrollTop;
   }
}  

function getXYWhere (e) {
   myClickX = (e||event).clientX;
   myClickY = (e||event).clientY;
   if ( document.documentElement.scrollTop > 0 ) {
      myClickY = myClickY + document.documentElement.scrollTop;
   }
}  
   

function set_vel (vel) {
   if ( vel == 1 ) {
      setTimeout ("document.getElementById ('formVel').style.height = $(document).height ()+'px';", 700);
   } else {
      document.getElementById ('formVel').style.height = screen.availHeight+'px';
   }
}

function obre_cond () {
   document.getElementById ('condicions').style.display = 'block';
   $('.BotigaCondBody').jScrollPane ({
      verticalDragMaxHeight: 100,
      showArrows: true
   });
}


function valida_info (msg1, msg2, msg3, msg4) {

   with (document.getElementById ('info')) {
      if ( /^\s*$/.test (info_email.value) ) {
         alert (msg1);
         info_email.focus ();
         return false;
      } else {
         if ( ! /^[A-Za-z0-9\.+_-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,6}$/.test (info_email.value) ) {
            alert (msg2);
            info_email.focus ();
            return false;
         }
      }
      if ( /^\s*$/.test (info_email2.value) ) {
         alert (msg1);
         info_email2.focus ();
         return false;
      } else {
         if ( ! /^[A-Za-z0-9\.+_-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,6}$/.test (info_email2.value) ) {
            alert (msg2);
            info_email2.focus ();
            return false;
         }
      }
      if ( info_email.value != info_email2.value ) {
         alert (msg3);
         info_email.focus ();
         return false;
      }
      if ( ! info_hlya.checked ) {
         alert (msg4);
         info_hlya.focus ();
         return false;
      }
   }

   return true;

}


