﻿/// <reference path="~/js/jquery-1.2.6.intellisense.js" />

var cImg;
var intlint;

$(function() {
    var lnavpos = $('#lNavInd').position();
    if (lnavpos != undefined)
    {
        $('#lNavInd').css("top", (lnavpos.top - 17) + 'px');
        $('#lNavInd').css("visibility", "visible");
    } 
});

function keyP(evt)
{   
    var keyCode;
	
	if(window.event)
    {
        keyCode = evt.keyCode
    }
    else if(evt.which)
    {
        keyCode = evt.which
    }
	
	if(keyCode == 13)
	{
		var targ = '';
		if (evt.target) targ = evt.target;
	    else if (evt.srcElement) targ = evt.srcElement;
		
		if (targ.id.indexOf('SearchBox') > -1)
		{
		    cancelEvt(evt);
		    document.getElementById(srchBtn).click();
		}
		else if ((targ.id.indexOf('Finish') > -1)	
		    || (targ.id.indexOf('Start') > -1)	
		    || (targ.id.indexOf('Finish') > -1))
		{
		    cancelEvt(evt);
		    document.getElementById(goBtn).click();
		}
	}
}

function cancelEvt(evt)
{
    if (evt.preventDefault)
		{
			evt.preventDefault();
			evt.stopPropagation();
		} else {
			event.returnValue=false; 
			event.cancel = true;
		}
}

function mvCat(cid)
{
    window.location.href = '/maps.aspx' + cid;
}

function cartClick()
{
    $('#smCartContent').slideToggle('fast');
}

function updateShip(code,cost)
{
    if (code == 1) 
    {
        $('#ship_IN').hide();
        $('#ship_US').hide();
        $('#ship_CN').show();
    }
   $('#' + shiphf).val(code);
   $('#total').html('$' + (sub + cost).toFixed(2));
}

function intlShip()
{
    $('#ship_US').hide();
    $('#ship_CN').hide();
    $('#ship_IN').show();
    $('#' + shiphf).val('IN');
    $('#total').html('$' + (sub).toFixed(2));
}

function updateUSship()
{
    $('#ship_IN').hide();
    $('#ship_CN').hide();
    $('#ship_US').show();
    $("input[@name='shipOpt']:checked").click();
}

function toggleDiv(divToTog, val)
{
    if (val)
        $('#' + divToTog).slideDown('fast');
    else
        $('#' + divToTog).slideUp('fast');
}

function doZoomify()
{
    $('#zoomWindow').show();
}

function endZoomify()
{
    $('#zoomWindow').hide();
}

function addZoomify(path)
{
    document.writeln("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' width='792' height='573' id='Object3'>");
    document.writeln("<param name='FlashVars' value='zoomifyImagePath=http://media.maps.com/zoomify/" + path + "/&zoomifyX=0.0&zoomifyY=0.0&zoomifyZoom=-1&zoomifyToolbar=1&zoomifyNavWindow=1'>");
    document.writeln("<param name='src' value='/img/mapzoom.swf'>");
    document.writeln("<embed flashvars='zoomifyImagePath=http://media.maps.com/zoomify/" + path + "/&zoomifyX=0.0&zoomifyY=0.0&zoomifyZoom=-1&zoomifyToolbar=1&zoomifyNavWindow=1' src='/img/mapzoom.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' width='792' height='573' name='theMovie'>");
    document.writeln("</embed></object>");
}

function scI(obj, img)
{
    hcI();
    
    cImg = $('<div style="border: solid 1px black;"></div>').append($('<img src="http://media.maps.com/magellan/Images/' + img + '" width=100 />'));
    $(cImg).css({ position: 'absolute', left: '-100px', top: '0px' });
    $(obj).append(cImg);
    
}

function hcI()
{
    if (cImg) $(cImg).remove();
}

function oedit(off,on)
{
    $('#' + off + ',#' + off + 'Btn').fadeOut('fast',function(){
        $('#' + on + ',#' + on + 'Btn').fadeIn('fast');
    });
}

function doRR(snd, t, sku)
{
    var obj = new Object();
    obj.t = t;
    obj.sku = sku;
    
    $.get('/Rails.ashx',obj,function (data) {
        $('#rrHolder').html(data);
        $('#rrHolder').fadeIn('fast');
    });
}

