function addChecked(field)
{
	var total = 0;
	
	for (x = 0; x < field.length; x++){
		if (field[x].checked == true)
			total += 1;
	}
	
	if (total > 0)
	{
		document.catalog.submit();		
		
	}else {
	
		WriteLayer('error',null,'<font color="red"><strong>* Please select at least one item. *</strong></font>');
	}
}


function checkAll(field)
{
	var i; 
	
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
		
		showSelected(field);
}

function outfit(outfitID, picture, quote, outfitName){
    this.outfitID = outfitID;
    this.picture = picture;
    this.quote = quote;
    this.outfitName = outfitName;
}	
	
function list(howMany, initstr)
{	
	this.length = howMany;
	for (var i = 1; i<=howMany; i++)
	{
		this[i] = initstr;
	}
}

//
// initOutfit() - set up the page with the first look
//
function initOutfit()
{	
    var s = document.getElementById("oi"); // main state form
    //var gid = s.gid.value;
    var lookID = s.lookID.value;
    var outfit = s.outfit.value;
    var outfitNameSpan = document.getElementById("outfitName");
    var OIX = document.getElementById("outfitIx"); // the form field containing the currently displayed outfitID
    
	var rand =  Math.floor(Math.random()*1000000)
	
	var outfitIx = OIX.value; // the outfit index for this look, fka 'oNum'
	
    if (0 == outfitIx)
        outfitIx = 1;
        
    var url = "/ajax/outfits-image.ajax.asp?lookID=" + lookID + "&outfit="  + outfit + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('outfit').innerHTML = t.responseText; document.getElementById("outfitI").src = "http://www.ravinstyle.com/products/" + theOutfitsList[outfitIx].picture; updateNavButtons(outfitIx); outfitNameSpan.innerHTML = theOutfitsList[outfitIx].outfitName;}
    });    

	var x = 0;

	var outfitID = Number(s.outfitID.value);
		
	if (outfitID > 0) 
	{
	//	for (x = 1; x <= theOutfitsList.length;x++)
		for (x = 1; x <= theOutfitsList[0];x++) // theOutfitsList[0] contains # of outfits for this look
		{
			if (theOutfitsList[x].outfitID == outfitID)
				//oNum = x;	// reset outfitIndex	
				outfitIx = x;
				OIX.value = x; // save in form field			
		}
	}		

	document.getElementById('outfitIx').value = outfitIx; // update form field

    url="/ajax/quote.ajax.asp?q=" + escape(theOutfitsList[outfitIx].quote) + "&m=" + rand;

    ajax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: '',
                onComplete: function(t) { $('quote').innerHTML = t.responseText; }
        });
        
        
	// update catalog (products) div
 
    url="/ajax/catalog.ajax.asp?eCode=2&oid=" + theOutfitsList[outfitIx].outfitID + "&lookID=" + lookID + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('catalog_right').innerHTML = t.responseText; }
    });
}

function updateNavButtons(ix) { // takes the index of the outfits array

    var btnNext = document.getElementById("nextI");
    var btnPrev = document.getElementById("previousI");
   
    if (btnNext != null) {
	    if (ix >= theOutfitsList[0]){
		    btnNext.src = "http://www.ravinstyle.com/images/nextoutfit-w.gif";
	    }else {
		    btnNext.src = "/buttons08/NEXTOUTFITbutton.jpg";
	    }
	}
	
	if (btnPrev != null) { // if null, we can't update
	    if (1 == ix){
		    btnPrev.src = "http://www.ravinstyle.com/images/previousoutfit-w.gif";
	    }
	    else {
		    btnPrev.src = "/buttons08/PREVIOUSOUTFITbutton.jpg";
	    } 
	}
}

