/** Autocomplete **/

//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.queryDelay = 0;
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("<span id='sitesearchshowall'>View all search results</span>");
	if(url == "None")
	{
		sMarkup = "No results found.";
		myAutoComp.setFooter("");
	}
	else
	{
		//sMarkup = "<a style='text-decoration:none;' href='" + url + "'>" + title + "</a>";
		//myAutoComp.setFooter("<a id='sitesearchshowall' style='text-decoration:none;' href='#'>To view all other search results, click on the GO button</a>");
		myAutoComp.setFooter("<a id='sitesearchshowall' style='text-decoration:none;' onClick='javascript:viewAll();' href='#'>View all other search results</a>");
		sMarkup = title;
	}
	//document.getElementById('loading-gif').style.visibility = 'hidden';
	$('#loading-gif').css('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. */
	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();
  //	 searchTerm = document.getElementById("SearchTerm").value;
  //	 searchTerm = searchTerm.replace(" ", "+");
  //	 location.href = 'http://www.abacus24-7.com/search.aspx?SearchTerm=' + searchTerm;
  //});
myAutoComp._updateValue = function() {
	return true;
}

function viewAll()
{
  searchTerm = document.getElementById("SearchTerm").value;
  //searchTerm = searchTerm.replace(" ", "+");
  searchTerm = searchTerm.replace(/ /g, "+");
  location.href = 'http://private.abacus24-7.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 **/


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='Abacus24-7 Printer Ink Cartridges & Electronic Accessories';
	var url='http://private.abacus24-7.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);
}

/** 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';
    });
})

/** End of My Account **/