﻿/*********************************************************************
*** (C) OK-Systems,2008 (All rights reserved)                      ***
*** Don't make any changes without reporting to oks@ok-systems.com ***
**********************************************************************
*** File____: fu_viking.js                                         ***
*** Project_: Viking                                               ***
*** Language: JavaScript                                           ***
*** Tier____: Presentation-services                                ***
*** Author__: Antonio Olmedo Soler                                 ***
*********************************************************************/


//==================================================
// BUTTON EVENT HANDLERS
//==================================================

//--------------------
//- Created_: 21-Jan-2002, Antonio Olmedo Soler
//- Modified: 14-Mar-2002, Antonio Olmedo Soler
//- Syntax__: BtnOver(e)
//- Description: Change Button image 
//--------------------
function BtnOver(e) {
	try {
		e.src=e.src.replace('btn','bt2');
		/*
		var oBubble=document.all.Bubble;
		if (oBubble) {
			oBubble.className='Bubble';
			var cMsg='';
			if (e.src.match('home')) {
				cMsg='<B>Página principal</B><BR>Portada del Web de Viking España.';
			} else if (e.src.match('intro')) {
				cMsg='<B>Presentación</B><BR>Folleto describiendo la compañía y sus productos.';
			} else if (e.src.match('contact')) {
				cMsg='<B>Cómo contactar con Viking</B><BR>Formulario de solicitud de información.';
			} else if (e.src.match('faq')) {
				cMsg='<B>Preguntas frecuentes</B>';
			} else if (e.src.match('form')) {
				cMsg='<B>Formación</B><BR>Seminarios Viking.';
			} else if (e.src.match('links')) {
				cMsg='<B>Enlaces</B><BR>Direcciones Web interesantes.';
			} else if (e.src.match('docs')) {
				cMsg='<B>Documentos</B><BR>Hojas técnicos, manuales,<BR>legistación, etc.';
			} else if (e.src.match('price')) {
				cMsg='<B>Listas de precios</B>';
			} else if (e.src.match('shop')) {
				cMsg='<B>La tienda Viking</B><BR>Consulte el catálogo de productos<BR>y envíe su solicitud.';
			} else if (e.src.match('index')) {
				cMsg='<B>Indice de contenidos</B><BR>Mapa del Web';
			} else if (e.src.match('vikingcorp')) {
				cMsg='Ir al Web de Viking Corporation<BR>(en inglés)';
			} else if (e.src.match('next')) {
				cMsg='Pasar a la siguiente página.';
			//}else {
			//	cMsg=e.src;
			}
			oBubble.innerHTML=cMsg;
		}
		*/
	} catch(oError) {}
	return void(null);
}

//--------------------
//- Created_: 21-Jan-2002, Antonio Olmedo Soler
//- Modified: 14-Mar-2002, Antonio Olmedo Soler
//- Syntax__: BtnOut(e)
//- Description: Change Button image 
//--------------------
function BtnOut(e) {
	try { 
		e.src=e.src.replace('bt2','btn'); 
		/*
		var oBubble=document.all.Bubble;
		if (oBubble) {
			oBubble.className='';
			oBubble.innerHTML='';
		}
		*/
	} catch(oError) {}
	return void(null);
}

//==================================================
// fu_shop.js
//==================================================


//--------------------
//- Created_: 31-Jan-2002, Antonio Olmedo Soler
//- Modified: 15-May-2002, Antonio Olmedo Soler
//- Syntax__: CheckProduct(oCheck)
//- Description: Change Button image 
//--------------------
function CheckProduct(chk) {
	//try {
		//var oForm=document.forms[0];
		var oForm=chk.form;
		if (oForm) {
			var oQuantity=oForm['Q_'+chk.value];
			if (oQuantity) oQuantity.value=(chk.checked?'1':'');
		}		
	//} catch(e) {}
	return void(null);
}


//--------------------
//- Created_: 01-May-2002, Antonio Olmedo Soler
//- Modified: 14-May-2002, Antonio Olmedo Soler
//- Syntax__: Confirm_Delete(oForm)
//- Description: 
//--------------------
function Confirm_Delete(oForm) {
	if (confirm('Por favor, confirme que desea eliminar de la solicitud los productos marcados')) {
		oForm.btnRemove.value='Remove';
		oForm.submit();
	}
	return void(null);
}


