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';
     }
}

function setPrintCSS(isPrint) {
// By Akella cssing.org.ua
// ���������� ��������� ������� ��� �������� � ���������
  if (document.getElementsByTagName)
      x = document.getElementsByTagName('link');
  else
  {
      alert('sorry this function is not work in your browser');
      return;
  }
// �������� �� ���� ��������� LINK � HTML  - �������� � ��������� ������ ��� �����
// ������������� �� �� �������� title
// �������� isPrint - �������� ������ �� ������� ������ ��� ����� ��� ��������
  for (var i=0;i<x.length;i++) {
      if(x[i].title == 'printview'){x[i].disabled = !isPrint;}
      if(x[i].title == 'screenview'){x[i].disabled = isPrint;}
  }
}

/* validate contact form*/

function validForm(f)
{
  var err="";
  if (f.name.value == ""){
    err = err + "<li>Name</li>";
  }
  if (f.email.value == ""){
    err = err + "<li>Email</li>";
  }
  if (f.company.value == ""){
    err = err + "<li>Company</li>";
  }

  if (f.message.value == ""){
    err = err + "<li>Your message</li>";
  }

  if (err.length > 0) {
    err = "<h3>Please enter:</h3><ul>" + err + "</ul>";
    document.getElementById('fill_form').innerHTML=err;
    document.getElementById('fill_form').style.display="block";
    return false;
  }
  else f.submit();
}


/* validate contact form*/

function validFormAff(f)
{
  var err="";
  if (f.name.value == ""){
    err = err + "<li>Name</li>";
  }

  if (f.company.value == ""){
    err = err + "<li>Company</li>";
  }
  if (f.email.value == ""){
    err = err + "<li>Email</li>";
  }
    if (f.cemail.value == ""){
    err = err + "<li>Confirm Email</li>";
  }



  if (err.length > 0) {
    err = "<h3>Please enter:</h3><ul>" + err + "</ul>";
    document.getElementById('fill_form').innerHTML=err;
    document.getElementById('fill_form').style.display="block";
    return false;
  }
  else f.submit();
}


/* validate login form*/

function validFormLogin(f)
{
  var err="";
  if (f.email.value == ""){
    err = err + "<li>Email</li>";
  }
  if (f.password.value == ""){
    err = err + "<li>Password</li>";
  }

  if (err.length > 0) {
    err = "<h3>Please enter:</h3><ul>" + err + "</ul>";
    document.getElementById('fill_form').innerHTML=err;
    document.getElementById('fill_form').style.display="block";
    return false;
  }
  else f.submit();
}

/* validate win form*/

function checkEmail(e)
{
 ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

 for(i=0; i < e.length ;i++)
  if(ok.indexOf(e.charAt(i))<0)
   return (false);

 if (document.images)
 {
  re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
  re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  if (!e.match(re) && e.match(re_two))
   return true;
  else
   return false;

 }
 return true;

}


function validFormWin(f)
{
  var err="";
  if (f.name.value == ""){
    err = err + "<li>Name</li>";
  }

  if (f.company.value == ""){
    err = err + "<li>Company Name</li>";
  }
// if (f.email.value == ""){
//    err = err + "<li>Email</li>";
// }
//  
//    if ((f.email.value != '') || (!check_mail(f.email.value))){
//    err = err + "<li>correct email</li>";
//  }
  
if (document.getElementById('email').value == '')
 {
  err = err + "<li>Email</li>";
  }

  if (document.getElementById('email').value != '')
 {
  if (!checkEmail(document.getElementById('email').value))
  {
  err = err + "<li>Please use email format, for example: user@domain.com</li>";
  }
 }

if (document.getElementById('cemail').value == '')
 {
    err = err + "<li>Confirm Email</li>";
  }

if (document.getElementById('email').value != '' && document.getElementById('cemail').value != '')
 {
  if (document.getElementById('email').value != document.getElementById('cemail').value)
  {
	      err = err + "<li>Email's does not match</li>";
  }

}


  if (err.length > 0) {
    err = "<h3>Please enter:</h3><ul>" + err + "</ul>";
    document.getElementById('fill_form').innerHTML=err;
    document.getElementById('fill_form').style.display="block";
    return false;
  }
  else f.submit();
}

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 closeTerms(){document.getElementById('terms').style.visibility = "hidden";}
function showTerms() {document.getElementById('terms').style.visibility = "visible";}
/*

function showCVV {
   document.getElementById('CVV').style.display = "block";
}

function closeCVV {
   document.getElementById('CVV').style.display = "none";
}
 */

 /*scroll*/
/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.

   sil, http://www.kryogenix.org/

   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) &&
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) &&
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }

    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;

    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;

    // Find the destination's position
    var destx = destinationLink.offsetLeft;
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent &&
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }

    // Stop any current scrolling
    clearInterval(ss.INTERVAL);

    cypos = ss.getCurrentYPos();

    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);

    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  }
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);


/*--------------
take tour block
--------------*/

function requestContent(contentName, callback)
{
	$.ajax({
		type: 'POST',
		url: '/content.php?url='+contentName,
		success: callback,
	});
}

function doRequestContent(contentName, sectionId)
{
	sectionId = sectionId ? sectionId : contentName;
         $('#promo_header').animate({opacity: "0"}, "slow");
		 $('#promo_header').css("display","none");
         $('#take-tour-block').attr("class","visible");
		 var maxl = 1025;
		if ( document.body.offsetWidth < maxl) {$('a.btn_shares').animate({opacity: "0"}, "1")};
	requestContent(
		contentName,
		function(html)
		{

			$('#take-tour-block').html(html);
		}
	);
}

function doRequestContentInner(contentName, sectionId)
{
	sectionId = sectionId ? sectionId : contentName;
         $('#promo_header').animate({opacity: "0"}, "slow");
		 $('#promo_header').css("display","none");
         $('body').addClass("tour");
         $('#take-tour-block').attr("class","visible");
		 $('html, body').animate({scrollTop:0}, 'slow');
	requestContent(
		contentName,
		function(html)
		{

			$('#take-tour-block').html(html);
		}
	);
}

/* *********************************
        ON LOAD
********************************* */
window.onload = function(){
lightgallery.init();

}

