
function quickSearch(did, catalog)
{
    objForm = document.forms[0];
    strUrl = '';
    
    for (i = 0; i < objForm.length; i++)
    {
        if (objForm[i].name.toLowerCase().indexOf('qs_') > -1 && objForm[i].value.length > 0)
        {
            if (objForm[i].name.toLowerCase().indexOf('freetext') > -1)
                strUrl += "&scF_" + objForm[i].name.replace('qs_', '') + '=' + objForm[i].value;
            else
                strUrl += "&scL_" + objForm[i].name.replace('qs_', '') + '=' + objForm[i].value;
        }
    }
    if (catalog != null && catalog.length > 0)
	    window.location = "/products.aspx?did=" + did + "&ctl=" + catalog + strUrl;
	else
	    window.location = "/products.aspx?did=" + did + strUrl;
}

function CheckAllAdvanced(f_strFormName) {
	intCount = 0;
	if (typeof(document.forms[f_strFormName]) == 'object') {
		for (var i = 0; i < document.forms[f_strFormName].length ; i ++)  {
			if (document.forms[f_strFormName].elements[i].type=='checkbox') {
				if (document.forms[f_strFormName].elements[i].name.length < 20)
				{
					document.forms[f_strFormName].elements[i].checked = eval(document.forms[f_strFormName].CheckAllAction.value);
					intCount = intCount + 1;
				}
			}
		}
	}
	if (intCount > 0)
	{
		if (document.forms[f_strFormName].CheckAllAction.value=='true') {
			document.forms[f_strFormName].CheckAllAction.value = 'false';
		}
		else {		
			document.forms[f_strFormName].CheckAllAction.value = 'true';	
		}
	}
}


function CheckSelChkBoxes(f_intNumOfSelReq, f_strErrorStatus, f_intMax, f_strMaxError) {
	var intChecked = 0;
	for (var i = 0; i < document.forms[0].length ; i ++)  {
		if (document.forms[0].elements[i].type=='checkbox' && document.forms[0].elements[i].checked==true) {
			intChecked++;	
		}
	}
	if (intChecked > f_intMax) {
	    document.forms[0].action='';
	    document.forms[0].postaction.value='';
	    alert(f_strMaxError); 
		return void(0);
	}
	else if (intChecked >= f_intNumOfSelReq) {
	    document.forms[0].submit();
	    document.forms[0].action='';
		return true;
	}
	else {
	    document.forms[0].action='';
	    document.forms[0].postaction.value='';
		alert(f_strErrorStatus); 
		return void(0);
	}
	
}
function basicPopup(url1, url2) {

popupWindow = window.open(url1,'popUpWindow','height=150,width=600,left=100,top=100,resizable=no,scrollbars=no,toolbar=nos,menubar=no,location=no,directories=no, status=no');
setTimeout("Redirect('" + url2 + "');popupWindow.close();",10000);

	}
function Redirect(url)
{
  location.href = url;
}

function goSetHeight(framename) 
        {
            if (parent == window) return;
            // arg: id of iframe element this doc is to be loaded into
            else parent.setIframeHeight(framename);
        }

function productImageViewer(containerElem, parameters)
{
	this.parameters = $.extend({
		mainContainerId: 'image_main',
		thumbsContainerId: 'image_thumbs',
		controlsContainerId: 'slideshow_controls',
		imageClass: 'image_main',
		thumbClass: 'thumb',
		prevButtonId: 'prev',
		nextButtonId: 'next'
	}, parameters);
	
	this.mainContainer = $('#' + this.parameters.mainContainerId);
	this.controlsContainer = $('#' + this.parameters.controlsContainerId);
	this.thumbsContainer = $('#' + this.parameters.thumbsContainerId);

	this.maxWidth = this.mainContainer.width();
	this.maxHeight = this.mainContainer.height();
	//alert('max: ' + this.maxWidth + 'x' + this.maxHeight);
	this.links = this.thumbsContainer.find('a.' + this.parameters.thumbClass);
	this.currentImage = this.mainContainer.find('img.' + this.parameters.imageClass);
	this.currentIndex = 0;
	this.zIndex = 50;
	this.isLoading = false;
	this.loaded = [];
	
	if (this.currentImage.length == 0)
	{
		return;
	}

	var objPointer = this;
	if (this.links.length > 0)
	{
		this.loaded = new Array(this.links.length);
				
		this.links.each(function(index, element) {
			element.id = objPointer.parameters.thumbsContainerId + '_0' + index;
		});
		
		this.links.hover(function(event) {
			event.preventDefault();
			objPointer.show(-1, null, this, false);
			return false;
		});

	    this.links.click(function(event) {
			event.preventDefault();
			this.blur();
			objPointer.show(-1, null, this, false);
			return false;
		});

		if (this.links.length > 1)
		{
			this.mainContainer.hover(
				function(event) {
					objPointer.controlsContainer.fadeIn('fast');
				},
				function(event) {
					objPointer.controlsContainer.fadeOut('slow');
				}
			);
			
			this.controlsContainer.find("[id$='" + this.parameters.prevButtonId + "']").click(function(event) {
				objPointer.showPrevious();
			});
			this.controlsContainer.find("[id$='" + this.parameters.nextButtonId + "']").click(function(event) {
				objPointer.showNext();
			});
		}
	}
	else
	{
		this.loaded = new Array(1);
	}

//	if (document.all && typeof this.currentImage[0].onreadystatechange != 'undefined' && this.currentImage[0].readyState != 'complete')
//	{
//		this.isLoading = true;
//		this.currentImage[0].onreadystatechange = function() {
//			if (this.readyState == 'complete')
//			{
//				objPointer.show(0, this, null, true);
//			}
//		}
//	}
//	else if (!this.currentImage[0].complete)
//	{
//		this.isLoading = true;
//		this.currentImage[0].onload = function() {
//			if (this.complete)
//			{
//				objPointer.show(0, this, null, true);
//			}
//		}
//	}
//	else
//	{
		this.show(0, this.currentImage[0], null, false);
//	}
}

function mascusProductImages(parameters) {
	if (!parameters)
		parameters = {};
	return this.each(function(){
		var viewer = new productImageViewer(this, parameters);
	});
};