function doMisfit(skustr)
{
    var data = '<table width="325" cellpadding="7" cellspacing="0" border="0">'
    + '<tr><td><h2>Maps.com Used Maps</h2></td><td valign="top" align="right"><a href="javascript:rrClose();"><img src="/img/org-close-btn.gif" border=0 alt="Close" /></a></td></tr>'
	+'<tr><td colspan="2">'
	+'Used maps are maps that are in less than perfect condition due to some flaw or damage. Typically the damage or flaw is found in the borders of the map, which can easily be trimmed to improve the overall condition of the product. In some cases there are wrinkles, creases, small tears or subtle fold lines. Sometimes the map is slightly smaller than the stated dimensions, due to trimming. Used maps are still usable and in many cases the damage is barely noticeable. They are great for framing, art projects, kids’ rooms, home offices, classrooms, playrooms and more.'
	+'<br/><br/>'
	+'<b>USED MAPS ARE:</b>'
	+'<ul>'
	+'<li>sold "As is"</li>'
	+'<li>Non-returnable/Non-refundable</li>'
	+'<li>Aggressively Discounted due to damage</li>'
	+'</ul>'
	+ "</td></tr>"
	+ skustr
	+'</table>';
	
	$('#rrHolder').html(data);
    $('#rrHolder').fadeIn('fast');
}

function doShipCountries()
{
    var data = '<table width="325" cellpadding="7" cellspacing="0" border="0">'
    + '<tr><td><h2>Countries Shipped To</h2></td><td valign="top" align="right"><a href="javascript:shipClose();"><img src="/img/org-close-btn.gif" border=0 alt="Close" /></a></td></tr>'
	+'<tr><td colspan="2">'
	+'AD > Andorra<br>'
	+'AT > Austria<br>'
	+'BE > Belgium<br>'
	+'CZ > Czech Republic<br>'
	+'DK > Denmark<br>'
	+'DO > Dominican Republic<br>'
	+'FI > Finland<br>'
	+'FR > France<br>'
	+'DE > Germany<br>'
	+'GR > Greece<br>'
	+'HK > Hong Kong<br>'
	+'HU > Hungary<br>'
	+'IE > Ireland<br>'
	+'IT > Italy<br>'
	+'JP > Japan<br>'
	+'LI > Liechtenstein<br>'
	+'LU > Luxembourg<br>'
	+'MY > Malaysia<br>'
	+'MC > Monaco<br>'
	+'NL > Netherlands<br>'
	+'NO > Norway<br>'
	+'PH > Philippines<br>'
	+'PL > Poland<br>'
	+'SG > Singapore<br>'
	+'KS > South Korea<br>'
	+'ES > Spain<br>'
	+'TW > Taiwan<br>'
	+'SE > Sweden<br>'
	+'CH > Switzerland<br>'
	+'GB > United Kingdom<br>'
	+'VA > Vatican City State<br>'
	+ "</td></tr>"
	+'</table>';
	
	$('#shipHolder').html(data);
    $('#shipHolder').fadeIn('fast');
}
function doShipCountries2()
{
    var data = '<table width="325" cellpadding="7" cellspacing="0" border="0">'
    + '<tr><td><h2>Countries Shipped To</h2></td><td valign="top" align="right"><a href="javascript:shipClose2();"><img src="/img/org-close-btn.gif" border=0 alt="Close" /></a></td></tr>'
	+'<tr><td colspan="2">'
	+'AD > Andorra<br>'
	+'AT > Austria<br>'
	+'BE > Belgium<br>'
	+'CZ > Czech Republic<br>'
	+'DK > Denmark<br>'
	+'DO > Dominican Republic<br>'
	+'FI > Finland<br>'
	+'FR > France<br>'
	+'DE > Germany<br>'
	+'GR > Greece<br>'
	+'HK > Hong Kong<br>'
	+'HU > Hungary<br>'
	+'IE > Ireland<br>'
	+'IT > Italy<br>'
	+'JP > Japan<br>'
	+'LI > Liechtenstein<br>'
	+'LU > Luxembourg<br>'
	+'MY > Malaysia<br>'
	+'MC > Monaco<br>'
	+'NL > Netherlands<br>'
	+'NO > Norway<br>'
	+'PH > Philippines<br>'
	+'PL > Poland<br>'
	+'SG > Singapore<br>'
	+'KS > South Korea<br>'
	+'ES > Spain<br>'
	+'TW > Taiwan<br>'
	+'SE > Sweden<br>'
	+'CH > Switzerland<br>'
	+'GB > United Kingdom<br>'
	+'VA > Vatican City State<br>'
	+ "</td></tr>"
	+'</table>';
	
	$('#shipHolder2').html(data);
    $('#shipHolder2').fadeIn('fast');
}
function shipClose()
{
    $('#shipHolder').fadeOut('fast');
}
function shipClose2()
{
    $('#shipHolder2').fadeOut('fast');
}

