/* AUTOCOMPLETE CONFIGURATION */
//DataSource
var myServer = "./autocomplete.aspx";
//var mySchema = ["ResultItem", "KeyDataField"];
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
this.myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
//AutoComplete
var myAutoComp = new YAHOO.widget.AutoComplete("SearchTerm","container", myDataSource);
myAutoComp.minQueryLength = 3;
myAutoComp.autoHighlight = false;
myAutoComp.animSpeed = 0.3;
myAutoComp.animVert = true;
myAutoComp.animHoriz = false;
myAutoComp.useShadow = true;
myAutoComp.prehighlightClassName = "yui-ac-prehighlight";

myAutoComp.formatResult = function(oResultItem, sQuery)
{
	var title = oResultItem[0];
	var url = oResultItem[1];
	var sMarkup;
	myAutoComp.setFooter("<a id='sitesearchshowall' style='text-decoration:none;' href='javascript:viewAll();'>View all other search results</a>");
	if(url == "None")
	{
		sMarkup = "No results found.";
		myAutoComp.setFooter("");
	}
	else
	{
		//sMarkup = "<a style='text-decoration:none;' href='" + url + "'>" + title + "</a>";
		sMarkup = title;
	}
	document.getElementById('loading-gif').style.visibility = 'hidden';
	return (sMarkup);
}

  /* What do we want to do when an item in the suggestion container
	   is selected (either by arrowing and hitting enter or by clicking)?
	   We'll subscribe to the itemSelectEvent and when it fires use its
	   arguments to set a new location for the current page. */
	this.myAutoComp.itemSelectEvent.subscribe(function(type, args) {
 		/* this line works around Opera's preventDefault
 		   bug: */
 		YAHOO.util.Dom.get("gobtn").disabled = true;
 		
 		/* now, we go off to the destination page chosen by
 		   the user from the AutoComplete suggestion list: */
 		if (args[2][1] != 'None')
    {
 		   location.href = (args[2][1]);
    }	
 	});

  /* Here's the wiring for the form submission on our footer link.
     Note that we use the YUI Event Utility to add this listener --
     this is part of YUI Core. */
  //YAHOO.util.Event.on("sitesearchshowall", "click", function(e) {
  	 /* The Dom Collection's get method is similar to
  		document.getElementById in this instance: */
  	 //YAHOO.util.Dom.get("Form").submit();
  //	 document.getElementById("Form").submit();
  //});

this.myAutoComp._updateValue = function() {
	return true;
}

function viewAll()
{
  searchTerm = document.getElementById("SearchTerm").value;
  //searchTerm = searchTerm.replace(" ", "+");
  searchTerm = searchTerm.replace(/ /g, "+");
  location.href = 'http://www.inkisland.com/search.aspx?SearchTerm=' + searchTerm;
}
          
// IFrame workaround for IE
//var ua = navigator.userAgent.toLowerCase();
//if(ua.indexOf('msie') != -1 && ua.indexOf('opera') < 0) 
//{
//this.myAutoComp.useIFrame = true;
//YAHOO.util.Dom.get("useiframe").checked = true;
//}				 					
/* END OF AUTOCOMPLETE CONFIGURATION */

/* jQuery events*/
$().ready(function() {
	$("#Form2").submit(function (){
		if( $("#SearchTerm2").val() == "")
		{
			alert('Please enter at least 3 characters in the search field!');
			return false;
		}
		else
		{							
			$("#SearchTerm2").attr({
			id: "SearchTerm",
			name: "SearchTerm"
			})
			return true;
		}
	});
  $("#searchroll").click(function () {
    $("#Form").submit();
  });
	
	$("#searchrollbig").click(function () {
	  $("#SearchTerm2").attr({
		id: "SearchTerm",
		name: "SearchTerm"
	  })
	  $("#Form2").submit();
	}); 	
});
/* end of jQuery events */
          
function bookmark()
{
  var title=document.title;
  var url=location.href;
  
  if (window.sidebar) window.sidebar.addPanel(title, url,"");
  
  else if( window.opera && window.print )
  {
  var mbm = document.createElement('a');
  mbm.setAttribute('rel','sidebar');
  mbm.setAttribute('href',url);
  mbm.setAttribute('title',title);
  mbm.click();
  }
  
  else if( document.all ) window.external.AddFavorite( url, title);
}
function bookmark1()
{
  var title='Ink Island - Ink Cartridges & Electronic Accessories';
  var url='http://www.inkisland.com';
  
  if (window.sidebar) window.sidebar.addPanel(title, url,"");
  
  else if( window.opera && window.print )
  {
  var mbm = document.createElement('a');
  mbm.setAttribute('rel','sidebar');
  mbm.setAttribute('href',url);
  mbm.setAttribute('title',title);
  mbm.click();
  }
  
  else if( document.all ) window.external.AddFavorite( url, title);
}


				
		function fillModel(seriesID, brandID)
		{
			var returnValue = Abacus_Store.singleProduct.getModels(seriesID, brandID).value;
			$('#modelContainer').html(returnValue);	
		}



/** Compatibility checker **/

	
/** End of compatibility checker **/



/** My Account **/

function showOrderItems(orderId) {
    //var orderId = $(this).attr('id');
    var itemsId = "#" + orderId + "-items";
    var display = $(itemsId).css('display');
    //if ($('#'+orderId+'-items').is(':visible'))
    if (display == 'none') {
        $('#' + orderId).text("Hide order items");
        $('#' + orderId + '-items').show();
    }
    else {
        $('#' + orderId).text("Show order items");
        $('#' + orderId + '-items').hide();
    }
}

function showInvoiceDetails(orderId) {
    var invoiceId = orderId + "-invoice-details";
    var spanId = orderId + "-invoice";
    var display = $('#' + invoiceId).css('display');
    //if ($('#'+orderId+'-items').is(':visible'))
    if (display == 'none') {
        $('#' + spanId).text("Hide invoice details");
        $('#' + invoiceId).show();
    }
    else {
        $('#' + spanId).text("Show invoice details");
        $('#' + invoiceId).hide();
    }

}

$('#accountContainer').tabs();

$(document).ready(function() {
    $('.rounded').corner();
    $('#submitDiv').click(function() {
        var validate = FrontPage_Account_Validator(document.AccountForm)
        if (validate == true) {
            var loginName = $("#LoginName").val();
            var ok = Abacus_Store.myaccount.loginNameExists(loginName).value;
            if (ok == true) {
                $("#loginNameExists").show();
            }
            else {
                $("#loginNameExists").hide();
                $('#AccountForm').submit();
            }
        }
    });
    $('#logOut').bind("click", function() {
        document.location.href = 'signout.aspx';
    });
	
	$('#printerBrandWrapper').bind('click', function(){
		$('#listBrandMenu').slideDown("slow");
	});
	
	$('#printerBrandWrapper').bind('mouseleave', function(){
		$('#listBrandMenu').slideUp("slow");
	});

	
})

/** End of My Account **/