document.write("<script type=\"text/javascript\" src=\"http://www.google.com/jsapi?key=ABQIAAAAStTJ73QWEGb_WG0FBUJxhRQ0mxjROmXlohMqNtwUTUG98dpwCxRDgtUZPSPoJelf1E8zQFIM-CspWg\"></script>");
document.write("<script src=\"http://www.google.com/jsapi\"></script>");
function open_popup(_1,_2,_3,_4){
prefs="resizable=no,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+_3+",height="+_4;
thWin=window.open(_1,_2,prefs);
thWin.focus();
};
function open_popup_scroll(_5,_6,_7,_8){
prefs="resizable=no,scrollbars=yes,scrolling=1,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+_7+",height="+_8;
thWin=window.open(_5,_6,prefs);
thWin.focus();
};
function changeLanguage(_9){
cookieName="SibLang";
chLang="";
if(_9=="en"){
window.location="../../en_UK/main/index_en.html";
}else{
if(_9=="es"){
window.location="../../es_ES/main/index_es.html";
}else{
if(_9=="fr"){
window.location="../../fr_FR/main/index_fr.html";
}else{
if(_9=="it"){
window.location="../../it_IT/main/index_it.html";
}else{
if(_9=="de"){
window.location="../../de_DE/main/index_de.html";
}
}
}
}
}
};
var chosLang="en_UK";
function openGlossary(_a){
filename="../../cgi-bin/en_UK/popup_glossary_en.pl?search="+_a;
glossary=window.open(filename,"glossary","toolbar=no,resize=yes,status=no,scrollbars=yes,personalbar=no,menubar=no,width=330,height=196");
};
function open_pic(_b,_c,_d,_e){
prefs="resizable=no,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+_d+",height="+_e;
thWin=window.open(_b,_c,prefs);
thWin.focus();
};
function open_pic_scroll(_f,_10,_11,_12){
prefs="resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+_11+",height="+_12;
thWin=window.open(_f,_10,prefs);
thWin.focus();
};
function open_hygienetips(_13){
path=_13;
name="hygiene";
width=560;
height=400;
prefs="resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+width+",height="+height;
thWin=window.open(path,name,prefs);
};
function opennofrenchpopup(){
path="../main/nofrench.html";
name="nofrench";
width=300;
height=250;
prefs="resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,width="+width+",height="+height;
thWin=window.open(path,name,prefs);
};
function openWhatIs(){
filename="../../en_UK/main/popup_whatisit.html";
glossary=window.open(filename,"glossary","toolbar=no,resize=yes,status=no,scrollbars=no,personalbar=no,menubar=no,width=420,height=260");
};
function openFilesafeAni(){
filename="../../en_UK/main/popup_filesafe.html";
glossary=window.open(filename,"illustrate","toolbar=no,resize=yes,status=no,scrollbars=no,personalbar=no,menubar=no,width=330,height=196");
};
function popUpWindow(_14,w,h){
ref=window.open(_14,"popupwindow","status=no,scrollbars=no,scrolling=0,resizable=no,width="+w+",height="+h+",top=10,left=10,locationbar=no");
};
function popUpScrollWindow(_17,w,h){
ref=window.open(_17,"popupwindow","status=no,scrollbars=yes,scrolling=1,resizable=no,width="+w+",height="+h+",top=10,left=10,locationbar=no");
};
function bookIt(_1a){
var _1b=new Array();
_1b=_1a.split("|");
if(document.all){
window.external.AddFavorite(_1b[0],_1b[1]);
}else{
alert("Sorry. Netscape users must bookmark the pages manually by hitting <Ctrl-D>");
}
};
function interestChange(){
param=document.forms[interestFormName].topic.value;
if(param=="ScientificPublications"){
redir="../../cgi-bin/en_UK/scientificpublications_en.pl";
}
if(param=="ProductSafetyData"){
redir="../../en_UK/product/productcompsitions_en.html";
}
if(param=="EnvironmentalMonitoring"){
redir="../../en_UK/safety/envmodelling_en.html";
}
if(param=="SafetyAssessment"){
redir="../../en_UK/safety/riskassessment_en.html";
}
if(param=="Animations"){
redir="../../en_UK/main/multimedia_en.html";
}
if(param=="ConsumerResearch"){
redir="../../en_UK/research/consumerresearch_en.html";
}
if(param=="ProductDevelopment"){
redir="../../en_UK/research/product_development_en.html";
}
if(param=="FateProcesses"){
redir="../../en_UK/safety/fateprocess_en.html";
}
document.location.href=redir;
};
var count=0;
function setCount(){
count=1;
};
function getCont(div){
var _1d=document.getElementsByTagName("title")[0].innerHTML;
var _1e="";
_1e+="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
_1e+="<html xmlns=\"http://www.w3.org/1999/xhtml\">";
_1e+="<head>";
_1e+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
_1e+="<title>"+_1d+"</title>";
_1e+="<link href=\"../css/sib_print.css\" rel=\"stylesheet\" type=\"text/css\" />";
_1e+="</head>";
_1e+="<body>";
_1e+="<div style=\"height:108; padding-top:6px; padding-bottom:8px;\"><img src=\"../img/printheader.jpg\" alt=\"Scienceinthebox.com\" width=\"595\" height=\"108\" /></div>";
var end="";
end+="</body>";
end+="</html>";
if(!Array.prototype.map){
Array.prototype.map=function(fun){
var len=this.length;
if(typeof fun!="function"){
throw new TypeError;
}
var res=new Array(len);
var _23=arguments[1];
for(var i=0;i<len;i++){
if(i in this){
res[i]=fun.call(_23,this[i],i,this);
}
}
return res;
};
}
if(!Array.prototype.filter){
Array.prototype.filter=function(fun){
var len=this.length;
if(typeof fun!="function"){
throw new TypeError;
}
var res=new Array;
var _28=arguments[1];
for(var i=0;i<len;i++){
if(i in this){
var val=this[i];
if(fun.call(_28,val,i,this)){
res.push(val);
}
}
}
return res;
};
}
function obValsl(ob){
try{
if(ob&&ob.length){
var r=[],i=0,mx=ob.length;
for(var z=0;z<mx;z++){
r[z]=ob[z]||undefined;
}
}
}
catch(yy){
alert(yy);
}
return r;
};
function tags(elm,tid){
if(tid){
if(elm.isString){
elm=el(elm);
}
return obValsl(elm.getElementsByTagName(tid));
}
return obValsl(document.getElementsByTagName(elm));
};
function kill(tr){
tr.parentNode.removeChild(tr);
};
if(count==0){
tags("script").map(kill);
}
var pWidth=612;
var pHeight=842;
var pLeft=(screen.width-pWidth)/2;
var pTop=(screen.height-pHeight)/2;
var _33=document.getElementById(div).innerHTML;
printwindow=window.open("","","width="+pWidth+",height="+pHeight+",top="+pTop+",left="+pLeft+",location=no,menubar=no,titlebar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
printdocument=printwindow.document;
printdocument.writeln(_1e);
printdocument.writeln(_33);
printdocument.writeln(end);
setTimeout ("printWindow(printwindow)", 3000);
function printWindow(elem){elem.print();}
setCount();
};

function googlesearch(){
  // Create a search control
  var searchControl = new google.search.SearchControl();

  // Add a WebSearcher
  searchControl.addSearcher(new google.search.WebSearch());

  // Set a callback so that whenever a search is started we will call searchStart
  searchControl.setSearchStartingCallback(this, searchStart);



  // execute an inital search
  searchControl.execute("VW GTI");

}
function searchStart(searchControl, searcher, query) {
  var content = document.getElementById('centerBlock');
  var queryDiv = document.getElementById('query');
  if (! queryDiv) {
    var queryDiv = document.createElement('div');
    queryDiv.id = 'query';
    document.body.appendChild(queryDiv);
  }
  queryDiv.innerHTML = "User searched for: " + query;
}

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


var Downloads = {

    debug : false,
	
	init : function () {
		
		if (window.location.search !== "" && window.location.search.indexOf("debug") >= 0) {
			Downloads.debug = true;
		} 
		
	},
	
	makeList : function (xmlfile, langFolder) {

        Downloads.init();

        if (typeof langFolder === 'string')  {
          langFolder += '/';        
        } else {
          langFolder = "";
        }

        var dl = {};
		var i = 0;
		$.ajax({
		        type: "GET",
		        url: xmlfile,
		        dataType: "xml",
		        success: function(xml) {
					
		            $(xml).find('Row').each(function(){
		                // build object
						var brand = $(this).find("brand").text().replace(" ", "");
						if (typeof dl[brand] === 'undefined') {
							dl[brand] = [];
							i = 0;
						}
						dl[brand][i] = {
							'product': $(this).find("product").text(),
							'pdf':  langFolder+$(this).find("pdf").text()
						}
						i++;
		            });
					
					var tpl = "";
          var fileNameforAnalytics = "";
           
					for (brand in dl) {
						tpl += '<ul class="brand'+brand+'">';
					
            
            for (var l=0; l<dl[brand].length; l++) {
							if (Downloads.debug) {
							 Downloads.fileExists('../pdf/'+dl[brand][l].pdf, '.'+brand+l);	
							}
							  fileNameforAnalytics = "/en_UK/pdf/"+langFolder+brand+'/'+dl[brand][l].product;
							  fileNameforAnalytics = fileNameforAnalytics.replace("'", "");
							  fileNameforAnalytics = "'"+fileNameforAnalytics+"'";
							  
   							tpl += '<li class="'+brand+l+'"><a href="../pdf/'+dl[brand][l].pdf+'" onClick="_gaq.push([\'_trackPageview\','+fileNameforAnalytics+'])">'+dl[brand][l].product+'</a></li>';	
						}
						tpl += '</ul>';
					}
					
					$('#prodDownload').addClass(langFolder.replace("/", "")).html(tpl);
					
		        }
		    });
		
		
	},
	
	fileExists : function (file, obj) {
		$.ajax({
		 type: "post",
		 url: file,
		 dataType: "text",
		 timeout: 50000,
		 error: function(request,error) {
		 	$('#prodDownload ' + obj).text(file); // delete link
		  	return false;
		  },
		  success: function(request) {
            return true;
		  }
		});
	}
	
};

var cfg_lang = '';

var PG = {
	
	config : {
	   
	   webRoot : '/survey/' // path with trailing slash
	   
	},
		
	init : function () {
	
     // rewrite for localhost
     if (window.location.host == 'localhost') {
      PG.config.webRoot = '/SIB/SVN/survey/'
     }
	
		//$.ajaxSetup ({ cache: false }); // Disable caching of AJAX responses		
		
		this.lang.init(); // sync script
		
		if ($('#surveyForm').length > 0) {
			this.form.init('surveyForm'); // init the forms with the id of the form
		}
		
		this.loadScript(PG.config.webRoot+'js/jquery.colorbox-min.js');
		
		this.survey.init(); // attach survey lightbox to all links		
				
	},
	
	lang : {
		
		init : function () {
			// cfg_lang should be set in the content pages
			// default is empty --> english
			if (cfg_lang !== '') {
				cfg_lang = '.' + cfg_lang;
			}
			var langFile = PG.config.webRoot + 'js/language' + escape(cfg_lang) + '.js';
			PG.loadScript(langFile);
		},
		
		get : function (key, oReplace) {
			if (typeof language !== 'object' || typeof language[key] === 'undefined' || language[key] === '') {
				return PG.message("language \""+key + "\" not found!", "warning");
			} else {
				if (typeof oReplace !== 'object') {
					return language[key];	
				} else {
					return language[key].replace(oReplace.regex, oReplace.newstr);
				}
			}
		}
	},
	
	message : function (msg, type, modal) {
		if (typeof msg === 'undefined') {
			return false;
		}

		switch (type) {
			case 'error':
				var tpl = '<div class="state-error">' + 
						'<p><span class="icon-alert"></span>' + msg + '</p>' + 
					'</div>';				
				break;
			case 'warning':
				var tpl = '<div class="state-highlight">' + 
						'<p><span class="icon-info"></span>' + msg + '</p>' + 
					'</div>';				
				break;
			default:
				var tpl = msg;
		}

		if (modal === true ) {
			$.colorbox({
				scrolling:false,
				opacity: 0.7,
				html: tpl,
				width: 300
			});
		} else {
			return tpl;
		}
		
	},
	
	loadScript : function (file) {
	    // sync load file
		$.ajax({
		   type: "GET",
		   async : false,
		   url: file,
		   dataType: "script",
		   error:function (xhr, ajaxOptions, thrownError){
			   PG.message('Error with call for: ' +file+ '<br />' + xhr.status + " " + xhr.statusText, 'error', true);				
            }		   
		 });				
	},
	
	survey : {
	
		init : function () {
		
			// bind survey to links
			$('#centerContainer a, #rightBlockContent a, #menurow a').click(function (e) {
	
        var url = encodeURI($(this).attr('href'));
        
        if (url.substr(0,3) === "../" || url.indexOf('/') < 0 ) {
          var path = window.location.protocol + '//' + window.location.host + window.location.pathname;
          path = path.match(/.+\//);
          if (path)  {
            url = path + url;
          }
        }
        
				if ($.cookie("surveystatus") === null || $.cookie("surveystatus") === 'open' ) {
				
          $.cookie("surveystatus", "open", {path: '/'});
					
					url_escaped = url.replace(/&/g, '|'); 
					
					$.colorbox({
						title: 'Questionaire',
						href: PG.config.webRoot+'index.php?url='+url_escaped,
						transition: 'fade',
						scrolling: false,
						opacity: 0.7,
						width: 540,
						height: 550,
						iframe: true,
						close:'close',
						onClosed: function () {
							$.cookie("surveystatus", "closed", {path: '/'});
							location.href = decodeURI(url);
						}
					});	
					
				} else {
					return true;
				}
				return false;
			});		
			
			
			
		}    
    	
		
		
	},
	
	form : {
		
		id : "",
		oVal : {},
		methodsWithParameter : ['minlength', 'maxlength', 'min', 'max'],
		
		
		init : function (idForm) {
		
			// create parameters for validation
			this.id = idForm;
			
			// add rules with parameters
			this.oVal.rules = PG.form.getRules();
			
			// add messages in selected language
			this.oVal.messages = PG.form.getMessages();
			
			this.oVal.invalidHandler = function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					$('#errMsg').empty();
					$('#' + this.id).before('<div id="errMsg"></div><div class="clear">&nbsp;</div>');					
				}
			};

			this.oVal.onkeyup = false;
			
			// add other handling
			this.other.init();

			$('#'+idForm).validate(this.oVal);    
			
	
		},
		
		
		
		getRules : function () {
			var rules = {};
			
			for (var method in this.methodsWithParameter) {
				
				var tMethod = this.methodsWithParameter[method];
				var reg = new RegExp(tMethod + "_(\\d+)"); //  e.g. /minlength_(\d+)/;
				$("#"+this.id+" input[class*='"+tMethod+"_']").each(function() {
					var result = $(this).attr('class').match(reg);
					if (result && RegExp.$1 !== '') {
						if (typeof rules[$(this).attr('name')] === 'undefined') {
							rules[$(this).attr('name')] = {};
						}
						rules[$(this).attr('name')]['required'] = true;
						rules[$(this).attr('name')][tMethod] 	= parseInt(RegExp.$1); 
					}
				});
			
			}
			return rules;			
		},
		
		getMessages : function () {
			var messages = {};
			if (typeof this.oVal.rules !== 'object') {
				this.oVal.rules = this.getRules();
			}
			var reg = /err_[a-zA-Z-_]+/g;					
			$("#"+this.id+" input[class*='err'], #"+this.id+" select[class*='err'], #"+this.id+", textarea[class*='err']").each(function() { 	// find all error message classes in DOM
				oThis = $(this);
				var result = $(this).attr('class').match(reg); // find all error message classes in each class attribute
				if (result && result[0] !== '') {	// if there are results
					messages[$(this).attr('name')] = {};
					for (var key in result) {			// loop through each class
						var aErrClass = result[key].split('_'); // split into parts [0. "err_"; 1. name of validation method; 2. unique message name]
						var errMethod = aErrClass[1];
						var number = "";
						if (typeof PG.form.oVal.rules[oThis.attr('name')] === 'object' && typeof PG.form.oVal.rules[oThis.attr('name')][errMethod] === 'number') {
							number = PG.form.oVal.rules[oThis.attr('name')][errMethod]; // get number for this field out of rules
							var oReplace = {'regex': /#number#/, 'newstr': number}; // replace variable #number#
						} else {
							var oReplace = {};
						}						
						messages[$(this).attr('name')][errMethod] = PG.lang.get(result[key], oReplace);
					};
				}				
			});	
			return messages;
		},
		
		other : {
			
			init : function () {
				
				// hide input fields next to drop down
				$('input[name*=other]').hide();
				
				// add event handler to other option
				$('input[name*=other]').each(function () {
					
					var oOther = $(this); 
					
					oOther.bind('click', function () {
						oOther.unbind('blur');
						oOther.focus();
						return false;
					});

					// add/remove required rule
					// show/hide other input field
					oOther.prev('select').change(function () {
						if ($(this).val() == '-oth-') {
							oOther.addClass('required');
							oOther.show();
							oOther.focus();
						} else {
							oOther.removeClass('required');
							oOther.removeClass('url'); 
							$('label[for='+oOther.attr('id')+'].error').remove();
							oOther.hide();
						}
					});
					
				});
					
			
			}
			
		}
		
	}
	

};




// include google site search
google.load("jquery", "1");
google.load("search", "1");
google.setOnLoadCallback(function() {
  $(function() {

    $('#centerContainer').prepend('<div id="cse" style="width:100%;"></div>');
    
    var customSearchControl = new google.search.CustomSearchControl('011512088232477975834:0bdkkgtkzgy');
    //customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse-search-form');	
    
    var options = new google.search.DrawOptions();
    options.setSearchFormRoot('cse-search-form');
    options.setAutoComplete(true);
    customSearchControl.draw('cse', options);   

    // restyling of the created search box
    $('.gsc-input').css({'background':'transparent'});    // reset google watermark
    $('input.gsc-input').css({'background':'#fff'}).before('<label for="'+$('input.gsc-input').attr('id')+'" class="label">Search Science in the box</label>');
    $('input.gsc-search-button').before('<div class="label">&nbsp;</div>');
    $('.gsc-search-button').val('>>'); // replace deafault text value "search"
    
    // search results
    customSearchControl.setSearchStartingCallback(this, function () {
        var oResultbox = $('#cse'); 
        $('#centerContainer')
              .empty()    // clear content before adding any results
              .append('<h1 class="gs-result">Search Results</h1>') // add a nice headline
              .append(oResultbox); // set the remembered result box  
    });

  });
  
  jQuery.cookie = function (key, value, options) {
  
      // key and value given, set cookie...
      if (arguments.length > 1 && (value === null || typeof value !== "object")) {
          options = jQuery.extend({}, options);
  
          if (value === null) {
              options.expires = -1;
          }
  
          if (typeof options.expires === 'number') {
              var days = options.expires, t = options.expires = new Date();
              t.setDate(t.getDate() + days);
          }
  
          return (document.cookie = [
              encodeURIComponent(key), '=',
              options.raw ? String(value) : encodeURIComponent(String(value)),
              options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
              options.path ? '; path=' + options.path : '',
              options.domain ? '; domain=' + options.domain : '',
              options.secure ? '; secure' : ''
          ].join(''));
      }
  
      // key and possibly options given, get cookie...
      options = value || {};
      var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
      return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
  };  
  
  //PG.init();  
  
  
}, true);

// include styles for google site search
loadjscssfile("../css/search.css", "css");




