var dom = (document.getElementById) ? true : false;
var moz = (dom && (navigator.appName=="Netscape")) ? true : false;

// Mozilla
function moveHintsN(e)
{
	xoff = window.pageXOffset + e.clientX + 10;
	document.getElementById('hints').style.left = xoff + "px";
	document.getElementById('hints').style.top = window.pageYOffset + e.clientY + 10 + "px";
	document.getElementById('hints').style.visibility = "visible";
}

function hideHintsN(e)
{
	document.onmousemove = null;
	document.onmouseout = null;
    document.getElementById('hints').style.visibility = "hidden";
}

// IE
function moveHints()
{
	if (moz) return;
    xoff = 0;
    yoff = 0;
	xoff += window.event.clientX + document.documentElement.scrollLeft + 10;
	yoff += window.event.clientY + document.documentElement.scrollTop + 10;
	document.getElementById('hints').style.left = xoff;
	document.getElementById('hints').style.top = yoff;
}

function hideHints()
{
	if (moz) return;
	document.getElementById('hints').style.visibility = "hidden";
}

function showHints(text)
{
	if (text == "") return;
	document.getElementById('hints').innerHTML = text;

	if (moz)
    { // for Mozilla
		document.onmousemove = moveHintsN;
		document.onmouseout = hideHintsN;
		return;
	}
    else
    { // for IE & Opera
		moveHints();
		document.getElementById('hints').style.visibility = "visible";
    }
}


//******************************************************************************

function initRollovers()
{
 if (!document.getElementById) return

 var aPreLoad = new Array();
 var sTempSrc;
 var aImages = document.getElementsByTagName('img');

 for (var i = 0; i < aImages.length; i++)
 {
  if (aImages[i].className == 'imgover')
  {
   var src = aImages[i].getAttribute('src');
   var ftype = src.substring(src.lastIndexOf('.'), src.length);
   var hsrc = src.replace(ftype, '_o'+ftype);

   aImages[i].setAttribute('hsrc', hsrc);

   aPreLoad[i] = new Image();
   aPreLoad[i].src = hsrc;

   aImages[i].onmouseover = function()
   {
    sTempSrc = this.getAttribute('src');
    this.setAttribute('src', this.getAttribute('hsrc'));
   }

   aImages[i].onmouseout = function()
   {
    if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
    this.setAttribute('src', sTempSrc);
   }
  }
 }
}

//******************************************************************************

var demoWin;
function DoWin(namehtm,wwin,hwin) {
  if ((demoWin != null) && (!demoWin.closed)){demoWin.close()}
  eval("demoWin=window.open('"+namehtm+"', 'demonstrationWin', 'width="+wwin+",height="+hwin+",location=0,top=0')");
  demoWin.focus();
}

//******************************************************************************

var demoWin2;
function DoWin2(wwin,hwin,imgnum) {
  if ((demoWin2 != null) && (!demoWin2.closed)){demoWin2.close()}
      eval("demoWin2=window.open('', 'demonstrationWin', 'width="+wwin+",height="+hwin+",location=0,top=0')");
  demoWin2.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
  demoWin2.document.writeln('    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  demoWin2.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">');
  demoWin2.document.writeln('<head>');
  demoWin2.document.writeln('  <title></title>');
  demoWin2.document.writeln('  <style type="text/css">');
  demoWin2.document.writeln('  /*<![CDATA[*/');
  demoWin2.document.writeln('    body  {margin: 0px; padding: 0px}');
  demoWin2.document.writeln('    img   {display: block; margin: 0px auto; padding: 0px; border: none}');
  demoWin2.document.writeln('  /*]]>*/');
  demoWin2.document.writeln('  </style>');
  demoWin2.document.writeln('</head>');
  demoWin2.document.writeln('<body>');
  demoWin2.document.writeln("  <a href=\"#\" onclick=\"self.close(); return false;\" title=\"Кликните для закрытия\"><img src=\"imgs/naruj-reklm/"+imgnum+".jpg\" alt=\"\" /></a>'");
  demoWin2.document.writeln('</body>');
  demoWin2.document.writeln('</html>');
  demoWin2.document.close()
  demoWin2.focus();
}

//******************************************************************************

function check_mail(mail_address)
{
  ParsePetrn = /[a-z_0-9\.]+[-]*[a-z_0-9\.]*[@][a-z_0-9\.]+[-]*[a-z_0-9\.]+[.]\w+[.]\w+|[a-z_0-9\.]+[-]*[a-z_0-9\.]*[@][a-z_0-9\.]+[-]*[a-z_0-9\.]+[.]\w+/i
  return ParsePetrn.test(mail_address);
}

