﻿/// <reference path="~/js/jquery-1.2.6.intellisense.js" />

var cImg;
var intlint;
var curPid = 0;
var curObj = null;

window.viewport =
{
    height: function() {
        return $(window).height();
    },

    width: function() {
        return $(window).width();
    },

    scrollTop: function() {
        return $(window).scrollTop();
    },

    scrollLeft: function() {
        return $(window).scrollLeft();
    }
};

$(document).ready(function() //neva
{        doRoll();}
);


$(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 doRoll() //neva
{
	$("img.rollover").hover(
	function()
		{
			this.src = this.src.replace("_off","_on");
		},
	function()
		{
			this.src = this.src.replace("_on","_off");
		}
		)
}

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='635' 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("<param name='bgcolor' value='#cae0f8'>");
    document.writeln("<embed bgcolor='#cae0f8' 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='635' 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 \n\n' + msg + '\n\n 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 doPlzAddr(skuid)
{
    var msg = $('#msgBox').val();
    if ((msg.indexOf('|') < 0) || (msg.length < 5))
    {
        alert('You must must provide a full address in order to purchase this product.');
        return;
    }

    var addr = msg.split('|');
    if (addr.length < 4) {
        alert('You must must provide a full address in order to purchase this product.');
        return;
    }

    if ((addr[0] == '') || (addr[1] == '') || (addr[2] == '') || (addr[3] == ''))
    {
        alert('You must must provide a full address in order to purchase this product.');
        return;
    }

    var clean = addr[0] + '\n' + addr[1] + ", " + addr[2] + " " + addr[3];

    if (confirm('Confirm that this is your correct address:\n\n' + clean + '\n\nYou will not be able to change this later.'))
        location.href = '/CartAdder.ashx?id=' + skuid + '&msg=' + escape(msg);
    else
        return false;
}

function doPlzYear(skuid)
{
    var msg = $('#msgBox').val();
    if (msg == '')
    {
        alert('You must enter a personalization message to purchase this product.');
        return;
    }

    var msgary = msg.split('|');
    if (msgary.length < 2) {
        alert('You must enter a personalization message to purchase this product.');
        return;
    }

    if (msgary[1] == '') {
        alert('You must enter a personalization message to purchase this product.');
        return;
    }
    
    if (confirm('Are you sure you wish "' + msgary[1] + '" for year ' + msgary[0] + ' to be the message shown on your puzzle?\nYou will not be able to change this later.'))
        location.href = '/CartAdder.ashx?id=' + skuid + '&msg=' + escape(msg);
    else
        return false;
}

function doPlzNYT(skuid)
{
    var msg = $('#msgBox').val();

    var date = msg.split('|');

    if (confirm('Are you sure you wish ' + date[0] + '/' + date[1] + '/' + date[2] + ' to be the front page date used for your puzzle?\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);    
    */
}

function moveQLbtn(pid) {
    if (($.browser.msie) && ($.browser.version == '6.0')) return;

    var obj = '#Pimg_' + pid;
    var x = $(obj).offset().left + $(obj).width() +2;
    var y = $(obj).offset().top + ($(obj).height() / 2) - 17;

    $('#qlBtn').css('top', y);
    $('#qlBtn').css('left', x);
    $('#qlBtn').show();
    curPid = pid;
    curObj = obj;
}

function doQL() {

    var y = viewport.scrollTop() + 200;
    var x = 100;
    if (viewport.width() > 1000) {
        x = ((viewport.width()-1000)/2) + x
    }
    $('#qlBtn').hide();
    $('#ql').hide();
    var url = '/QuickLook.ashx?pid=' + curPid + '&rurl=' + rUrl(curPid.toString());
    $('#qlCnt').html("<div style='text-align: center; padding-top: 150px;'><img src='/img/qlLoad.gif' /></div>");
    $('#qlCnt').load(url);

    $('#ql').css('top', y);
    $('#ql').css('left', x);
    $('#ql').fadeIn();
}

function QLC() {
    $('#ql').fadeOut('fast');
}

function moveQLbtn2(pid) {
    if (($.browser.msie) && ($.browser.version == '6.0')) return;

    var obj = '#Pimg_' + pid;
    var x = $(obj).offset().left + $(obj).width() +2;
    var y = $(obj).offset().top + ($(obj).height() / 2) - 17;

    $('#qlBtn2').css('top', y);
    $('#qlBtn2').css('left', x);
    $('#qlBtn2').show();
    curPid = pid;
    curObj = obj;
}

function doQL2() {

    var y = viewport.scrollTop() + 200;
    var x = 100;
    if (viewport.width() > 1000) {
        x = ((viewport.width()-1000)/2) + x
    }
    $('#qlBtn2').hide();
    $('#ql2').hide();

	$('#qlCnt2').hide();
	$('#qlCnt3').hide();
	$('#qlCnt4').hide();
    //var url = '/QuickLook2.ashx?pid=' + curPid + '&rurl=' + rUrl(curPid.toString());
	if (curPid == 11067) {
    $('#qlCnt2').show();
	} 
	if (curPid == 17260) {
    $('#qlCnt3').show();
	} 
	if (curPid == 526){
    $('#qlCnt4').show();
	}
	else { }
    $('#ql2').css('top', y);
    $('#ql2').css('left', x);
    $('#ql2').fadeIn();
}

function QLC2() {
    $('#ql2').fadeOut('fast');
}

function rUrl(pid) {
    var code = 0;    
    for (var i = 0; i < pid.length; i++) {
        var tmp = pid.charCodeAt(i);
        tmp = tmp * Math.abs(255 - tmp);
        code += tmp;
    }
    code = code % 1023;
    code = code + "";
    var tx = 4;
    var ts = code.split("");
    for (i = 0; i < tx - code.length; i++) {
        ts.unshift("0");
    }
    code = ts.join("");
    code = code.substring(0, tx / 2) + "M" + code.substring(tx / 2, tx);
    return code;
}
