//category.jsp

var browsername=navigator.appName;
var completeUrl = "";
var url = "";
var lPageNo = "";

function loadXMLDocForCategory(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function processReqChange(){
    if (req.readyState == 4){
        if (req.status == 200){
            window.document.location.href = completeUrl;
        } else {
            alert("There was a problem retrieving the XML data:\n" +req.statusText);
        }
    }
}


function handleWithEnterKey(evt,pUrl){
    if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13)){
        goToPage(document.getElementById('pgno').value,pUrl);
    }
}



function goToPage(pageNo,pCompleteUrl){
    var lPageNo = trimString(pageNo);
    if(pageNo!=null && pageNo!=''){
       window.document.location.href = pCompleteUrl+"page-"+pageNo+"/";

    }
}

function trimString (str) {
    while (str.charAt(0) == ' ')
    str = str.substring(1);
    return str;
}

function changeItemsPerPage(pUrl,pCompleteUrl){
	
	completeUrl = pCompleteUrl;
    var shoesPerPage = document.getElementById("itemsPerPage").value;
    var url = pUrl+"/pagination.do?shoesperpage="+shoesPerPage+"&number="+Math.random();
    
    this.loadXMLDocForCategory(url);
}

//itemsincategory

function hoverBorderOn(row) {
    try{
        row.style.borderColor = '#999999';
    } catch(e) {};

}

function hoverBorderOff(row) {
    try{
        row.style.borderColor = 'white';
    }catch(e){
    }
}

function addbackURL(backURL) {
	if (window.sidebar && window.sidebar.addPanel) {
		window.sidebar.addPanel('Solestruck - A Passion for Shoes', backURL,'');
	} else {
		window.external.AddFavorite(backURL,'Solestruck - A Passion for Shoes');
	}
}

//sale.jsp

function addbackURLForSale(backURL) {
		if (window.sidebar && window.sidebar.addPanel) {
			window.sidebar.addPanel('sale', backURL,'');
		} else {
			window.external.AddFavorite(backURL,'sale');
		}
	}

function loadXMLDocForSale(pUrl) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeForSale;
        req.open("GET", pUrl, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangeForSale;
            req.open("GET", pUrl, true);
            req.send();
        }
    }
}


function processReqChangeForSale() {
    if (req.readyState == 4) {
        if (req.status == 200) {
			var pageNo=1;
			if(lPageNo!=null){
				pageNo = lPageNo;
		}

		// Updated By Mugundhan FOR CDSS 102 on 11/01/10

		var size =document.getElementById('sizeselect').innerHTML;
		var color =document.getElementById('colorselect').innerHTML;
		var style =document.getElementById('styleselect').innerHTML;  
		var brand =document.getElementById('brandselect').innerHTML;
		var price =document.getElementById('priceselect').innerHTML;
		var percentage = document.getElementById('percentageselect').innerHTML;
		var TheAction = "/sale-shoes/";
		if (brand != "view all"){TheAction +='brand-'+brand.replace(/ /g,"-")+"/";}
		if (style != "view all"){TheAction +='style-'+style.replace(/ /g,"-")+"/";}
		if (color != "view all"){TheAction +='color-'+color.replace(/ /g,"-")+"/";}
		if (size != "view all"){TheAction +='size-'+size+"/";}
		if (price != "view all"){TheAction +='price-'+price.replace(/ /g,"-")+"/";}
		if (percentage != "view all") { TheAction += 'percentage-' +(percentage.replace(/%/g,"")).replace(/ /g,"-") + "/"; }
        TheAction+="page-"+"1"+"/";
		
		window.document.location.href = url+TheAction;
			
        }else {
            alert("There was a problem retrieving the XML data:\n" +req.statusText);
        }
    }
}


function handleWithEnterKeyForSale(evt,pUrl,pSubCategoryId){
    if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13)){
		if(pSubCategoryId == 'sale')
			goToPageForSale(document.getElementById('pgno').value,pUrl);
		else if(pSubCategoryId == 'advancesearch')
			goToPageForSearch(document.getElementById('pgno').value,pUrl);
    }
}

function goToPageForSale(pageno,pUrl){

	url = pUrl;
    lPageNo = trimStringForSale(pageno);

// Updated by Mugundhan  FOR CDSS 102 on 11/01/10

    if(lPageNo!=null && lPageNo!=''){
		var size =document.getElementById('sizeselect').innerHTML;
		var color =document.getElementById('colorselect').innerHTML;
		var style =document.getElementById('styleselect').innerHTML;  
		var brand =document.getElementById('brandselect').innerHTML;
		var price =document.getElementById('priceselect').innerHTML;
		var percentage = document.getElementById('percentageselect').innerHTML;
   	    var TheAction = "/sale-shoes/";
		if (brand != "view all"){TheAction +='brand-'+brand.replace(/ /g,"-")+"/";}
		if (style != "view all"){TheAction +='style-'+style.replace(/ /g,"-")+"/";}
		if (color != "view all"){TheAction +='color-'+color.replace(/ /g,"-")+"/";}
		if (size != "view all"){TheAction +='size-'+size+"/";}
		if (price != "view all"){TheAction +='price-'+price.replace(/ /g,"-")+"/";}
		if (percentage != "view all") { TheAction += 'percentage-' +(percentage.replace(/%/g,"")).replace(/ /g,"-") + "/"; }
		TheAction+="page-"+lPageNo+"/";	
		window.document.location.href = url+TheAction;
    }
}


function trimStringForSale (str) {
    while (str.charAt(0) == ' ')
    str = str.substring(1);
    return str;
}