function rrClose()
{
    $('#rrHolder').fadeOut('fast');
}

function hpt(tab)
{
    $('#hpt1,#hpt2').hide();
    $('#hpt' + tab).show();
    if (tab == 1)
    {
        $('.hpb2on').removeClass('hpb2on');
        $('.hpb1').addClass('hpb1on');
    } else {
        $('.hpb1on').removeClass('hpb1on');
        $('.hpb2').addClass('hpb2on');
    }
    
}

function doMoreView(pid)
{
    window.open('/moreViews.aspx?pid=' + pid, 'MoreViews', 'width=450,height=450,resizable=yes');
}

function shipChg()
{
    $('#rrHolder').fadeIn('fast');
}

function navOvr(obj)
{
    if (obj.style.filter)
    {
        var orig = obj.style.filter;
        orig = orig.substr(orig.indexOf('maps.com')+8);
        orig = orig.substr(0,orig.indexOf('",'));        
        obj.orig = 'url(' + orig + ')';
    }
    else    
        obj.orig = obj.style.backgroundImage;
    obj.style.backgroundImage = 'url(/img/leftNav_ovr.png)';
    if (obj.className == 'lNavBtn1')
        obj.getElementsByTagName('a')[0].style.color = '#ffffff'; 
}

function navOut(obj)
{
    obj.style.backgroundImage = obj.orig;
    if (obj.className == 'lNavBtn1')
        obj.getElementsByTagName('a')[0].style.color = '#0B3543';
}

function topOvr(obj)
{
    if (obj.style.filter)
    {
        var orig = obj.style.filter;
        orig = orig.substr(orig.indexOf('maps.com')+8);
        orig = orig.substr(0,orig.indexOf('",'));        
        obj.orig = 'url(' + orig + ')';
    }
    else    
        obj.orig = obj.style.backgroundImage;
    obj.style.backgroundImage = 'url(/img/topNav_ovr.png)';
    obj.getElementsByTagName('a')[0].style.color = '#ffffff'; 
}

function topOut(obj)
{
    obj.style.backgroundImage = obj.orig;
    obj.getElementsByTagName('a')[0].style.color = '#0B3543'; 
}

(function ($) {

$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';
    
    return this.each(function () {
        var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

        function remove() {
            if (this.value === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) { 
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if ((this.value === '') || (this.valueOf == 'Address, City, State, and/or ZIP')) {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title
            
            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);

function capWords(element) {
var inputString = document.getElementById(element); // The input text field
var outputString = document.getElementById(element); // The output text field
var tmpStr, tmpChar, preString, postString, strlen;
//tmpStr = inputString.value.toLowerCase();
tmpStr = inputString.value;
stringLen = tmpStr.length;
if (stringLen > 0)
{
  for (i = 0; i < stringLen; i++)
  {
    if (i == 0)
	{
      tmpChar = tmpStr.substring(0,1).toUpperCase();
      postString = tmpStr.substring(1,stringLen);
      tmpStr = tmpChar + postString;
    }
    else
	{
      tmpChar = tmpStr.substring(i,i+1);
      if (tmpChar == " " && i < (stringLen-1))
	  {
      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
      preString = tmpStr.substring(0,i+1);
      postString = tmpStr.substring(i+2,stringLen);
      tmpStr = preString + tmpChar + postString;
      }
    }
  }
}
outputString.value = tmpStr;
}

function doPlz(skuid)
{
    var msg = $(msgBox).val();
    if (msg == '')
    {
        alert('You must enter a personalization message to purchase this product.');
        return;
    }
    
    if (confirm('Are you sure you wish "' + msg + '" to be the message shown on your map?\nYou will not be able to change this later.'))
    {
        location.href = '/CartAdder.ashx?id=' + skuid + '&msg=' + escape(msg);
    } else
    {
        return false;
    }
    
}

function intlBox(box, img)
{
    $('#intlBox').empty();        
    $('#intlBox').append('<div style="position: absolute; height: 25px; top:0px; width: 522px; cursor: pointer;" onclick="$(\'#intlBox\').hide();"><img src="/img/x.gif" width="522" height="25" /></div><a href="/tracking.aspx"><img src="/img/' + img + '" /></a>');
    //$('#intlBox').css('left',($(box).offset().left - 150));    
    $('#intlBox').show();
   
}

function intlDone()
{

    clearTimeout(intlint);
/*    
    intlint = setTimeout(function () {
        $('#intlBox').fadeOut();
    }, 3000);    
    */
}