var compareList = "";
var holdCountryDropDown;
function AddRemoveFromComparison(currentCheckBox)
{	
	if(currentCheckBox.checked)
	{
		if(compareList.length > 0)
		{
			compareList = compareList + currentCheckBox.value + "|";
		}
		else
		{
			compareList = currentCheckBox.value + "|";
		}
	}
	else
	{
		compareList = replace(compareList, currentCheckBox.value + "|", "", false);
	}
}

function OpenProductCompare(evnt)
{
	var e = (window.event) ? window.event : evnt;
	
	var tempList = compareList;
	
	if(compareList.length > 0)
	{
		tempList = compareList.substring(0, compareList.length - 1);
	}
	
	var items = tempList.split("|");
	
	if(items.length < 1 || items.length > 5 || items[0].length == 0)
	{
		alert(cstNoCompare);
	}
	else
	{
		OpenProductCompareWindow(tempList)
	}
}

function OpenProductCompareWindow(productList)
{
	callPopup("/applications/search/products/compare.aspx?c=" + productList, "ProductCompare", "scrollbars=yes,resizable=yes,height=500,width=915,top=1,left=1");
}

function OpenSurveyWindowByType(openType)
{
	//SurveyButtonDiv - turn this off
	var surveyButtonDiv = document.getElementById(surveyButtonDivClientId);
	surveyButtonDiv.style.display = "none";
	
	var additionalQueryString = "";
	
	if(openType.length > 0)
	{
		additionalQueryString = "&f=" + openType;
	}
	
	callPopup("/applications/surveys/RedesignSurveyA.aspx?d=true&k=true" + additionalQueryString, "RedesignSurvey", "scrollbars=1,resizable=1,top=70,left=70,width=1000,height=600");
}

function OpenSurveyWindow()
{
	OpenSurveyWindowByType("");
}

function OpenSurveyWindowForNo()
{
	OpenSurveyWindowByType("NO");
}

function OpenSurveyWindowForYes()
{
	OpenSurveyWindowByType("YES");
}

function ToggleProductInformationTabs(visibleTab)
{
	var i;
	for(i=0;i<productInformationTabs.length;i++)
	{
		var currentDiv = document.getElementById(productInformationTabs[i]);
		
		if(i == visibleTab)
		{
			currentDiv.style.display = "";
		}
		else
		{
			currentDiv.style.display = "none";
		}
	}
}

function ToggleHideShowPropertiesCharacteristics()
{
	var propertiesDiv = document.getElementById("PropertiesDiv");
	var characteristicsDiv = document.getElementById("CharacteristicsDiv");
	
	if(propertiesDiv.style.display == "none")
	{
		propertiesDiv.style.display = "";
	}
	else
	{
		propertiesDiv.style.display = "none";
	}
	
	if(characteristicsDiv.style.display == "none")
	{
		characteristicsDiv.style.display = "";
	}
	else
	{
		characteristicsDiv.style.display = "none";
	}
}

function DatasheetCountryChanged(countryDropDown)
{
	var country = countryDropDown.options[countryDropDown.selectedIndex].value;
	holdCountryDropDown = countryDropDown;
	PullDatasheetsByCountry(country);
}

function GetDatasheetLabelName()
{
	return datasheetsClientId + "_DatasheetsLoadingLabel";
}

function GetSdsSpan()
{
	return datasheetsClientId + "_SdsSpan";
}

function GetPdsSpan()
{
	return datasheetsClientId + "_PdsSpan";
}

function PullDatasheetsByCountry(country)
{
    var loadButton = document.getElementById(datasheetsClientId + "_LoadDatasheets");
	loadButton.style.display = "none";
	
	if(holdCountryDropDown == null)
	{
		holdCountryDropDown = document.getElementById(datasheetsClientId + "_CountryDropDown");
	}
	
	holdCountryDropDown.disabled = true;

	
	//Changes Done for 339238RM		
	if(showSds == "true")
	{ 
        UpdateImage(GetSdsSpan(),datasheetsUpdatingMessage);
    }
    
    if(showPds == "true")
    {
        UpdateImage(GetPdsSpan(),datasheetsUpdatingMessage);
    }
            
	//document.body.style.cursor="wait";
	PageMethods.SdsPdsHtml(country, productId, productType, datasheetsUserLanguage, dataEnvironment, showPds, showSds, GetSdsPdsHtml_Callback);
}

function GetSdsPdsHtml_Callback(response)
{
    var documentList;
	
	documentList = response;
		
	if(showSds == "true")
	{
	var sdsSpan = document.getElementById(GetSdsSpan());
	sdsSpan.innerHTML = documentList[0];
	}
	
	if(showPds == "true")
	{
	var pdsSpan = document.getElementById(GetPdsSpan());
	pdsSpan.innerHTML = documentList[1];
	}
	
	UpdateLabel(GetDatasheetLabelName(), "");
	document.body.style.cursor="auto";
	
	holdCountryDropDown.disabled = false;
}

