//--------------------------------------------------------------------------------
//
//    File name   : locator.js
//    Description : This js file is used to display the contact details based on product selection.
//    version     : 1.0
//--------------------------------------------------------------------------------


// Function to display the Search Button
function renderSearchButton() {
	document.write("<input type=\"button\" value=\"Search\" onclick=\"formSubmit()\">");
}

// Function to submit the form after confirming the search criteria
function formSubmit() {
		// Product Mode selected
		if (!isProductSelected()) {
			// Product not selected
			alert("Please select a Product");
			//document.forms[0].action = "/sm/contactsupport-sub/customer-support.html";
			//document.forms[0].submit();
			document.getElementById("product").focus();			
			return false;
		} else {
			// Product selected
			document.forms[0].action = "/sm/contactsupport-sub/customer-support.html";
			document.forms[0].submit();
		}
}

function renderProductName() {	
	selectedSearchMode = getSelectedProductMode();
		document.write("<select id=\"product\" name=\"product\">");
		document.write("<option value=\"\">--Select a Product Name--</option>");
		for (i=0; i<products.length; i++) {			
			if (products[i][0] == selectedSearchMode) {
				document.write("<option selected=\"true\" value=\"" + products[i][0] + "\">" + products[i][1] + "</option>");
			}
			else{
				document.write("<option value=\"" + products[i][0] + "\">" + products[i][1] + "</option>");
			}
		}
		document.write("</select>");	
}

// Function to display the Search Button
function renderProductButton() {
	document.write("<input type=\"submit\" value=\"Search\">");
}

var products = new Array();
products = [
["AC","AC<sup>&reg;</sup> polyethylene polymers"],
["AR","Aclar"],
["AF","Advanced Fibers & Composites"],
["AE","Aegis"],
["BF","Barrier Films"],
["BJ","Burdick & Jackson High Purity Chemicals"],
["CA","Capran"],
["CC","Cyclohexanone, Cyclohexanol, Caprolactam"],
["EM","Electronic Materials"],
["EN","Enovate"],
["FP","Fluorine Products"],
["GR","Genetron Refrigerants"],
["GS","Genesolv Solvents"],
["HC","Honeywell Chemicals"],
["LL","Lumilux<sup>&reg;</sup> Luminescent pigment"],
["RH","Riedel-de Haen Fine Chemicals"],
["RV","Rheochem<sup>&trade;</sup> vinyl lubricants"],
["SP","Specialty Polymers"],
["SN","Sulf-N Ammonium Sulfate"]
];

// Function to check if Product is selected
function isProductSelected() {
	if (document.getElementById("product").selectedIndex == 0) {		
		return false;
	} else if (document.getElementById("product").disabled == true) {
		return false;
	} else {
		return true;
	}
}

// Function to display the contact details based on the product selection
function displayProductInformation() {	
		if (isProductSelected()) {			
			// Product available 
			document.write("<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\">");
			document.write("<tbody>");	
			for (k=0; k<products.length; k++) {
				if(products[k][0] == selectedSearchMode){
					for(j=0;j<3;j++){					
						document.write("<tr><td width=\"35%\" valign=\"top\">");
						document.write("<strong><span class='FH22'>" + productHeader[j]+ "</span></strong>");
						document.write("<td width=\"65%\">"+productElements[k][j]+"</td>");
						document.write("</td></tr>");
					}
				}
			}			
			document.write("</tbody>");
			document.write("</table>"); 
		} else {
			
		}
	}


