
var aValue;
var nI = 0;
var aURLArguments = location.search.substring(1).split('&');
for (nI = 0; nI < aURLArguments.length; nI++) {
	aValue = aURLArguments[nI].split('=');
	if (aValue[0].toLowerCase() == 'srccode') {
		document.cookie = 'srccode=' + escape(aValue[1]) + ';domain=.bhphotovideo.com;expires=';
   	}
   	if (aValue[0].toLowerCase() == 'cpncode') {
		document.cookie = 'cpncode=' + escape(aValue[1]) + ';domain=.bhphotovideo.com;expires=';
    }
}

// Drop Down Navigation
function change(){
selected=document.dropdownnav.drop.selectedIndex;
loc=document.dropdownnav.drop[selected].value;
document.location=loc;
}

var compareSize = 0


function setCompareSize(size){
	compareSize = size;
}

function compareSubmit ()
{
    if  ( compareSize < 2 )
    {
        alert ( "Please check 2 or more items before hitting compare!" );
		return;
    }
    else
	{

 if( compareSize <=4)
 {
    if (screen.width<=800)
    {
      var cwidth=771 - (4-compareSize)*150+24
      var cheight=550
    }
    else
    {
      var cwidth=923 - (5-compareSize)*150+24
      var cheight=550
    }
}
else if(compareSize <=5)
{
    if (screen.width<=800)
    {
      var cwidth=771 - (4-compareSize)*150
      var cheight=550
    }
    else
    {
      var cwidth=923 - (5-compareSize)*150
      var cheight=550
    }
}
else
{
    if (screen.width<=800)
    {
      var cwidth=771
      var cheight=550

    }
    else
    {
      var cwidth=923
      var cheight=550
    }
}

var newWindow = window.open('','comparewindow','height='+cheight+',width='+cwidth+',directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no');
       		newWindow.focus();
	    newWindow.resizeTo(cwidth,cheight+30);
 document.comparisonForm.submit();
 }
}

function canCompare()
{
    if  ( compareSize < 2 )
    {
        alert ( "Please check 2 or more items before clicking compare! " );
        return false;
    }
    else

		if( compareSize <=4)
 {
    if (screen.width<=800)
    {
      var cwidth=771 - (4-compareSize)*150+24
      var cheight=550
    }
    else
    {
      var cwidth=923 - (5-compareSize)*150+24
      var cheight=550
    }
}
else if(compareSize <=5)
{
    if (screen.width<=800)
    {
      var cwidth=771 - (4-compareSize)*150
      var cheight=550
    }
    else
    {
      var cwidth=923 - (5-compareSize)*150
      var cheight=550
    }
}
else
{
    if (screen.width<=800)
    {
      var cwidth=771
      var cheight=550

    }
    else
    {
      var cwidth=923
      var cheight=550
    }
}
		var newWindow = window.open('','comparewindow','height='+cheight+',width='+cwidth+',directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no');
       		newWindow.focus();
	    newWindow.resizeTo(cwidth,cheight+30);
		return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//Function called when clicking on close window in holiday closing popup. Hides the layer that the page is being called into.

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}


/*var cur_lyrPromotion;
function PromotionLayers(id) {
  if (cur_lyrPromotion) hidePromotionLayer(cur_lyrPromotion);
  showPromotionLayer(id);
  cur_lyrPromotion = id;
}

function showPromotionLayer(id) {
  var lyrPromotion = getElemRefsPromotion(id);
  if (lyrPromotion && lyrPromotion.css) lyrPromotion.css.display = "block";
}

function hidePromotionLayer(id) {
  var lyrPromotion = getElemRefsPromotion(id);
  if (lyrPromotion && lyrPromotion.css) lyrPromotion.css.display = "none";
}

function getElemRefsPromotion(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}
*/



function changeOtherQuantityBox(q)
{
	if( q.id.indexOf('layer') != -1 )
		getElementRefs(q.id.substring( 'layer'.length ) ).value = q.value;
	else
	    getElementRefs('layer' + q.id).value = q.value;
}

var notesArray = [];
function isNotTheFirstTime(id) {
    for( i=0; i <= notesArray.length; i++ ) {
		if( notesArray[i] == id )
		    return true;
	}
	return false;
}

var mouseX = ""
var mouseY = ""
var iReturnValue =""

function popLayersSalesComment(id,type)
{
	if( type == 'addtocart' && isNotTheFirstTime(id) )
		 return true;
	else if ( !isNotTheFirstTime(id) )
		notesArray[notesArray.length]=id;

    showLayerSalesComment(id);
	return false;
}

/*function movelayer(event) {
		//alert(document.body.scrollTop)
		mouseX = event.screenY
		mouseY = event.screenX
		
	}*/

function getY( oElement )
{
iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;

}
return iReturnValue;
}



function showLayerSalesComment(id) {
	var lyrSalesComment = getElemRefs(id);
		if(id=="map7"){
			 // document.getElementById(id).style.left = 79 + "%"
			 document.getElementById(id).style.left = 50 + "%";
			 document.getElementById(id).style.marginLeft = 298 + "px"
		}else{
            document.getElementById(id).style.left = 50 + "%"
		}
			//document.getElementById(id).style.top = (iReturnValue-25) + "px"
			if (lyrSalesComment && lyrSalesComment.css)  lyrSalesComment.css.display = "block";
  
}


function hideLayerSalesComment(id) {
  var lyrSalesComment = getElemRefs(id);
  if (lyrSalesComment && lyrSalesComment.css) lyrSalesComment.css.display = "none";
}


function submitAddToCart(id) {
    document.getElementById(id).submit();
}

function addToCompare ( categoryId, theElement )
{
	var array = theElement.name.split("_");
	sku = array[1];
	itemSource = array[2];

	if ( theElement.checked )
	{
		if ( compareSize < 20 )
		{
			DWRHelper.addToComparisonChart( categoryId, sku, itemSource );
		    compareSize++;
		}
		else
		{
		    theElement.checked = false;
		    alert ( "Sorry you can only compare up to 20 items " );
		}
	}
	else
	{
		 DWRHelper.removeFromComparisonChart( categoryId, sku, itemSource );
	     compareSize--;
	}
}

$(document).ready(function(){

	$(".map9").mouseover(function () {
		$(this).parent("span").siblings("div:map9n7").show();
    });

	$(".map9").mouseout(function(){
		$(this).parent("span").siblings("div:map9n7").hide();
	});
	
	
	$('#InstantRebateList').bhLayer({
		openerSelector: false,
		closerSelector: "#cannon-layer-close",
		modal: {center: true, overlayStyle:{zIndex : 8000}, moveToBottom: true}
	}).css({zIndex:'9900'});
	$('.doubleRebate').click(function(e){
		$('#InstantRebateList').bhLayer("show");
									  e.stopPropagation();
	});
	 $(".viewRebateItems").hover(
     
	 function () {
        $(this).attr('src','/images/cannon-rebate-viewListingHover.jpg');
      }, 
      function () {
        $(this).attr('src','/images/cannon-rebate-viewListing.jpg');
      }
    );


});