function gotoNextO(s)
{	
	var nextImage = document.getElementById("nextI");
	
	nextImage.blur();
	
	var outfitNameSpan = document.getElementById("outfitName");
	outfitNameSpan.innerHTML = "&nbsp;";
	
    var waiting_image = document.getElementById("ajax").innerHTML;
    
    var rand =  Math.floor(Math.random()*1000000)
    var s = document.getElementById("oi");
	
    ////////////////////////////////////////////////////////////////////////
    // new index  JAN08
    ////////////////////////////////////////////////////////////////////////
    var OIX = document.getElementById("outfitIx"); // the form field containing the currently displayed outfitID
    var outfitIx = Number(OIX.value);
  //  alert(outfitIx);
   if (outfitIx == theOutfitsList[0]) // we're already at the last outfit
        return;
    
    var OIX = document.getElementById("outfitIx"); // the form field containing the currently displayed outfitID
        
    document.getElementById("catalog_right").innerHTML = waiting_image;
    document.getElementById("quote").innerHTML = waiting_image;
        
	if (outfitIx < theOutfitsList[0]){
		outfitIx += 1; // increment outfit index
		// load new outfit pic
		document.getElementById("outfitI").src = "http://www.ravinstyle.com/products/" + theOutfitsList[outfitIx].picture;
		
		var rand =  Math.floor(Math.random()*1000000)
		
      //  var url = "/ajax/catalog.ajax.asp?eCode=2&oid=" + theOutfitsList[oNum].outfitID + "&lookID=" + s.lookID.value + "&oNum=" + oNum + "&m=" + rand;
        var url = "/ajax/catalog.ajax.asp?eCode=2&oid=" + theOutfitsList[outfitIx].outfitID + "&lookID=" + s.lookID.value + "&m=" + rand;

        ajax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: '',
                onComplete: function(t) { $('catalog_right').innerHTML = t.responseText; }
        });
		
        url = "/ajax/quote.ajax.asp?q=" + escape(theOutfitsList[outfitIx].quote) + "&m=" + rand;

        ajax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: '',
                onComplete: function(t) { $('quote').innerHTML = t.responseText;outfitNameSpan.innerHTML = theOutfitsList[outfitIx].outfitName; }
        });		
		
		
		//s.oNum.value = oNum;
		OIX.value = outfitIx; // save the new index
       // alert(s.oNum.value);
		if (outfitIx >= theOutfitsList[0]){
			nextImage.src = "http://www.ravinstyle.com/images/nextoutfit-w.gif";
		}else {
			nextImage.src = "/buttons08/NEXTOUTFITbutton.jpg";
		}
		if (1 == outfitIx){
			document.getElementById("previousI").src = "http://www.ravinstyle.com/images/previousoutfit-w.gif";
		}else {
			document.getElementById("previousI").src = "/buttons08/PREVIOUSOUTFITbutton.jpg";
		}

	}
	if('object' == typeof(s.blur))
		s.blur();
		
}
function gotoPreviousO(s)
{	    
    var rand =  Math.floor(Math.random()*1000000)
	var s = document.getElementById("oi");
	
	//var oNum = Number(s.oNum.value);
    ////////////////////////////////////////////////////////////////////////
    // new index  JAN08
    ////////////////////////////////////////////////////////////////////////
    var OIX = document.getElementById("outfitIx"); // the form field containing the currently displayed outfitID
    var outfitIx = Number(OIX.value);
	
	var outfitNameSpan = document.getElementById("outfitName");
	outfitNameSpan.innerHTML = "&nbsp;";
	var previousImage = document.getElementById("previousI");
	
	previousImage.blur();
	
	if (1 == outfitIx)
	    return;
	    
	var waiting_image = document.getElementById("ajax").innerHTML;
    
    document.getElementById("catalog_right").innerHTML = waiting_image;
    document.getElementById("quote").innerHTML = waiting_image;
    
	if (outfitIx > 1){
		outfitIx -= 1; // decrement the array index
		
        var url = "/ajax/catalog.ajax.asp?eCode=2&oid=" + theOutfitsList[outfitIx].outfitID + "&lookID=" + s.lookID.value + "&m=" + rand;
        
        ajax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: '',
                onComplete: function(t) { $('catalog_right').innerHTML = t.responseText; }
        });
		
        url = "/ajax/quote.ajax.asp?q=" + escape(theOutfitsList[outfitIx].quote) + "&m=" + rand;

        ajax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: '',
                onComplete: function(t) { $('quote').innerHTML = t.responseText; outfitNameSpan.innerHTML = theOutfitsList[outfitIx].outfitName; }
        });		
		
		document.getElementById("outfitI").src = "http://www.ravinstyle.com/products/" + theOutfitsList[outfitIx].picture;		
		
		OIX.value = outfitIx; // save the new index
	
		if (outfitIx >= theOutfitsList[0]){
			document.getElementById("nextI").src = "http://www.ravinstyle.com/images/nextoutfit-w.gif";
		}else {
			document.getElementById("nextI").src = "/buttons08/NEXTOUTFITbutton.jpg";
		}
		if (1 == outfitIx){
			previousImage.src = "http://www.ravinstyle.com/images/previousoutfit-w.gif";
		}else {
			previousImage.src = "/buttons08/PREVIOUSOUTFITbutton.jpg";
		}
	}
	if('object' == typeof(s.blur))
		s.blur();
}

function showDetail(productID) {
    var rand =  Math.floor(Math.random()*1000000)

    var url = "/ajax/productDetail.outfits.ajax.asp?productID="  + productID + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('outfit').innerHTML = t.responseText;}
    });
    
    
    url = "/ajax/quote.ajax.asp?productID="  + productID + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('quote').innerHTML = t.responseText;}
    });
}
///////////
function isNumber(theNumber) {
	//alert("s.name=" + s.name);
	var numCheckString = "0123456789";
	var i;
	for (i = 0; i < theNumber.length; i++)
	{
		if (numCheckString.indexOf(theNumber.charAt(i)) == -1) {
		return(false);
		}
	}
	return(true);
}

function show_large_image(pic, prod) {
	var eventWind =  window.open("show_large_image.asp?pic=" + pic + "&prod=" + prod,"small","HEIGHT=650,WIDTH=600,scrollbars=yes, resizable=yes, toolbar=no");
	if (eventWind.opener == null) eventWind.opener = self;
	eventWind.focus();
}

function addToWishListAJX(){
    var form = document.getElementById("productDetailForm");
    var productID = 0, colorID = 0, sizeID = 0, sid = 0, qty = 1, sale, price;
    
    if (form != null)
    {
        colorID = form.colorSelect[form.colorSelect.selectedIndex].value;
        sizeID = form.sizeSelect[form.sizeSelect.selectedIndex].value;
        productID = form.productID.value;
        sid = form.sid.value;
        qty = form.qty.value;
        sale = form.sale.value;
        price = form.price.value;
    }
    else {alert("can't find the form to add cart item."); return;}
        
    var rand =  Math.floor(Math.random()*1000000);
    
    var url = "/ajax/addWishList.ajax.asp?sid=" + sid + "&productID="  + productID + "&price="  + price + "&sale="  + sale + "&qty="  + qty + "&colorSelect=" + colorID + "&sizeSelect=" + sizeID + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('status').innerHTML = t.responseText;}
    });
}


