//-----------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (C) Copyright IBM Corp. 2009 All Rights Reserved.
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with
// IBM Corp.
//-----------------------------------------------------------------

// GOSPCatalog.js

// JS function to display and hide the categories

var sub = false;

function categoryChange(cat,categories) { 
	
	var catArrays = null;
	if (null != categories) {
		catArrays = categories.split("|")
	}
	if (null != catArrays) {
		for (index = 0; index < catArrays.length; index++) {
			if (null != catArrays[index] && catArrays[index] != '') {
				document.getElementById(catArrays[index] + "_on").style.visibility="hidden";
				document.getElementById(catArrays[index] + "_on").style.display="none";
				
				document.getElementById(catArrays[index] + "_off").style.visibility="visible";
				document.getElementById(catArrays[index] + "_off").style.display="inline";
				
				document.getElementById("show_" + catArrays[index]).style.visibility="hidden";
				document.getElementById("show_" + catArrays[index]).style.display="none";
			}	
		}
	}
		
	var catOn = cat + "_on";
	var catOff = cat + "_off";
	var catshow = "show_"+ cat;
	
	document.getElementById(catOn).style.visibility="visible";
	document.getElementById(catOn).style.display="inline";	
	
	document.getElementById(catOff).style.visibility="hidden";
	document.getElementById(catOff).style.display="none";	
	
	document.getElementById(catshow).style.visibility="visible";
	document.getElementById(catshow).style.display="inline";	
}

//====================SEARCH RESULT PAGE==============================

function submitCatalogSortForm(catGroupId) {

	if(document.CatalogSortForm.orderBy1.value==0) {
		return false;
	}
	else 
	{
		setSortingFields();
	}	
	
	if(catGroupId==undefined) {
//		alert("catGroupId==undefined");
		document.CatalogSortForm.catGroupId.value="";
	}
	else {
//		alert("catGroupId!=undefined");
//		alert("catGroupId: "+catGroupId);
		document.CatalogSortForm.catGroupId.value=catGroupId;
	}
	document.CatalogSortForm.submit();
} 
function getRadioValue(catGroupId)
{
//	alert("catGroupId: "+catGroupId);
	setSortingFields();
	if(catGroupId == '') {
//		alert("catGroupId is empty");
		document.CatalogSortForm.catGroupId.value="";
	}
	else {	
//		alert("catGroupId is NOT empty");	
   		document.CatalogSortForm.catGroupId.value=catGroupId;
    }
	document.CatalogSortForm.submit();
}
     
function setSortingFields()
{
	var strOrderBy = document.CatalogSortForm.orderBy1.value;
	var strsortOrder = "AscOperator";
		if(strOrderBy == 'PriceL' || strOrderBy == 'PriceH')
		{
			if(strOrderBy=='PriceH')
				strsortOrder = "DescOperator";
				
			strOrderBy = "ListPriceListPrice";
			
		}	
	
	//Sorting order

	for (var i=0; i<document.CatalogSortForm.orderBy1.length; i++){
		 if (document.CatalogSortForm.orderBy1[i].selected==true){
		  	document.CatalogSortForm.orderBy1[i].value = strOrderBy;
		 }
		}

	document.CatalogSortForm.orderByOperator1.value=strsortOrder;
}

//========================SEARCH RESULT PAGE==========================

//========================CATEGORY LANDING PAGE=======================
function submitCategoryLandingSortForm() {
	if(document.CategoryLandingSortForm.orderBy.value==0) {
	
		return false;
	}
	document.CategoryLandingSortForm.submit();
}  
//========================CATEGORY LANDING PAGE=======================

//========================ACCESSORY LANDING PAGE======================

function submitAccessoryLandingSortForm() {

	if(document.AccessoryLandingSortForm.orderBy.value==0) {

		return false;
	}
	else {
	
	}

	document.AccessoryLandingSortForm.submit();
}  

function submitAccessoryLandingSortFormWithSubCategory() {

	if(document.AccessoryLandingSortForm.subCategoryId.value==0) {
	
		return false;
	}

	document.AccessoryLandingSortForm.submit();
}  

//========================ACCESSORY LANDING PAGE======================

