﻿/* Pfizer (Public Site) - Main functions */




var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17418851-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();





// dropdown menu variables
var timeout = 250;
var closetimer = 0;
var ddmenuitem = 0;






// returns a specific attribute from the URL
$.extend({
 getUrlVars: function(){
 var vars = [], hash;
 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 for(var i = 0; i < hashes.length; i++)
 {
 hash = hashes[i].split('=');
 vars.push(hash[0]);
 vars[hash[0]] = hash[1];
 }
 return vars;
 },
 getUrlVar: function(name) {
 return $.getUrlVars()[name];
 }
});


getQueryString = function( name )
{
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]"+name+"=([^&#]*)";
 var regex = new RegExp( regexS );
 var results = regex.exec( window.location.href );
 if( results == null )
return "";
 else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}


$(document).ready(function() {

/*substituir imagens do header consoante a página*/
/*
var sobre_nos = new Array (155, 152, 153, 156, 154, 151, 150);
var sua_saude = new Array (157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 203);
var iandd = new Array (173, 171, 172);
var sala_imprensa = new Array (85, 206);
var sites_pfizer = new Array (209, 0);
//var sobre_nos = new Array (146, 167);


var paginas = new Array(sobre_nos, sua_saude, iandd, sala_imprensa,sites_pfizer);


var idpagina = getQueryString('ID');


for (i = 0; i < paginas.length; i++){
   for(j = 0; j < paginas[i].length; j++){
      if(paginas[i][j] == idpagina)
         $('#dwtopimage').attr('src', '/Files/Billeder/PfizerPublico/Cabecalho/header' + i + '.jpg');
	break;
 }
}
*/









 /* insert the icon by adding a class */
 $('#bottomMenu li:eq(0) a').addClass('twitter-icon');
 $('#bottomMenu li:eq(1) a').addClass('rss-icon');
 /* remove the border-bottom from the news list*/
 if( $('.news').length > 0 ) {
 $('.news li:last').css('border-bottom', 'none');
 }


 /* dropdown menus acions */
 $('#jsddm > li').bind('mouseover', jsddm_open);
 $('#jsddm').bind('mouseout', jsddm_timer);
 /* resize the left column and append the search product form by area to the left column */
 if( $('#searchProductByArea').length > 0 ) {
 var menuHeight = $('#leftSideContainer').height(),
 formHeight = $('#searchProductByArea').height() + 10,
 contentHeight = $('#centerContainerData').height();
 if( menuHeight + formHeight < contentHeight ) {
 $('#leftSideContainer').height( $('#content').height() );
 $('#leftSideContainer').append( $('#searchProductByArea') );
 $('#searchProductByArea').css({'position': 'absolute', 'display': 'block'});
 }
 else {
 $('#leftSideContainer').append( $('#searchProductByArea') );
 $('#searchProductByArea').css({'display': 'block'});
 $('#centerContainer').height( $('#content').height() );
 }
 }
 else {
 if( $('#leftSideContainer').length > 0 ) {
 $('#leftSideContainer').height( $('#content').height() );
 $('#centerContainer').height( $('#content').height() );
 }
 }
 $('#jsddm').children('li').each(function(cont){
$(this).addClass('item' + cont); 
 });


 /* remove the top padding and the bottom border*/
 $('.overallNews li:first').css('padding-top', '0px');
 $('.overallNews li:last').css('border-bottom', 'none');


 /* set up the total pages on the news page */
 if( $.getUrlVar('ID') == '85' ) {
 var cleanNumber = "";
 var pageValue = $('#hiddenTotalPages a:last').html();
 if( pageValue.indexOf('<B>') != -1 ) {
 cleanNumber = pageValue.substring( pageValue.indexOf('<B>') + 3, pageValue.length - 4 );
 $('#hiddenTotalPages a').html(cleanNumber);
 }
 else {
 if( pageValue.indexOf('<b>') != -1 ) {
 cleanNumber = pageValue.substring( pageValue.indexOf('<b>') + 3, pageValue.length - 4 );
 $('#hiddenTotalPages a').html(cleanNumber);
 }
 }
 $('#totalPageNumbers').append( $('#hiddenTotalPages a:last') );
 }
 $('#password').focus(function() {
 $(this).css('background-image', 'none');
 });
 $('#password').blur(function() {
 if( $(this).val() == "" )
 $(this).css('background-image', 'url(Files/System/PfizerPublico/images/passwordBackground.gif)');
 });
 $('#confirmation').focus(function() {
 $(this).css('background-image', 'none');
 });
 $('#confirmation').blur(function() {
 if( $(this).val() == "" )
 $(this).css('background-image', 'url(Files/System/PfizerPublico/images/confPassBackground.gif)');
 });
 /* reposition the last dropdown list from the menu */
 if( $('.menuWithoutBar ul').width() > $('.menuWithoutBar').width() ) {
 var delta = -( $('.menuWithoutBar ul').width() - $('.menuWithoutBar').width() );
 delta += "px";
 $('.menuWithoutBar ul').css('margin-left', delta);
 }
 /* IE6 fixes */
 if( $.browser.msie && $.browser.version.substring(0,1) == "6" ) {
 var marginToMove;
 $('.submenu').each(function(i) {
 marginToMove = $(this).parent().width() * -1 - 3;
 $(this).css('margin-left', marginToMove);
 });
 /* change the send input button layout of the registration page on hover state */
 $('#submitter').hover(function() {
 $(this).css({'background-color': '#007dc3', 'color': '#81c6ec', 'border-color': '#007dc3', 'cursor': 'pointer'});
 }, function() {
 $(this).css({'background-color': '#81c6ec', 'color': '#007dc3', 'border-color': '#81c6ec', 'cursor': 'default'});
 });
//$('.menuWithoutBar ul').css('margin-left', '0px'});
 }
 /* set the height of the banners' ParagraphText equal on both elements */
 if( $('#secondLine').length > 0 && $('#secondLine .firstColumn .ParagraphText').height() != $('#secondLine .secondColumn .ParagraphText').height() ) {
 if( $('#secondLine .firstColumn .ParagraphText').height() > $('#secondLine .secondColumn .ParagraphText').height() )
 $('#secondLine .secondColumn .ParagraphText').height( $('#secondLine .firstColumn .ParagraphText').height() );
 else
 $('#secondLine .firstColumn .ParagraphText').height( $('#secondLine .secondColumn .ParagraphText').height() );
 }
});


/* sets up the advanced search parameters */
function searchProduct() {
 var globalURL = "Default.aspx?ID=186";
 var productName = $('#productName').val();
 var productArea = $('#productArea').val();
 if( productName == "Nome" ) {
 if( productArea == "Área terapêutica" )
 alert( "Dados de pesquisa incorrectos." );
 else
 location.href = globalURL + "&eComSearch=1&Category=" + productArea + "&Category_Type=0";
 }
 else {
 if( productArea == "Área terapêutica" )
 location.href = globalURL + "&eComSearch=1&ProductName=" + productName + "&ProductName_Type=0";
 else
 location.href = globalURL + "&eComSearch=1&ProductName=" + productName + "&ProductName_Type=0&Category=" + productArea + "&Category_Type=0"; 
 }
}






/* resets the general search box text to its default value */
function checkIfEmpty( input, defaultValue ) {
 if( ( $('#'+input).val() == "" ) || $('#'+input).val().toLowerCase() == defaultValue.toLowerCase() )
 $('#'+input).val( defaultValue );
}


/* clears the general search box text */
function clearField( input, defaultValue ) {
 if( ( $('#'+input).val() == "" ) || ( $('#'+input).val().toLowerCase() == defaultValue.toLowerCase() ) ){
 	$('#'+input).val("");
	}
}




/* dropdown menus functions */
function jsddm_open(){
 jsddm_canceltimer();
 jsddm_close();
 ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function jsddm_close(){
 if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
function jsddm_timer(){
 closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer(){
 if( closetimer ) {
 window.clearTimeout(closetimer);
 closetimer = null;
 }
}






/* checks if the general search box value isn't empty or if it's not equal to the default value */
function ValidateSearch( errorMessage, defaultValue ) {
 if( ( $('#searchText').val() == "" ) || ( $('#searchText').val().toLowerCase() == defaultValue.toLowerCase() ) ) {
 alert( errorMessage );
 return false;
 }
}