//--------------------
//- Created_: 01-May-2002, Antonio Olmedo Soler
//- Modified: 29-Mar-2005, Antonio Olmedo Soler
//- Syntax__: Validate_Field(e,cName)
//- Description: 
//--------------------
function Validate_Field(e,cName) {
	//alert('Validate_Field('+e+','+cName+')');
	try {
		if (e.value) return true;
		alert('`El campo '+cName+' es obligatorio !');
		try { e.focus(); } catch (e) {}
		return false;
	} catch(oError) {}
	return true;
}

//--------------------
//- Created_: 29-03-2005, Antonio Olmedo Soler
//- Modified: 29-03-2005, Antonio Olmedo Soler
//- Syntax__: IsValid_Email(cValue)
//- Description: Check if the field value is a valid e-mail address
//- Notes___: Found in www.aspfaq.com/show.asp?id=2238
//--------------------
function IsValid_Email(cValue){
	return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(cValue);
} 


//--------------------
//- Created_: 01-May-2002, Antonio Olmedo Soler
//- Modified: 05-May-2002, Antonio Olmedo Soler
//- Syntax__: Validate_Order()
//- Description: 
//--------------------
function Validate_Order() {
	//alert('Validate_Order');
	try {
		var frm=document.frm;
		//if (!frm.OrderItems.value) {
		//	alert('No se puede enviar la solicitud de oferta porque no ha seleccionado ningún producto  !');
		//	return false;
		//}
		//if (!Validate_Field(frm.Name,'Nombre'))	return false;
		//if (!Validate_Field(frm.EMail,'E-mail'))	return false;
	} catch(oError) {}
	return true;
}


//--------------------
//- Created_: 16-May-2002, Antonio Olmedo Soler
//- Modified: 16-May-2002, Antonio Olmedo Soler
//- Syntax__: Object_FormValidate(frm,cClassName)
//- Description: 
//--------------------
function Object_FormValidate(frm,cClassName) {
	//alert('Object_FormValidate');
	try {
		var cFoo=cClassName+"_FormValidate(document.forms['"+frm.name+"'])";
		return (eval(cFoo));
	} catch(oError) {}
	return true;
}

//--------------------
//- Created_: 16-May-2002, Antonio Olmedo Soler
//- Modified: 28-Aug-2002, Antonio Olmedo Soler
//- Syntax__: Object_FormValidate(frm,cClassName)
//- Description: 
//--------------------
function Customer_FormValidate(frm) {
	//alert('Customer_FormValidate('+frm+')');
	try {
		if (!Validate_Field(frm.Customer_email,'E-mail'))		return false;
		if (!Validate_Field(frm.Customer_pwd,'Contraseña'))		return false;
		if (!Validate_Field(frm.Customer_name,'Nombre'))		return false;
		if (!Validate_Field(frm.Customer_company,'Compañía'))	return false;
	} catch(oError) {}
	return true;
}

//==================================================
// ADAPTED FROM VIKINGCORP.COM
//==================================================

/* -----------------------------------
   rotating home page items
   ----------------------------------- */
var image_count;
var headline_count;
var word_count;
var current_image=0;
var current_headline=0;
var current_word=0;

$(document).ready(function(){
  image_count = $("#banner div").hide().size();
  headline_count = $("div.headline").hide().size();
  $("#banner div:eq("+current_image+")").show();
  $("div.headline:eq("+current_headline+")").show();
  setInterval(feature_rotate,5000); //time in milliseconds
});

function feature_rotate() {
  old_image = current_image%image_count;
  new_image = ++current_image%image_count;
  $("#banner div:eq(" + new_image + ")").fadeIn("slow", function() {
    $("#banner div:eq(" + old_image + ")").fadeOut("slow");
  });

   old_headline = current_headline%headline_count;
   new_headline = ++current_headline%headline_count;
  $("div.headline:eq(" + new_headline + ")").fadeIn("slow", function() {
    $("div.headline:eq(" + old_headline + ")").fadeOut("slow");
  });
}

