

function populateProcess(nr, selectedValue, selectedText, frm, btnName) {

		allSubProcesses = document.sub.subpro;
		allSubProcessesPhrase = document.sub.subpro1;
		
		if (nr==0) {
			document.pro.ps.options.length = 1;			
			document.pro.ps.options[0].text = "-------------------------Select-------------------------";
			document.pro.ps.options[0].value = "-1";
			return;
		}
		else {
			// Find out size of this dropdown
			matchingValues = 0;
			for (a=0; a<allSubProcesses.length; a++) {
				if (selectedValue == allSubProcesses[a].value) {
				matchingValues++;
				}
			}
			document.pro.ps.length = matchingValues + 1;
		
			j=1;
			for (i=0; i<allSubProcesses.length; i++) {
				if (selectedValue == allSubProcesses[i].value) {
					document.pro.pm.options[0].text = "-------------------------Select-------------------------";
					document.pro.ps.options[j].text = allSubProcesses[i].text;
					document.pro.ps.options[j].value = allSubProcessesPhrase[i].value;
					document.pro.main.value = selectedText;
					j++;
				}
			}
		}


			document.pro.radio1.checked = true;
			document.pro.im.options[0].selected = true;
			document.pro.is.options[0].selected = true;
			document.pro.mm.options[0].selected = true;
			document.pro.ms.options[0].selected = true;
			//document.pro.brand.options[0].selected = true;
			document.pro.grade.value = "";
			document.pro.is.length = 1;
			document.pro.ms.length = 1;

		
	}
	
	function populateIndustry(nr, selectedValue, selectedText, frm, btnName) {

		allSubIndustries = document.sub.subind;
		allSubIndustryPhrase = document.sub.subind1;
		
		if (nr==0) {
			document.pro.is.options.length = 1;			
			document.pro.is.options[0].text = "-------------------------Select-------------------------";
			document.pro.is.options[0].value = "-1";
			return;
		}
		else {
			matchingValues = 0;
			for (a=0; a<allSubIndustries.length; a++) {
				if (selectedValue == allSubIndustries[a].value) {
				matchingValues++;
				}
			}
			document.pro.is.length = matchingValues + 1;
		
			j=1;
			for (i=0; i<allSubIndustries.length; i++) {
				if (selectedValue == allSubIndustries[i].value) {
					document.pro.im.options[0].text = "-------------------------Select-------------------------";
					document.pro.is.options[j].text = allSubIndustries[i].text;
					document.pro.is.options[j].value = allSubIndustryPhrase[i].value;
					document.pro.main.value = selectedText;
					j++;
				}
			}
		}
		document.pro.radio2.checked = true;
		document.pro.pm.options[0].selected = true;
		document.pro.ps.options[0].selected = true;
		document.pro.mm.options[0].selected = true;
		document.pro.ms.options[0].selected = true;
		//document.pro.brand.options[0].selected = true;
		document.pro.ps.length = 1;
		document.pro.ms.length = 1;
		
	}
	
	
		function populateMaterial(nr, selectedValue, selectedText, frm, btnName) {

		allSubMaterial = document.sub.submat;
		allSubMaterialPhrase = document.sub.submat1;
		
		if (nr==0) {
			document.pro.ms.options.length = 1;			
			document.pro.ms.options[0].text = "-------------------------Select-------------------------";
			document.pro.ms.options[0].value = "-1";
			return;
		}
		else {
			matchingValues = 0;
			for (a=0; a<allSubMaterial.length; a++) {
				if (selectedValue == allSubMaterial[a].value) {
				matchingValues++;
				}
			}
			document.pro.ms.length = matchingValues + 1;
		
			j=1;
			for (i=0; i<allSubMaterial.length; i++) {
				if (selectedValue == allSubMaterial[i].value) {
					document.pro.mm.options[0].text = "-------------------------Select-------------------------";
					document.pro.ms.options[j].text = allSubMaterial[i].text;
					document.pro.ms.options[j].value = allSubMaterialPhrase[i].value;
					document.pro.main.value = selectedText;
					j++;
				}
			}
		}
				
		document.pro.radio3.checked = true;
		document.pro.pm.options[0].selected = true;
		document.pro.ps.options[0].selected = true;
		document.pro.im.options[0].selected = true;
		document.pro.is.options[0].selected = true;
		//document.pro.brand.options[0].selected = true;
		document.pro.ps.length = 1;
		document.pro.is.length = 1;
	}
	
	function searchProcess(nr) {
		alert(nr)
	
	}
	
	
	
	function setHiddenValue(selectedText, checkbox) {
		document.pro.sub.value = selectedText;
		if (checkbox == 1) {
			document.pro.radio1.checked = true;	
		}
	}
	
	function setHiddenIndValue(selectedText, checkbox) {
		document.pro.sub.value = selectedText;
		if (checkbox == 2) {
			document.pro.radio2.checked = true;	
		}
		
	}
	
	function setHiddenMatValue(selectedText, checkbox) {
		document.pro.sub.value = selectedText;
		if (checkbox == 3) {
			document.pro.radio3.checked = true;	
		}
	}
	
	function download() {
		document.pl_stat.submit();
	}
	
	function downloadMsds() {
		document.msds.submit();
	}
	
	function downloadPds() {
		document.pds.submit();
	}

	
	function setCountry(selectedValue, isBorealis) {
		if(isBorealis){
			document.pro.country.value = selectedValue;
			nCountries = document.sub.ncountries;
			canceled = false;
			for (i=0;i<nCountries.length;i++) {
				if (selectedValue == nCountries[i].value) {
					if (nCountries[i].text == "Borouge") {
						if(confirm("Our joint venture Borouge is your contact in this country. Click OK to go directly to the Borouge website."))       
			       		{
			            	var url = "http://www.borouge.com/EServices/Pages/DataSheets.aspx";
			            	window.location.href=url;    
		                }
		                else{
		                	document.getElementById("allcountry").options[0].selected = true;
		                	setDefaultCountry('');
		                	canceled=true;
		   				}
					}
				}
			}
			if(!canceled){
				setDefaultCountry(selectedValue);
			}
		}
		else{
			document.pro.country.value = selectedValue;
			nCountries = document.sub.ncountries;
			canceled = false;
			for (i=0;i<nCountries.length;i++) {
				if (selectedValue == nCountries[i].value) {
					if (nCountries[i].text == "Borealis") {
						if(confirm("Our joint venture Borealis is your contact in this country. Click OK to go directly to the Borealis website."))       
			       		{
			            	var url = "http://www.borealisgroup.com/";
			            	window.open(url);    
		                }
		                else{
		                	document.getElementById("allcountry").options[0].selected = true;
		                	setDefaultCountry('');
		                	canceled=true;
		   				}
					}
				}
			}
			if(!canceled){
				setDefaultCountry(selectedValue);
			}
		}		
	}
	
	function makeDisable(dropdown){
    var x=document.getElementById(dropdown);
    x.disabled=true
	}
	
	function makeEnable(dropdown){
    var x=document.getElementById(dropdown)
    x.disabled=false
	    if (dropdown == 'grade') {
	    	var a = document.getElementById('brand')
	    	var b = document.getElementById('pm')
	    	var c = document.getElementById('ps')
 		    var d = document.getElementById('im')
   	    	var e = document.getElementById('is')
   	    	var f = document.getElementById('mm')   	    	
   	    	var g = document.getElementById('ms')
   	    	a.disabled=true   	    	
   	    	b.disabled=true   	    	   	    	
			c.disabled=true
			d.disabled=true
			e.disabled=true
			f.disabled=true
			g.disabled=true									   	    	   	    	   	    				   	    	   	    	   	    	
	    }
	    if (dropdown == 'brand') {
	    	var a = document.getElementById('grade')
	    	var b = document.getElementById('pm')
	    	var c = document.getElementById('ps')
 		    var d = document.getElementById('im')
   	    	var e = document.getElementById('is')
   	    	var f = document.getElementById('mm')   	    	
   	    	var g = document.getElementById('ms')
   	    	a.disabled=true   	    	
   	    	b.disabled=true   	    	   	    	
			c.disabled=true
			d.disabled=true
			e.disabled=true
			f.disabled=true
			g.disabled=true									   	    	   	    	   	    				   	    	   	    	   	    	
	    }
	    if (dropdown == 'pm') {
	    	var a = document.getElementById('grade')
	    	var b = document.getElementById('brand')
 		    var c = document.getElementById('ps')
 		    var d = document.getElementById('im')
   	    	var e = document.getElementById('is')
   	    	var f = document.getElementById('mm')   	    	
   	    	var g = document.getElementById('ms')
   	    	a.disabled=true   	    	
   	    	b.disabled=true   	    	   	    	
			c.disabled=false
			d.disabled=true
			e.disabled=true
			f.disabled=true
			g.disabled=true			
	    }
	    if (dropdown == 'im') {
	    	var a = document.getElementById('grade')
	    	var b = document.getElementById('brand')
 		    var c = document.getElementById('pm')
 		    var d = document.getElementById('ps')
   	    	var e = document.getElementById('is')
   	    	var f = document.getElementById('mm')   	    	
   	    	var g = document.getElementById('ms')
   	    	a.disabled=true   	    	
   	    	b.disabled=true   	    	   	    	
			c.disabled=true
			d.disabled=true
			e.disabled=false
			f.disabled=true
			g.disabled=true			
	    }
	    if (dropdown == 'mm') {
	    	var a = document.getElementById('grade')
	    	var b = document.getElementById('brand')
 		    var c = document.getElementById('pm')
 		    var d = document.getElementById('ps')
   	    	var e = document.getElementById('im') 		    
   	    	var f = document.getElementById('is')  	    	
   	    	var g = document.getElementById('ms')
   	    	a.disabled=true   	    	
   	    	b.disabled=true   	    	   	    	
			c.disabled=true
			d.disabled=true
			e.disabled=true
			f.disabled=true
			g.disabled=false		
	    }
	}
	
	function setRadioBrand() {
		document.pro.radio5.checked = true;
	}
	function setRadioGrade() {
		document.pro.radio4.checked = true;
		document.pro.pm.options[0].selected = true;
		document.pro.ps.options[0].selected = true;		
		document.pro.im.options[0].selected = true;
		document.pro.is.options[0].selected = true;
		document.pro.mm.options[0].selected = true;
		document.pro.ms.options[0].selected = true;
	}
		
	function checkData(value) {
		alert()
	}	

	function submitForm(obj) {
		if (obj.country.value == "" || obj.country.value == "-1") {
			alert("Please select your country.")
			return false;
		}
		else {
			if (obj.type[0].checked) {
				if (obj.grade.value == "") {
					alert('Please enter a grade name');
					return false;
				}
				else {
					return submitProForm(obj);
				}
			}
			else if (obj.type[1].checked) {
				if (obj.ps.value == "-1" || obj.ps.value == "") {
					alert('Please select a sub process');
					return false;
				}
				else {
					return submitProForm(obj);
				}
			}
			else if (obj.type[2].checked) {
				if (obj.is.value == "-1" || obj.is.value == "") {
					alert('Please select a sub industry');
					return false;
				}
				else {
					return submitProForm(obj);
				}
			}
			else if (obj.type[3].checked) {
				if (obj.ms.value == "-1" || obj.ms.value == "") {
					alert('Please select a sub material');
					return false;
				}
				else {
					return submitProForm(obj);
				}
			}
			
		}
	}
	
	function submitProForm(pro){
		pro.submit();
		showWaitBar();
		return true;
	}
	
	function showWaitBar(){
		$('wait_bar').setStyle('visibility', 'visible');
		$('wait_front').setOpacity(0.10);
//		$("#spinme").spinner({
//			height: 48,
//			width: 48,
//			speed: 50,
//			image: '/image/datasheets/spotlight_spinner_big.png'
//		});
	}
	
	function clearData(nr) {
		if (nr == 1) {
			document.pro.im.options[0].selected = true;
			document.pro.is.options[0].selected = true;
			document.pro.mm.options[0].selected = true;
			document.pro.ms.options[0].selected = true;
			document.pro.grade.value = "";
			//document.pro.brand.options[0].selected = true;	
		}
		if (nr == 2) {
			document.pro.pm.options[0].selected = true;
			document.pro.ps.options[0].selected = true;
			document.pro.mm.options[0].selected = true;
			document.pro.ms.options[0].selected = true;
			document.pro.grade.value = "";
			//document.pro.brand.options[0].selected = true;	
		}
		if (nr == 3) {
			document.pro.pm.options[0].selected = true;
			document.pro.ps.options[0].selected = true;
			document.pro.im.options[0].selected = true;
			document.pro.is.options[0].selected = true;	
			document.pro.grade.value = "";
			//document.pro.brand.options[0].selected = true;
		}
		else if (nr == 4 || nr == 5) {
			document.pro.pm.options[0].selected = true;
			document.pro.ps.options[0].selected = true;
			document.pro.im.options[0].selected = true;
			document.pro.is.options[0].selected = true;
			document.pro.mm.options[0].selected = true;
			document.pro.ms.options[0].selected = true;	
		}
	}
	
	function setCountryCookie(nameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = nameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
	}
	
	function setDefaultCountry(country) {
	setCountryCookie('BorealisCountry',country,1000);
	}
	
	function getEnter(ev) {
  	enter=((ev.which)||(ev.keyCode));

	switch(enter) {

 	case 13:
 	submitForm(document.pro);return false;
	break;

  }
 }
 
 function getCookie(nameOfCookie) {
	if (document.cookie.length > 0){
		var begin = document.cookie.indexOf(nameOfCookie+"=");
		if (begin != -1){
			begin += nameOfCookie.length+1;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function htmlEncode(s)
{
return s.replace(/&(?!\w+([;\s]|$))/g, "&amp;")
.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function changeUpdateCheckboxes(theCheckbox){
	var otherOne;
	if(theCheckbox.id == 'disableAlerts1'){
		document.getElementById('receiveUpdateDaily1').checked=false;
		document.getElementById('receiveUpdateWeekly1').checked=false;
	}
	else{
		if(theCheckbox.id == 'receiveUpdateDaily1'){
			otherOne = document.getElementById('receiveUpdateWeekly1');
		}
		else{
			otherOne = document.getElementById('receiveUpdateDaily1');
		}
		document.getElementById('disableAlerts1').checked=false
		otherOne.checked = !theCheckbox.checked;
	}
}