function changeItemsPerPageForSale(pUrl,pSubCategoryId){
	
	url = pUrl;
    var shoesPerPage = document.getElementById("itemsPerPage").value;
    var lUrl = pUrl+"/pagination.do?shoesperpage="+shoesPerPage;
	if(pSubCategoryId == 'sale')
		this.loadXMLDocForSale(lUrl);
	else if(pSubCategoryId == 'advancesearch')
	{
		if(document.getElementById("isClodTagNeeded").value="needed")
		{		
			var shoesPerPage = document.getElementById("itemsPerPage").value;
   			var url = pUrl+"/pagination.do?shoesperpage="+shoesPerPage+"&number="+Math.random();
    		this.loadXMLDocForCategory(url);
		}else
		{
			this.loadXMLDocForSearch(lUrl);
		}
	}
}

//search

function goToPageForSearch(pageno,pUrl){
	if(document.getElementById("isClodTagNeeded").value="needed")
	{
		
			window.document.location.href = pUrl+"page-"+trimString(pageno)+"/";	
	}
	else
	{
	//url = pUrl;
    lPageNo = trimString(pageno);
    if(pageno!=null && pageno!=''){
		var heelheight=document.getElementById('heelheightselect').innerHTML;
		var size =document.getElementById('sizeselect').innerHTML;
		var color =document.getElementById('colorselect').innerHTML;
		var style =document.getElementById('styleselect').innerHTML;  
		var brand =document.getElementById('brandselect').innerHTML;
		var searchkey = "";
		if(document.getElementById('soleSearchQuery') != null)
		 searchkey =document.getElementById("soleSearchQuery").value;
		var TheAction = "/search-womens-shoes/";
		if (searchkey != ""){TheAction +='phrase-'+searchkey.replace(/ /g,"-")+"/";}
		if (brand != "select" && brand != "view-all"){TheAction +='brand-'+brand.replace(/ /g,"-")+"/";}
		if (style != "select" && style != "view-all"){TheAction +='style-'+style.replace(/ /g,"-")+"/";}
		if (heelheight != "select" && heelheight != "view-all"){TheAction +='heelheight-'+heelheight.replace(/ /g,"-")+"/";}
		if (color != "select" && color != "view-all"){TheAction +='color-'+color.replace(/ /g,"-")+"/";}
		if (size != "select" && size != "view-all"){TheAction +='size-'+size.replace(/ /g,"-")+"/";}
		TheAction+="page-"+lPageNo+"/";
		window.document.location.href = url+TheAction;		
    }
    }
}



function loadXMLDocForSearch(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeForSearch;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangeForSearch;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function processReqChangeForSearch() {

    if (req.readyState == 4) {

        if (req.status == 200) {
			var pageNo=1;
			if(lPageNo!=null && lPageNo!=''){
				pageNo = lPageNo;
		}
		var heelheight=document.getElementById('heelheightselect').innerHTML;
		var size =document.getElementById('sizeselect').innerHTML;
		var color =document.getElementById('colorselect').innerHTML;
		var style =document.getElementById('styleselect').innerHTML;  
		var brand =document.getElementById('brandselect').innerHTML;
		var searchkey  = "";
		if(document.getElementById('soleSearchQuery') != null)
		 searchkey =document.getElementById("soleSearchQuery").value;
		var TheAction = "/search-womens-shoes/";
		if (searchkey != ""){TheAction +='phrase-'+searchkey+"/";}
		if (brand != "select" && brand != "view-all"){TheAction +='brand-'+brand.replace(/ /g,"-")+"/";}
		if (style != "select" && style != "view-all"){TheAction +='style-'+style.replace(/ /g,"-")+"/";}
		if (heelheight != "select" && heelheight != "view-all"){TheAction +='heelheight-'+heelheight.replace(/ /g,"-")+"/";}
		if (color != "select" && color != "view-all"){TheAction +='color-'+color.replace(/ /g,"-")+"/";}
		if (size != "select" && size != "view-all"){TheAction +='size-'+size.replace(/ /g,"-")+"/";}
		TheAction+="page-"+pageNo+"/";
		window.document.location.href = url+TheAction;
			
        } else {
            alert("There was a problem retrieving the XML data:\n" +req.statusText);
        }
    }
}

function goToPageForSaleOrSearch(pageno,pUrl,pSubCategoryId){
	lPageNo = trimStringForSale(pageno);
	if(pSubCategoryId == 'sale')
		goToPageForSale(document.getElementById('pgno').value,pUrl);
	else if(pSubCategoryId == 'advancesearch')
		goToPageForSearch(document.getElementById('pgno').value,pUrl);
}

 function checkGoToArrowProperty(id1,id2) {
     /*alert(id1);
     alert(id2);*/
     var browserName = navigator.appName;
     if (browserName == "Microsoft Internet Explorer") {
         document.getElementById(id1).style.paddingTop = "1px";
         document.getElementById(id2).style.paddingTop = "0px";
     }
 }

function rollDiv (pDivId) {
	document.getElementById(pDivId).style.cursor = 'pointer';
	document.getElementById(pDivId).style.color = '#000000';
}

function unrollDiv (pDivId) {
	document.getElementById(pDivId).style.cursor = 'auto';
	document.getElementById(pDivId).style.color = '#666666';
}

function showDiv (pDivId) {
	document.getElementById(pDivId).style.display = 'block';
}

function hideDiv (pDivId) {
	document.getElementById(pDivId).style.display = 'none';
}

function enableZoomDiv(id)
{
//document.getElementById(id).style.display = "block";
document.getElementById(id).style.color = "black";
}

function disableZoomDiv(id)
{
//document.getElementById(id).style.display = "none";
document.getElementById(id).style.color = "white";

}




