var thisFileURL = window.location.toString();
var Sections = new Array('common','analysis','development','production');
var thisSectionNb = readcookie('section');
function InitIndex(){
	if (thisFileURL.indexOf('print') < 1){
		document.getElementById('page_container').style.width = '776px';
	}
	erasecookie('section');
}
function InitMenus(){
	if (((screen.width > 0) && (screen.width <= 800)) || (readcookie('smallscreen') != null)){
		document.getElementById('page_container').style.width = '776px';
	}
	//Determine section location or section heritance of the page
	if (thisFileURL.indexOf('print') > 0){
		document.getElementById('css').href='/kromasil/export/system/modules/com.eka.kromasil/resources/css/print.css';
		document.getElementById('css').media='print, screen';
		document.getElementById('page_logo').src='/kromasil/export/system/modules/com.eka.kromasil/resources/images/page_header_kromasil_logo_blue.gif';
		if (thisFileURL.indexOf('application_guide') > 0){
			document.getElementById('page_header').style.height = '50px';
		}
	}else{
		var Microsites = new Array('cellucoat', 'amycoat');
		var Microsite = false;
		for (my = 0; my < Microsites.length; my++){
    		if (thisFileURL.indexOf(Microsites[my]) > 0){
    			Microsite = true;
    		 }
    	}
    	var Sections = new Array('common','analysis','development','production');
    	var SectionNb = -1;
    	for (n = 0; n < Sections.length; n++){
    		if (thisFileURL.indexOf(Sections[n]) > 0){
    			SectionNb = n;
    			n = Sections.length + 1;
    		}
    	}
    	if (SectionNb > 0){
    		writecookie('section',SectionNb);
    	}else{
    		if (SectionNb == 0){
        		StoredSection = readcookie('section');
        		if(Boolean(StoredSection)){
        			SectionNb = StoredSection;
        		}else{
        			SectionNb = -1;
        		}
    		}
    	}
    	//if (SectionNb == -1){
    		//erasecookie('section');
    	//}
    	//Settings for left menu - parts to be shown and formattings thereof
    	if (SectionNb > 0){
    		var SectionDiv = document.getElementById? document.getElementById(Sections[SectionNb]) : document.all.Sections[SectionNb];
    		var SectionMenu = getElementsByTagNames('ul',SectionDiv);
    		for (i = 0; i < SectionMenu.length; i++){
    			SectionMenu[i].style.display = 'block';
    		}
    		//format displayed menu part
    		var SectionMenuA = getElementsByTagNames('a',SectionMenu[0]);
    		var VirtualFileURL = thisFileURL.replace('common', Sections[SectionNb]);
    		for (i = 0; i < SectionMenuA.length; i++){
        		if (VirtualFileURL.indexOf(SectionMenuA[i])!= -1){
        			SectionMenuA[i].parentNode.className = 'on';
        		}
        	}
    	}else{
    		if (Microsite == false){
    			var PageMenuID = 'page_menu';
    			var PageMenu = document.getElementById? document.getElementById(PageMenuID) : document.all.PageMenuID;
    	   		var MenuParagraphs = getElementsByTagNames('p',PageMenu);
    	   		for (i = 0; i < MenuParagraphs.length; i++){
    	   			MenuParagraphs[i].style.display = 'block';
    	   		}
    	   	}
    	}
    	PrintLinks();
	}

}
function InitMapping(){
	TestStatus = readcookie('google');
    if (TestStatus != 'off'){_uacct = "UA-770543-1";urchinTracker();}
}
function InitContentImages(){
	var ContentImages = getElementsByClassName(document, "div", "fig");
	for (i = 0; i < ContentImages.length; i++){
		if (ContentImages[i].childNodes[1].width > 150){
			ContentImages[i].lastChild.style.width = ContentImages[i].childNodes[1].width + 'px;';
			ContentImages[i].style.width = ContentImages[i].childNodes[1].width + 'px;';
		}
	}
}
function InitContentFigures_dommass_not_working(){
	var ContentImages = $("panel_content").elmsByClass("figure", "div");
 	for (i=0; i<parseInt(ContentImages.length); i++){
 		var FigureImage = ContentImages[i].elmsByTag('img');
		var FigureTexts = ContentImages[i].elmsByTag('p');
		for (j=0; j<parseInt(FigureTexts.length); j++){
			FigureTexts[j].style.width = FigureImage[0].width + 'px';
		}
	}
}
function InitContentFigures(){
	var ContentImages = getElementsByClassName(document, "div", "figure");
 	for (i=0; i<parseInt(ContentImages.length); i++){
 		var FigureImage = ContentImages[i].getElementsByTagName('img');
		var FigureTexts = ContentImages[i].getElementsByTagName('p');
		for (j=0; j<parseInt(FigureTexts.length); j++){
			if (FigureImage[0].width != 0){
				FigureTexts[j].style.width = FigureImage[0].width + 'px';
			}
		}
	}
}
function PrintWindow(){
	if (thisFileURL.indexOf('print=1')>0){
		openPrintWindow(thisFileURL);
	}else{
		if (thisFileURL.indexOf('?')== -1){
			var PrintTag = '?print=1';
		}else{
			var PrintTag = '&print=1';
		}
		window.location = thisFileURL + PrintTag;
	}
}
function PrintLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "print")
     anchor.target = "_blank";
 }
}
function PrintWindowOld(){
	window.location = window.location.toString() + '#print';
	window.location.reload();
}
function openPrintWindow(url) {
	window.open(url, "print", "height=400,width=600,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}
function openPopupWindow(url, width, height) {
	window.open(url, "popup", "height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}
function submitSearch() {
	document.getElementById('searchForm').submit();
}
function addProducts() {
 document.getElementById('orderForm').submit();
}
function ZebraTables() {
    var tables = getElementsByClassName(document, 'table', 'zebra');
    if (! tables) { return; }
	for (g = 0; g < tables.length; g++){
    	var tbodies = tables[g].getElementsByTagName("tbody");
    	for (var h = 0; h < tbodies.length; h++) {
      		var TableRows = tbodies[h].getElementsByTagName("tr");
      		OddRow = true;
      		for (var i = 0; i < TableRows.length; i++) {
			    if (!hasClass(TableRows[i]) && ! TableRows[i].style.backgroundColor) {
 					var TableCells = TableRows[i].getElementsByTagName("td");
 					if (OddRow == true){
 						TableCells[0].className = "odd";
						TableRows[i].className = "odd";
					}else{
 						TableCells[0].className = "even";
					}
				}
				OddRow = !OddRow;
			}
		}
	}
}
function ShowExample(Example){
 var Examples = new Array('example1','example2');
 ExampleToShow = document.getElementById? document.getElementById(Example) : document.all.Example;
 ExampleToShow.style.display = 'block';
 for (i=0; i<Examples.length; i++){
  if (Example != Examples[i]){
   ExampleToHide = document.getElementById? document.getElementById(Examples[i]) : document.all.Examples[i];
   ExampleToHide.style.display = 'none';
  }
 }
}
function playIt(n){
	ArrowMargins = new Array ('1px', '24px', '47px', '70px', '93px');
	Conditions = new Array(
		'Conditions: Particle size: 5  &micro;m &middot; Column length: 250 mm &middot; Flow rate: 1 ml/min',
		'Conditions: Particle size: <em>3<\/em>  &micro;m &middot; Column length: <em>150<\/em> mm &middot; Flow rate: 1 ml/min',
		'Conditions: Particle size: 3  &micro;m &middot; Column length: <em>50<\/em> mm &middot; Flow rate: 1 ml/min',
		'Conditions: Particle size: 3  &micro;m &middot; Column length: 50 mm &middot; Flow rate: <em>3<\/em> ml/min',
		'Conditions: Particle size: 3  &micro;m &middot; Column length: 50 mm &middot; Flow rate: <em>7<\/em> ml/min'
	);
	PlayItem = 'url(../images/cellucoat_fast_chromatography0' + n + '.gif)';
	PlayItHere = document.getElementById('play_it_here');
	PlayItHere.style.backgroundImage = PlayItem;
	ConditionsHere = document.getElementById('fastplayer_conditions').getElementsByTagName('p');
	ConditionsHere[0].innerHTML = Conditions[n];
	MoveItHere = document.getElementById('list_arrow').getElementsByTagName('img');
	MoveItHere[0].style.marginTop = ArrowMargins[n];
	if (n == 4){
		PlayItHere.innerHTML = '<p>Baseline separation in less than 30 s<\/p>';
	}else{
		PlayItHere.innerHTML = '&nbsp;';
	}
}
function removeSelected() {
	document.cartForm.command.value="remove";
	document.cartForm.submit();
}
function saveUpdates() {
	document.cartForm.command.value="save";
	document.cartForm.submit();
}
function checkForm() {
	var formIsValid = true;
	var nonEmptyFields = new Array("name", "company", "email");
	var nonEmptyFieldsLabels = new Array("Name", "Company", "E-mail");
	if(document.orderForm.elements["sendToSeparationProducts"].value == "false") {
		if(document.orderForm.elements["distributorId"].value == "") {
			alert("Select distributor");
			return;
		}
	}

	for(i = 0; i < nonEmptyFields.length; i++) {
		if(document.orderForm.elements[nonEmptyFields[i]].value == "") {
			formIsValid = false;
			alert("'" + nonEmptyFieldsLabels[i] + "' can not be empty");
			return;
		}
	}

	var emailRegExp = new RegExp("^([0-9A-z-_]+\\.)*[0-9A-z-_]+@((([0-9A-z-_]+\\.)+[A-z]+)|(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))$","g");
	var result = document.orderForm.elements["email"].value.match(emailRegExp);
	if(result == null) {
		formIsValid = false;
		document.forms['orderForm'].command.value = "sendMail";
		alert("Field 'Email' has incorrect format");
		return;
	}
	document.forms['orderForm'].command.value = "sendMail";
	document.forms['orderForm'].submit();
}
function goToCartPage() {
	document.forms['orderForm'].command.value = "goToCartPage";
	document.forms['orderForm'].submit();
}
function goToPublicationsPage() {
	document.forms['orderForm'].command.value = "goToPublicationsPage";
	document.forms['orderForm'].submit();
}

function ToggleMenu(){
	if (document.getElementById('page_menu').style.display == 'none'){
		document.getElementById('page_menu').style.display = 'block';
		document.getElementById('gray_panel').style.marginLeft='0';
	}else{
		document.getElementById('page_menu').style.display = 'none';
		document.getElementById('gray_panel').style.marginLeft='-23em';
	}
}
function openpdf(item){
	publication = getElementsByTagNames('a', item);
	window.location = publication[0];

}
function savePublications() {
	document.publicationForm.submit();
}
function ShowPart(part){
	var AllParts = getElementsByClassName(document, 'div', 'publication_part')
	for (i = 0; i<AllParts.length; i++){
		if (AllParts[i].id == part){
			document.getElementById(part).style.display = 'block';
		}else{
			document.getElementById(AllParts[i].id).style.display = 'none';
		}
	}
}
/*
    Application Guide
*/
function RestoreFilterState(){
  FilterState=readcookie('filter');
  if (FilterState != null){
    window.location = FilterState;
  }else{
    /*window.location = "http://www.kromasil.com/kromasil/opencms/common/what/application_guide/";*/
    window.href = "kromasil/opencms/common/what/application_guide/";
  }
}

function resetForm(){
	if (thisFileURL.indexOf("&phase")>0){
 		BaseURL = thisFileURL.substr(0, thisFileURL.indexOf("&phase"));
 	}else{
 		if (thisFileURL.indexOf("?")>0){
 			BaseURL = thisFileURL.substr(0, thisFileURL.indexOf("?"));
 		}else{
 			BaseURL = thisFileURL;
 		}
 	}
	location.href = BaseURL;
}
function resetMicrositeForm(){
	location.href = 'index.html';
}
function ShowText(part){
	var diven = document.getElementById(part);
	var texten = diven.getElementsByTagName("p");
	texten[0].style.display='block';
}
function HideText(part){
	var diven = document.getElementById(part);
	var texten = diven.getElementsByTagName("p");
	texten[0].style.display='none';
}
function viewApplication(){
	writecookie('filter',window.location.toString());
	document.getElementById("viewApp").value = "1";
	document.getElementById("filterForm").submit();
}
function changeAppType(){
 document.getElementById("id").value="0";
 if (document.getElementById("substance")) document.getElementById("substance").value="0";
 document.getElementById("subject").value="0";
 document.getElementById("phase").value="0";
 document.getElementById("technology").value="0";
 document.getElementById("filterForm").submit();
}

function changeSubject(){
 document.getElementById("id").value="0";
 if (document.getElementById("substance")) document.getElementById("substance").value="0";
 document.getElementById("phase").value="0";
 document.getElementById("technology").value="0";
 document.getElementById("filterForm").submit();
}

function changePhase(){
 document.getElementById("id").value="0";
 if (document.getElementById("substance")) document.getElementById("substance").value="0";
 document.getElementById("filterForm").submit();
}

function changeTechnology(){
 document.getElementById("id").value="0";
 if (document.getElementById("substance")) document.getElementById("substance").value="0";
 document.getElementById("filterForm").submit();
}

function changeSubstance()
{
 document.getElementById("id").value="0";
 document.getElementById("filterForm").submit();
}
function toggleTable(table)
{

 children = document.getElementById(table).rows;
 for (i=1; i< children.length-1; i++)
 {
  el = children[i];
  if (el.tagName == "TR")
  {
   if (el.style.display != 'none') el.style.display='none'; else el.style.display = children[0].style.display;
  }
 }
}
function ToggleStructures(){
	var structures = getElementsByClassName(document, "div", "application_substances");
	var structureImages = getElementsByTagNames('img',structures[0]);
	var StructureTrigger = document.getElementById('StructureTrigger');
	if (structureImages[0].style.display == 'none'){
		StructureTrigger.innerHTML = 'Hide structures';
		StructureTrigger.className = 'minus';
		Toggler = 'block';
	}else{
		StructureTrigger.innerHTML = 'Show structures';
		Toggler = 'none';
		StructureTrigger.className = 'plus';
	}
	for (i = 0; i < structureImages.length; i++){
		structureImages[i].style.display = Toggler;
	}
}
function openWindow(url)
{
 window.open(url,null,"height=300,width=400,status=no,toolbar=no");
}

function printWindow(url)
{
 window.open(url,null,"status=no,toolbar=no,scrollbars=yes");
}
/*
    Written by Peter-Paul Koch, http://www.quirksmode.org/dom/getElementsByTagNames.html
*/
function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function writecookie(thiscookie,thisvalue) {
	createcookie(thiscookie, thisvalue, 1);
};
function createcookie(name,value,days) {
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/"; // domain=.kromasil.com
};
function readcookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};
function erasecookie(name) {
	createcookie(name,"",-1);
};
  // Zebra tables derived from David Miller
  //http://alistapart.com/d/stripedtables/example.html

  //this function is needed to work around a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}
function SwitchOver(toSection){
	if ((thisSectionNb > 0) && (Sections[thisSectionNb] != toSection)){
    	var toURL = thisFileURL.replace(Sections[thisSectionNb], toSection);
	   	location.href = toURL;
	}else{
		location.href = "/kromasil/opencms/" + toSection + "/";
	}
}