function DistributorStateOnChange(stateDropDown)
{
	var state = stateDropDown.options[stateDropDown.selectedIndex].value;
	
	PageMethods.SetDistributorState(state, SetDistributorState_Callback);
}

function SetDistributorState_Callback(result)
{
//Do Nothing...
}

function ShowMore(itemClientId)
{
	HideShowMoreLess(itemClientId, "none", "");
}

function ShowLess(itemClientId)
{
	HideShowMoreLess(itemClientId, "", "none");
}

function HideShowMoreLess(itemClientId, limitedDisplay, allDisplay)
{
	var limitedDiv = document.getElementById(itemClientId + "_LimitedDiv");
	var allDiv = document.getElementById(itemClientId + "_AllDiv");
	
	limitedDiv.style.display = limitedDisplay;
	allDiv.style.display = allDisplay;
}

function LogDatasheetPdfClick(documentType, title, referrer, language, country, rid)
{
	dcsMultiTrack("DCS.dcsuri",documentType + " - " + title);
	dcsMultiTrack("WT.ti","Dow Corning - " + documentType + " Document");
	dcsMultiTrack("DCSext.APP", "DOCS");
	dcsMultiTrack("WT.cg_n", "Documents");
	dcsMultiTrack("DCS.dcsref",referrer);
	dcsMultiTrack("DCSext.A04",language);
	dcsMultiTrack("DCSext.A03",country);
	dcsMultiTrack("DCSext.A08",rid);
	dcsMultiTrack("DCSext.A05",documentType);
	dcsTagAut();
}

function LogDetailsLinkClicks(boxTitle, linkTitle, productName)
{
	dcsMultiTrack("DCS.dcsuri", boxTitle + ".link");
	dcsMultiTrack("DCSext.APP", "DCSEARCH");
	dcsMultiTrack("WT.cg_n", "PFDetails");
	dcsMultiTrack("DCSext.A10", linkTitle);
	dcsMultiTrack("WT.pn", productName);
	dcsTagAut();
}

function ToggleHideShowItems(id, isStart)
{
	var itemDiv = document.getElementById("NavigationItem_" + id);
	var imageDiv = document.getElementById("ExpandCollapseImage_" + id);
	
	var imageTop, imageBottom;
	if(isStart)
	{
		imageTop = document.getElementById("NavigationDividerImageTop_" + id);
		imageBottom = document.getElementById("NavigationDividerImageBottom_" + id);
	}
	
	if(itemDiv.style.display == "")
	{
		itemDiv.style.display = "none";
		imageDiv.src = "/images/expand.gif";
		
		if(isStart)
		{
			imageBottom.style.display = "none";
			imageTop.src = "/images/BodyDivider.gif";
		}
	}
	else
	{
		itemDiv.style.display = "";
		imageDiv.src = "/images/collapse.gif";
		
		if(isStart)
		{
			imageBottom.style.display = "";
			imageTop.src = "/images/BodyShadowTop.gif";
			imageBottom.src = "/images/BodyShadowBottom.gif";
		}
	}
}

function UpdateImage(labelName,message)
{
    var label = document.getElementById(labelName);
	var new_text=document.createTextNode(message);	
	var new_image=document.createElement('img'); 
	new_image.setAttribute('src','/images/spinning_wheel.gif');
	
	if(label.childNodes.length == 0)
	{
	    //Changes Done for 377773IM	
        label.appendChild(new_image);
	    label.appendChild(new_text);
	}
	else
	{
	    label.replaceChild(new_image, label.childNodes[0]);
	    //label.replaceChild(new_text, label.childNodes[0]);
	    label.appendChild(new_text);
	}
}

function ViewMsds(productNumber, productTypeCode)
{
    productId = productNumber;
    productType = productTypeCode;
    
    holdCountryDropDown = document.getElementById(datasheetsClientId + "_CountryDropDown");
    var country = holdCountryDropDown.options[holdCountryDropDown.selectedIndex].value;
    
    var msdsInstructions = document.getElementById(msdsInstructionClientId);
    var viewMsds = document.getElementById(msdsControlSpan);
    
    msdsInstructions.style.display = "none";
    viewMsds.style.display = "";
   
    PullDatasheetsByCountry(country);
}

function RetryServerSide()
{
    var retryQueryString = "";
    
    if(reloadLinkUrl.indexOf("?") > 0)
    {
        retryQueryString = "&";
    }
    else
    {
        retryQueryString = "?";
    }
    
    holdCountryDropDown = document.getElementById(datasheetsClientId + "_CountryDropDown");
    var country = holdCountryDropDown.options[holdCountryDropDown.selectedIndex].value;
    
    retryQueryString = retryQueryString + "prod=" + productId + "&type=" + productType + "&dsctry=" + country;
    
    location.href = reloadLinkUrl + retryQueryString;
}