var productElements = new Array();
productElements = [

["AC<sup>&reg;</sup> polyethylene polymers","<b>USA:</b><br>1-888-245-4738 (US)<br>52-55-55-49-0313 (Mexico)<br>55-11-4166-1944 (Brazil)","<a href='/sm/acwax/'>AC<sup>&reg;</sup> polyethylene polymers</a>"],
["Aclar","<b>Asia/Pacific:</b><br>86-21-2894-2946","<a href='/sm/aclar/'>Aclar</a>"],
["Advanced Fibers & Composites","<b>USA:</b><br>1-800-695-5969<br><br><b>Europe:</b><br>33-3-82-44-56-20<br><br><b>Asia/Pacific:</b><br>662-631-1969 Bangkok, Thailand","<a href='/sm/afc/'>Advanced Fibers &amp; Composites</a>"],
["Aegis","<b>Asia/Pacific:</b><br>86-21-2894-2752","<a href='/sm/aegis/'>Aegis</a>"],
["Barrier Films","<b>Asia/Pacific:</b><br>86-21-2894-2946","<a href='/sm/barrierfilms/'>Barrier Films</a>"],
["Burdick & Jackson High Purity Chemicals","<b>USA:</b><br>1-800-322-2766 (US - Customer Service)<br>1-800-368-0050 (US - Technical Service)<br>231-726-3171 (Canada)<br><br><b>Europe:</b><br>49-5137-999-203 (Germany)<br><br><b>Asia/Pacific:</b><br>91-124-637-1770/72 (India)<br>65-6580-3811 (Singapore)<br>82-2-595-5809 (Korea)<br>81-3-5475-2332 (Japan)<br>86-21-6237-0237-541 (China)<br>86-21-2894-2607 (Asia)","<a href='/sm/rlss/bandj/'>Burdick &amp; Jackson High Purity Chemicals</a>"],
["Capran","<b>Asia/Pacific:</b><br>86-21-2894-2946","<a href='/sm/capran/'>Capran</a>"],
["Cyclohexanone, Cyclohexanol, Caprolactam","<b>Asia/Pacific:</b><br>1-877-370-7007<br>86-21-2894-2752","<a href='/sm/chemicalintermediates/'>Cyclohexanone, Cyclohexanol, Caprolactam</a>"],
["Electronic Materials","<b>Asia/Pacific:</b><br> +86-21-2894-2593 (Dimitry  Shashkov)<br><br><b>USA:</b><br> +1 (480) 293-9857 (Chris  DeMember)<br>+1 (480) 293-9868 (Michael Tucker)<br><br><b>Europe:</b><br> +44(0)1270 780 401 (Stephen Page)<br>+49(0)5137 999 218 (Pedro  Schleese)<br>+49(0)5137 999 107 (fax)","<a href='/sm/em/'>Electronic Materials</a>"],
["Enovate","<b>USA:</b><br>1-800-631-8138<br>905-608-6325 (Canada)<br>800-631-8138 (Latin, Central and South America)<br><br><b>Europe:</b><br>32-16-391-278 (Europe)<br>39-02-937-96-777 (Italy)<br><br><b>Asia/Pacific:</b><br>65-355-2828 (Singapore)","<a href='/sm/chemicals/enovate/'>Enovate</a>"],
["Fluorine Products","<b>USA:</b><br>1-800-522-8001(US)<br>905-608-6325 (Canada)<br>305-702-6490 (Latin, Central and South America)<br><br><b>Europe:</b><br>32-16-391-278<br><br><b>Asia/Pacific:</b><br>65-355-2828","<a href='/sm/chemicals/refrigerants/eu/en/'>Fluorine Products</a>"],
["Genetron Refrigerants","<b>USA:</b><br>1-800-631-8138 (US)<br>905-608-6325 (Canada)<br><br><b>Asia/Pacific:</b><br>65-776-1006 (Singapore)<br>852-2506-1812 (Hong Kong)<br>82-2-595-0204 (Korea)<br><br><b>Australia & New Zealand:</b><br>81-3-9529-1411 (Australia & New Zealand)","<a href='/sm/genetron/'>Genetron Refrigerants</a>"],
["Genesolv Solvents","<b>USA:</b><br>1-800-631-8138<br>905-608-6325 (Canada)<br>305-702-6490 (Latin America)<br><br><b>Europe:</b><br>32-16-391-287 (Belgium)<br>39-02-937-96-777 (Italy)<br><br><b>Asia/Pacific:</b><br>65-355-2828 (Singapore)","<a href='/sm/genesolv/'>Genesolv Solvents</a>"],
["Honeywell Chemicals","1-800-322-2766","<a href='/sm/specialtychemicals/ofc/'>Honeywell Chemicals</a>"],
["Lumilux<sup>&reg;</sup> Luminescent pigment","<b>Europe:</b><br>1-800-322-2766<br>49-5137-999-525 (Europe-Phone)<br>49-5137-999-121 (Europe-Fax)<br><br><b>Asia/Pacific:</b><br>65-36580-37-86 (Asia/Pacific-Phone)<br>65-6783-6054 (Asia/Pacific-Fax)","<a href='/sm/lumilux/'>Lumilux<sup>&reg;</sup> Luminescent pigment</a>"],
["Riedel-de Haen Fine Chemicals","<b>USA:</b><br>1-800-322-2766 (US)<br><br><b>Europe:</b><br>49-5137-999-227 (Europe-Phone)<br>49-5137-999-868 (Europe-Fax)<br><br><b>Asia/Pacific:</b><br>65-355-2828 (Asia/Pacific-Phone)<br>65 445 3033 (Asia/Pacific-Fax)<br>86-21-2894-2617 (Asia)","<a href='/sm/specialtychemicals/ofc/'>Riedel-de Haen Fine Chemicals</a>"],
["Rheochem<sup>&trade;</sup> vinyl lubricants","<b>USA:</b><br>1-800-222-0094<br><br><b>Europe:</b><br>32-16-391-211<br><br><b>Asia/Pacific:</b><br>65-355-2828 (Singapore)","<a href='/sm/rheochem/'>Rheochem<sup>&trade;</sup> vinyl lubricants</a>"],
["Specialty Polymers","<b>Asia/Pacific:</b><br>1-866-495-3477<br>86-21-2894-2752","<a href='/sm/polymers/'>Specialty Polymers</a>"],
["Sulf-N Ammonium Sulfate","1-800-446-3022","<a href='/sm/sulfn/na/'>Sulf-N Ammonium Sulfate</a>"],
];

var productHeader = new Array(); 
productHeader = [
["Product Name"],
["Contact Details"],
["Website"]
];

// Common variables used across the various functions
var selectedSearchMode = "";

function getSelectedProductMode() {
	
	var url = window.location.href;
	var filename = url.substring(url.indexOf('?product=')+9,url.length);
	return filename;
}