/* -----------------------------------
   drow-down menu
   ----------------------------------- */

$(document).ready(function(){
  
  $('#primary-nav > ul > li').each(function(i) {
    var timeOut;
    $('li:last',this).height('15px');
    $(this).hover(function(){
     clearTimeout(timeOut);
     $('#primary-nav > ul > li > ul').css('display','none');
     $('> ul', this).css('display','block');
     if ($.browser.msie) {
       var $this_ul = $('> ul', this);
       if ($this_ul.length) {
         $this_ul.prepend("<iframe></iframe>");
         $('iframe', this).height($this_ul.get(0).offsetHeight + 'px');
       }
     };
    },function(){  // on mouseOut
     var self = this;
     timeOut = setTimeout(function() {
       $('> ul', self).css('display','none');
       if ($.browser.msie) {
         $(self).find('iframe').remove();  
       };
     },300);
   });
 });

  $('#primary-nav > ul > li:lt(6) ul > li').each(function(i) {
    var timeOutSub;
    if ($('> ul', this).size() > 0) {
      $('> a', this).addClass('has-subnav');
      $('> a.active', this).removeClass().addClass('active-has-subnav');

      $(this).hover(function(){ //this part is for mouseOver
        clearTimeout(timeOutSub);
        $(this).parent().find('li:not(this) ul').css('display','none');
        $('> ul', this).css({display:'block',visibility:'visible'});
        if ($.browser.msie) {
          var $this_ul = $('> ul', this);
          $this_ul.prepend("<iframe></iframe>");
          $('iframe', this).height($this_ul.get(0).offsetHeight + 'px');
        };
      },function(){ // on mouseOut
        var self = this;
        timeOutSub = setTimeout(function() {
          $('> ul', self).css({display:'none',visibility:'hidden'});
          if ($.browser.msie) {
            $(self).find('iframe').remove();  
          };
        },300);
      });
    }      
  });
}); // end document ready

/* -----------------------------------
   calculate feature word text color
   ----------------------------------- */
   
$(document).ready(function() {
  $('div.headline-container').each(function(i) {
    var feature_red = 0;
    var feature_green = 0;
    var feature_blue = 0;
    var headline_background = $('div.headline', this).css('backgroundColor');
    if (headline_background.match(/^#/)) {
      var headline_rgb = $('div.headline', this).css('backgroundColor').match(/^#(..)(..)(..)/);
      var feature_red = Math.floor(50 + (parseInt(headline_rgb[1],16)/1.25));
      var feature_green = Math.floor(50 + (parseInt(headline_rgb[2],16)/1.25));
      var feature_blue = Math.floor(50 + (parseInt(headline_rgb[3],16)/1.25)); 
    } else {
      var headline_rgb = $('div.headline', this).css('backgroundColor').match(/^rgb\(([\d]*),\s*([\d]*),\s*([\d]*)/);
      var feature_red = Math.floor(50 + (parseInt(headline_rgb[1])/1.25));
      var feature_green = Math.floor(50 + (parseInt(headline_rgb[2])/1.25));
      var feature_blue = Math.floor(50 + (parseInt(headline_rgb[3])/1.25));
    }
    $('div.feature-word', this).css('color','rgb(' + feature_red + ',' + feature_green + ',' + feature_blue + ')');   

  });
});

/* -----------------------------------
   show and hide product info
   ----------------------------------- */

var show_hide;

$(document).ready(function(){
  $(document).bind('unload', function(event) {
    $('li').unbind('mouseout').unbind('mouseover');
    show_hide = null;
  });
  
  $('div.results').hide();

  show_hide = function() {
    $('div.product-info a.inactive-link').click(show_hide);
    $('a.show-hide').removeClass('inactive-link');
    $(this).unbind("click");
    $(this).click(function() {
      return false;
    });
    $(this).addClass('inactive-link');
    $('div.results:visible').slideUp('medium');
    $(this).parent().find('div.results:hidden').slideDown('medium');
    return false;
  };

  $('a.show-hide').click(show_hide);

}); // end document ready