//========================FACETED NAVIGATION======================
function submitAccessoryDisplayForm() {

	if(document.AccessoryDisplayForm.accProductId.value==0) {
		return false;
	}
	
	document.AccessoryDisplayForm.submit();
}

function submitFacetedNavAccessoriesForm(httpWebPath, catGroupId){

	var storeId=document.FacetedNavAccessoriesForm.storeId.value;
	var catalogId=document.FacetedNavAccessoriesForm.catalogId.value;
	var langId=document.FacetedNavAccessoriesForm.langId.value;
	var categoryId=catGroupId;
	var pageSize=document.FacetedNavAccessoriesForm.pageSize.value;
	var beginIndex=document.FacetedNavAccessoriesForm.beginIndex.value;
	var minPrice=document.FacetedNavAccessoriesForm.minPrice.value;
	var maxPrice=document.FacetedNavAccessoriesForm.maxPrice.value;
	var orderBy=document.FacetedNavAccessoriesForm.orderBy.value;
    var subSubCategoryId=document.FacetedNavAccessoriesForm.subSubCategoryId.value;
    var isAccessoryCategory=document.FacetedNavAccessoriesForm.isAccessoryCategory.value;
    var field1=document.FacetedNavAccessoriesForm.field1.value;
    var submitAction=document.FacetedNavAccessoriesForm.submitAction.value;

	window.location=httpWebPath+submitAction+"_"+storeId+"_"+catalogId+"_"+langId+"_"+categoryId+"_"+pageSize+"_"+minPrice+"_"+maxPrice+"_"+orderBy+"_"+subSubCategoryId+"_"+isAccessoryCategory+"_"+field1+"_"+beginIndex;
}


function submitFacetedNavSubAccessoriesForm(httpWebPath, catGroupId, subSubCategoryId){
	var storeId=document.FacetedNavAccessoriesForm.storeId.value;
	var catalogId=document.FacetedNavAccessoriesForm.catalogId.value;
	var langId=document.FacetedNavAccessoriesForm.langId.value;
	var categoryId=catGroupId;
	var pageSize=document.FacetedNavAccessoriesForm.pageSize.value;
	var beginIndex=document.FacetedNavAccessoriesForm.beginIndex.value;
	var minPrice=document.FacetedNavAccessoriesForm.minPrice.value;
	var maxPrice=document.FacetedNavAccessoriesForm.maxPrice.value;
	var orderBy=document.FacetedNavAccessoriesForm.orderBy.value;
    var subSubCategoryId=subSubCategoryId;
    var isAccessoryCategory=document.FacetedNavAccessoriesForm.isAccessoryCategory.value;
    var field1=document.FacetedNavAccessoriesForm.field1.value;
    var submitAction=document.FacetedNavAccessoriesForm.submitAction.value;

	window.location=httpWebPath+submitAction+"_"+storeId+"_"+catalogId+"_"+langId+"_"+categoryId+"_"+pageSize+"_"+minPrice+"_"+maxPrice+"_"+orderBy+"_"+subSubCategoryId+"_"+isAccessoryCategory+"_"+field1+"_"+beginIndex;
}


function gotoHomePageFromAccessories(homePageURL,obj){
	document.FacetedNavAccessoriesForm.categoryId.value="";
	obj.location = homePageURL;
}

function submitPhoneDisplayForm(httpWebPath) {
	var storeId=document.PhoneDisplayForm.storeId.value;
	var catalogId=document.PhoneDisplayForm.catalogId.value;
	var langId=document.PhoneDisplayForm.langId.value;
	var PhByMod=document.PhoneDisplayForm.PhByMod.value;
	var productId=document.PhoneDisplayForm.productId.value;

	if(productId==0) {
		return false;
	}
	else {
		window.location=httpWebPath+"productdetailbymodel_"+storeId+"_"+catalogId+"_"+langId+"_"+productId+"_"+PhByMod;
	}
}

