//productForm

//introduced.select.onchange=function(){alert();};
jQuery(document).ready(function () {
    attach_selection_handlers();
    
});


function attach_selection_handlers() {
    if($('input[name=id]').val() == 6111 || $('input[name=id]').val() == 6196) {
        return;
    }
    
    
    // tag all of the items
    $('select option').each(function() {
        var text = $(this).text().toLowerCase();

        if(text.indexOf('xxl') >= 0 || text.indexOf('xxxl') >= 0) {
            $(this).attr('name', 'size');
        }
        if(text.indexOf('white') >= 0) {
            $(this).attr('name', 'color');
        }
    });

    $('select').change(function() {
        // if the item contains white then disable M,2XL, and 3XL
        var color = 0;
        var size = 0;
        
        $('select option:selected').each(function() {
            var text = $(this).text().toLowerCase();

            if(text.indexOf('xxl') >= 0 || text.indexOf('xxxl') >= 0) {
                size = 1;
            }
            
            if(text.indexOf('white') >= 0) {
                color = 1;
            }
            
        });
        
        if(size) {
            $('option[name=color]').attr('disabled', 'true');
        } else {
            $('option[name=color]').removeAttr('disabled');   
        }
        
        if(color) {
            $('option[name=size]').attr('disabled', 'true');
        } else {
            $('option[name=size]').removeAttr('disabled');   
        }        
    });
}


function switch_picture(new_image) {
	var img = document.getElementById('main_image');
	img.src=new_image;
}

function findY(obj)
{
  var curtop = 0;
  if(obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  }
  else if (obj.y) {
    curtop += obj.y;
	}
  return curtop;
}

function findX(obj)
{
  var curtop = 0;
  if(obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x) {
    curtop += obj.x;
	}
  return curtop;
}


function showHelp(anchor, box) {
    var obj = document.getElementById(box); 
    var obj2 = document.getElementById(anchor);
	var xMousePos;
	var yMousePos;

	yMousePos = findY(obj2);
	xMousePos = findX(obj2);
	obj.style.top = (yMousePos - 200) + 'px';
	obj.style.left = (xMousePos - 100) + 'px';
	obj.style.visibility='visible';
	obj.style.zIndex = 16;


	var els = document.productForm.elements; 

	for(i=0; i < els.length; i++){ 
		if (els[i].type == "select-one") {
				els[i].style.visibility = 'hidden';
		}
	}

	return false;
}

function checkAttributes(form)
{

var returnval = true;

var els = form.elements; 

	for(i=0; i < els.length; i++){ 
		if (els[i].type == "select-one") {
				if(els[i].options[els[i].selectedIndex].value == "-1") {

				//display pop up box informing of missing attribute
					document.getElementById('sizeRequiredBox').style.visibility='visible';

					returnval = false;	
				}

		}
	}
	if(returnval === true) {
		document.productForm.submit();
	}
return returnval;
}
function hideHelp(helpBox) {
	document.getElementById(helpBox).style.visibility='hidden';
	document.getElementById(helpBox).style.zIndex=-15;


	var els = document.productForm.elements; 

	for(i=0; i < els.length; i++){ 
		if (els[i].type == "select-one") {
				els[i].style.visibility = 'visible';
		}
	}


	return false;
}
