﻿var Browser = {
	Version: function() {
		var version = 999;
		if (navigator.appVersion.indexOf("MSIE"))
			version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	}
}
		

function SwapImage(ImageId,NewSrc){
	document.getElementById(ImageId).src = NewSrc;
}

function doPopup(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs){
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1){
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	window.open(theURL, theWinName, paramstr);
}

function showmenu(num) {
        document.getElementById("submenu"+num).style.display = "block";
    }

function hidemenu(num) {
    document.getElementById("submenu" + num).style.display = "none";
}

function showsubmenu(parent) {
    divshow = parent.getElementsByTagName("div");    
    if (divshow.length > 0) {
		divshow[0].style.display = "block";
    }
}

function hidesubmenu(parent) {
    divshow = parent.getElementsByTagName("div");
    if (divshow.length > 0) {
        divshow[0].style.display = "none";
    }
}

function MoveSubIE6(Obj, Offset){
	//var a = document.getElementById("sd")
	//a.parentNode 
	
	if (Browser.Version() < 7){
		if (Offset == "On" && Obj.parentNode.firstChild.className == "TopMenuLink") {
			Obj.style.marginLeft = "-20px";
		}
		else if (Offset == "Off" && Obj.parentNode.firstChild.className == "TopMenuLink") {
			Obj.style.marginLeft = "0px";
		} 
	}
}
function doSearchPost(SearchTerms, NewPage, PageIsPostBack, PageCounter, SearchCategoryId) {
    document.getElementById("pSearchTerms").value = SearchTerms;
    document.getElementById("NewPage").value = NewPage;
    document.getElementById("currentPage").value = PageCounter;
    document.getElementById("PageIsPostBack").value = PageIsPostBack;
    if (document.forms.frmSearchResults) {        
        document.forms.frmSearchResults.action = 'SearchResults.aspx?C=' + SearchCategoryId ;
        document.forms.frmSearchResults.submit();
    }
}

function doSearchPost2(SearchTerms, NewPage, PageIsPostBack, PageCounter, SearchCategoryId) {
    document.getElementById("pSearchTerms2").value = SearchTerms;
    document.getElementById("NewPage2").value = NewPage;
    document.getElementById("currentPage2").value = PageCounter;
    document.getElementById("PageIsPostBack2").value = PageIsPostBack;
    if (document.forms.frmSearchResults2) {        
        document.forms.frmSearchResults2.action = 'SearchResults.aspx?C=' + SearchCategoryId ;
        document.forms.frmSearchResults2.submit();
    }
}

/*---------------------: Code for Gallery: Start : -------------------*/

function moveGallerySet(direction, buttonClicked, GalleryMove, OtherButton) {
    var thumbsArea = document.getElementById(GalleryMove);
    var leftMargin = thumbsArea.style.marginLeft;
    if (!leftMargin) {
        leftMargin = 0;
    }
    else {
        leftMargin = leftMargin.replace("px", "");
    }
    thumbsArea.style.marginLeft = leftMargin + "px";
    if (direction == 1) {
        //check if there is something to show. We need absolute values. Since leftMargin is either
        //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
        //whether there is anything hidden to the right. If there is, then the thumbnail area width
        //must be greater than the sum of the width of the showable area and the amount we've already 
        //shifted the thumbnail area to the left.
        if (thumbsArea.parentNode.offsetWidth - leftMargin < thumbsArea.offsetWidth-10) {
            leftMargin = leftMargin - thumbsArea.parentNode.offsetWidth;
            slideLeft(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
            //thumbsArea.style.marginLeft = leftMargin + "px";
        }
        //Now that we've moved the area, blindly activate the "back" button.
        document.getElementById(OtherButton).style.display = "inline";
        //Also, check whether we need to de-activate the "forward" button. Same rationale as above.
        if (thumbsArea.parentNode.offsetWidth - leftMargin > thumbsArea.offsetWidth) {
            document.getElementById(buttonClicked).style.display = "none";
        }
    }
    else {
        //check if there is something to show. We need absolute values. Since leftMargin is either
        //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
        //whether there is anything hidden to the left. If there is, then the margin is negative.
        if (leftMargin < 0) {
            leftMargin = parseInt(leftMargin) + parseInt(thumbsArea.parentNode.offsetWidth);
            //The leftmost position is with left margin equal to 0. If we go beyond that, it's an error
            if (leftMargin > 0) {
                leftMargin = 0;
            }
            slideRight(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
            //thumbsArea.style.marginLeft = leftMargin + "px";
        }
        //Now that we've moved the area, blindly activate the "forward" button.
        document.getElementById(OtherButton).style.display = "inline";
        //Also, check whether we need to de-activate the "back" button. Same rationale as above.
        if (leftMargin >= 0) {
            document.getElementById(buttonClicked).style.display = "none";
        }
    }
}

function slideLeft(start, stop, elementId, speed) {
    var i;
    var counter=0;
    for (i = start; i > stop; i--) {
        counter++;
        window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10 / speed) * counter);
    }
 }

 function slideRight(start, stop, elementId, speed) {
    var i;
    var counter = 0;
    for (i = start; i < stop; i++) {
        counter++;
        window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10/speed) * counter);
    }
}

/*---------------------: Code for Gallery: End : -------------------*/