function submitFacetedNavDevicesForm(httpWebPath,catGroupId){
	var storeId=document.FacetedNavDevicesForm.storeId.value;
	var catalogId=document.FacetedNavDevicesForm.catalogId.value;
	var langId=document.FacetedNavDevicesForm.langId.value;
	var categoryId=catGroupId;
	var pageSize=document.FacetedNavDevicesForm.pageSize.value;
	var beginIndex=document.FacetedNavDevicesForm.beginIndex.value;
	var minPrice=document.FacetedNavDevicesForm.minPrice.value;
	var maxPrice=document.FacetedNavDevicesForm.maxPrice.value;
	var orderBy=document.FacetedNavDevicesForm.orderBy.value;
    var deviceSelected=document.FacetedNavDevicesForm.deviceSelected.value;
    var field1=document.FacetedNavDevicesForm.field1.value;
    var submitAction=document.FacetedNavDevicesForm.submitAction.value;

	if(sub == false) {
		sub = true;
		window.location=httpWebPath+submitAction+"_"+storeId+"_"+catalogId+"_"+langId+"_"+categoryId+"_"+pageSize+"_"+minPrice+"_"+maxPrice+"_"+orderBy+"_"+deviceSelected+"_"+field1+"_"+beginIndex;
	}

}

function submitFacetedNavDevicesForm2(catGroupId){
	
	document.FacetedNavDevicesForm.categoryId.value=catGroupId;
	if(sub == false) {
		sub = true;
		document.FacetedNavDevicesForm.submit();
	}

}

function gotoHomePageFromDevices(homePageURL,obj){
	document.FacetedNavDevicesForm.categoryId.value="";
	obj.location = homePageURL;
}


function submitFacetedNavDevicesFormWithPriceRange(categoryId,minPrice,maxPrice){
	document.FacetedNavDevicesForm.categoryId.value=categoryId;

	document.FacetedNavDevicesForm.minPrice.value=minPrice;
	document.FacetedNavDevicesForm.maxPrice.value=maxPrice;
	document.FacetedNavDevicesForm.submit();
}

function submitFacetedNavDevicesFormWithoutPriceRange(categoryId){
	document.FacetedNavDevicesForm.categoryId.value=categoryId;
	document.FacetedNavDevicesForm.minPrice.value=-1;
	document.FacetedNavDevicesForm.maxPrice.value=-1;
	document.FacetedNavDevicesForm.submit();
}

function submitFacetedNavDevicesFormWithFeatures(categoryId,minPrice,maxPrice){
	document.FacetedNavDevicesForm.categoryId.value=categoryId;
	document.FacetedNavDevicesForm.minPrice.value=minPrice;
	document.FacetedNavDevicesForm.maxPrice.value=maxPrice;

	//document.FacetedNavDevicesForm.submit();


	if(sub == false) {
		sub = true;
		document.FacetedNavDevicesForm.submit();
	}
	else {
//		alert("Please wait till you get the response");
	}
	

}

function validateSearchTerm() {
	var searchTerm = document.CatalogSearchForm.searchTerm.value;
	//alert("searchTerm: "+ searchTerm);
	document.CatalogSearchForm.submit();
	
}  


function submitBrowseAll(field1){
	
	document.FacetedNavDevicesForm.field1.value=field1;
	
	document.FacetedNavDevicesForm.submit();
	
}

function submitBroweAllWithPriceRange(field1,minPrice,maxPrice){
	document.FacetedNavDevicesForm.field1.value=field1;

	document.FacetedNavDevicesForm.minPrice.value=minPrice;
	document.FacetedNavDevicesForm.maxPrice.value=maxPrice;
	document.FacetedNavDevicesForm.submit();
}
function submitBrowseAllWithoutPriceRange(field1){
	document.FacetedNavDevicesForm.field1.value=field1;
	document.FacetedNavDevicesForm.minPrice.value=-1;
	document.FacetedNavDevicesForm.maxPrice.value=-1;
	document.FacetedNavDevicesForm.submit();
}
function submitBrowseAllAccessoriesForm(field1){

	document.FacetedNavAccessoriesForm.field1.value=field1;
	document.FacetedNavAccessoriesForm.submit();
}



//========================FACETED NAVIGATION======================

function flashDisabled(cat) { 
	
	document.getElementById("flashcontent1_on").style.visibility="hidden";
	document.getElementById("flashcontent1_on").style.display="none";
	document.getElementById("flashcontent2_on").style.visibility="hidden";
	document.getElementById("flashcontent2_on").style.display="none";

	var catOn = cat + "_on";
	
	document.getElementById(catOn).style.visibility="visible";
	document.getElementById(catOn).style.display="inline";	
}