function validForm(f)
{
  if (f.email.value == ""){
    alert("Please, enter your E-mail");
    f.email.focus();
    return false;
  }
  else if (!check_mail(f.email.value))
  {
    alert("Please, enter valid E-mail address");
    f.email.focus();
    return false;
  }

  else f.submit(); // Отправляем на сервер
}

//******************************************************************************

function hide_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        node.className=node.className.replace('showed', '');
        node.className += ' hidden';
    }
}

function show_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        node.className=node.className.replace('hidden', '');
        node.className += ' showed';
    }
}

function toggle_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        if (node.className.indexOf('hidden') != -1)
            node.className=node.className.replace('hidden', 'showed')
        else if (node.className.indexOf('showed') != -1)
            node.className=node.className.replace('showed', 'hidden')
        else node.className += ' showed';
     }
}
//======================= Gmap
function initialize() {
  var map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(39.9078, -74.9809), 15);

  var map = new GMap2(document.getElementById("map_canvas_Lodi"));
  map.setCenter(new GLatLng(40.8817, -74.0666), 16);
  
    var map = new GMap2(document.getElementById("map_canvas_NP"));
  map.setCenter(new GLatLng(40.6184, -74.4534), 16);

    var map = new GMap2(document.getElementById("map_canvas_SB"));
  map.setCenter(new GLatLng(40.3380, -74.0653), 16);


// =========== CH marker
var map = new GMap2(document.getElementById("map_canvas"));
var center = new GLatLng(39.9078, -74.9809);
map.setCenter(center, 15);


var marker = new GMarker(center, {draggable: false});

GEvent.addListener(marker, "dragstart", function() {
  map.closeInfoWindow();
  });

GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("<b>Kitchen & BathWorks-Cherry Hill <br /> Showroom</b> <br /><br /> 1641 Marlton Pike East (Route 70  East) <br /> Cherry Hill, NJ 08034");
  });

map.addOverlay(marker);
// ======== Lodi marker
var map = new GMap2(document.getElementById("map_canvas_Lodi"));
var center_lodi = new GLatLng(40.8817, -74.0666);
map.setCenter(center_lodi, 16);

var marker_lodi = new GMarker(center_lodi, {draggable: false});

GEvent.addListener(marker_lodi, "dragstart", function() {
  map.closeInfoWindow();
  });

GEvent.addListener(marker_lodi, "click", function() {
    marker_lodi.openInfoWindowHtml("<b>Kitchen & BathWorks-Lodi Showroom</b> &nbsp;&nbsp; <br /><br /> 41 Robinson Road <br /> Lodi, NJ 07644");
  });

map.addOverlay(marker_lodi);

// ======== North Plainfield marker
var map = new GMap2(document.getElementById("map_canvas_NP"));
var center_NP = new GLatLng(40.6184, -74.4534);
map.setCenter(center_NP, 16);

var marker_NP = new GMarker(center_NP, {draggable: false});

GEvent.addListener(marker_NP, "dragstart", function() {
  map.closeInfoWindow();
  });


GEvent.addListener(marker_NP, "click", function() {
    marker_NP.openInfoWindowHtml("<b>Kitchen & BathWorks-North Plainfield &nbsp;&nbsp; <br /> Showroom</b> <br /><br /> Route 22 West & West End Avenue <br /> North Plainfield, NJ 07061");
  });
map.addOverlay(marker_NP);

// ======== Shrewsbury marker
var map = new GMap2(document.getElementById("map_canvas_SB"));
var center_SB = new GLatLng(40.3380, -74.0653);
map.setCenter(center_SB, 16);

var marker_SB = new GMarker(center_SB, {draggable: false});

GEvent.addListener(marker_SB, "dragstart", function() {
  map.closeInfoWindow();
  });

GEvent.addListener(marker_SB, "click", function() {
    marker_SB.openInfoWindowHtml("<b>Kitchen & BathWorks-Shrewsbury &nbsp;&nbsp; <br /> Showroom</b> <br /><br /> 47 Newman Springs Road <br /> Shrewsbury, NJ 07702");
  });

map.addOverlay(marker_SB);
}
$(document).click(function(e){
    if ($(e.target).parents().filter('#landing-popup:visible').length != 1) {
        $('#landing-popup').fadeOut();
    }
});
$(function() {
    $("#btn_close").click(function(){
      $('#landing-popup').fadeOut();
      return false;
  })
})



