/*********************************************************************
* Copyright 2008 Amblique :: www.amblique.com :: All Rights Reserved *
**********************************************************************
* JAVASCRIPT AND OTHER SCRIPTING
*********************************************************************/

/**********************************
* jQuery scripts
**********************************/
// noConflict :: http://docs.jquery.com/Core/jQuery.noConflict
// jQuery.noConflict();
$(function() {
//	// IE PNG Fix :: http://www.campbellsdigitalsoup.co.uk/about/png-fix	
	$(document).pngFix();
	
	// PopupWindow :: http://plugins.jquery.com/project/PopupWindow
	var profiles = {
		popupToolsPrint:{height:500,width:780,center:1,scrollbars:1,status:0,resizable:1},
		popupToolsEmail:{height:400,width:500,center:1,scrollbars:1,status:0,resizable:1}
	};
	$(".tool").popupwindow(profiles);

	// jQuery Lightbox :: http://leandrovieira.com/projects/jquery/lightbox
	$('a[rel*=lightbox]').lightbox({
		overlayBgColor: '#FFF',
		overlayOpacity: 0.8,
		containerBorderSize: 10,
		containerResizeSpeed: 400,
		imageLoading: 'images/lightbox/loading.gif',
		imageBtnClose: 'images/lightbox/close.gif',
		imageBtnPrev: 'images/lightbox/prevlabel.gif',
		imageBtnNext: 'images/lightbox/nextlabel.gif'
   });

	// Your code goes here
	// $("table.table-mycart").empty();
	
	initialisePopups();
	
});

/**********************************
* Custom scripts
**********************************/

/***** Popup windows *****/
function PopUpSend(URL) {
	window.open(URL,"Send","height=400,width=500,scrollbars=yes,menubar=no,statusbar=no,personalbar=no,locationbar=no");
}
function PopUpPrint(URL) {
	window.open(URL,"Print","height=500,width=500,scrollbars=yes,menubar=no,statusbar=no,personalbar=no,locationbar=no"); 
}

/***** Google toolbar yellow fields Fix *****/
if(window.attachEvent)
window.attachEvent("onload",setListeners);

function setListeners(){
inputList = document.getElementsByTagName("INPUT");
for(i=0;i<inputList.length;i++){
	inputList[i].attachEvent("onpropertychange",restoreStyles);
	inputList[i].style.backgroundColor = "";
}
selectList = document.getElementsByTagName("SELECT");
	for(i=0;i<selectList.length;i++){
		selectList[i].attachEvent("onpropertychange",restoreStyles);
		selectList[i].style.backgroundColor = "";
	}
}
function restoreStyles(){
	if(event.srcElement.style.backgroundColor != "" && event.srcElement.style.backgroundColor != "#a0d0ff"){
		event.srcElement.style.backgroundColor = "#a0d0ff"; /* color of choice for AutoFill */
		document.all['googleblurb'].style.display = "block";
	}
}

/***** Clear Input Text *****/
function clearText(thefield, clearType){ 
	if (thefield.defaultValue==thefield.value) {
		thefield.value = ""
	}		
}


function registerNextTabControl(sSourceID, sTargetID)   {
    $('#'+sSourceID).keydown(function(e) {
        if (e.which == 9)   {
            e.preventDefault();
            $('#'+sTargetID).focus();
        }
    });
    
}

trace = function(message) {
    var page = window.location; var hasConsole = false;
    try { if (typeof (console) != "undefined") hasConsole = true; } catch (e) { }
    if (hasConsole) { console.log(message); }
}

///
/// var a = new Array();
/// a.indexOf('a', 1);
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, fromIndex) {
        if (fromIndex == null) {
            fromIndex = 0;
        } else if (fromIndex < 0) {
            fromIndex = Math.max(0, this.length + fromIndex);
        }
        for (var i = fromIndex, j = this.length; i < j; i++) {
            if (this[i] === obj) return i;
        }
        return -1;
    };
}

///
/// var string = "Hello {0}!".format('David');
if (!String.prototype.format) {
    String.prototype.format = function() {
        var pattern = /\{\d+\}/g;
        var args = arguments;
        return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
    };
}

///
/// var string = 'Hello   '.trim();
if (!String.prototype.trim) {
    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
}


/// to use this:
/// <a href="www.google.com" width="600" height="400" name="WishListPrint" status="0" toolbar="0" rel="popup">Hello</a>
initialisePopups = function() {
    $('a[rel=popup]').live('click', function(event) {
        var width = $(this).attr('width');
        var height = $(this).attr('height');
        var href = $(this).attr('href');
        var name = $(this).attr('name');
        var status = $(this).attr('status');
        var toolbar = $(this).attr('toolbar');
        
        if (width && height && href && name  && status  && toolbar) {
            window.open(href, name, 'height=' + height + ',width=' + width + ',status=' + status + ',toolbar=' + toolbar, false);
            return false;
        }
    });
};

function AddToCart(baseUrl, iProductID, iQty)	{
	GB_showCenter('', baseUrl +'additem.aspx?pkid='+ iProductID + '&qty=' + iQty, 450, 550);
}

function AddToCartCompleted()	{
	window.location.reload();
}

function closeGBWindowFromPopup(noRefresh)  {
    if (!noRefresh)  {
        top.location.href = top.location.href;
    }
    top.GB_hide();
}
