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';
     }
}

/*************************************************************************/


/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function nice()
{
	var forms = getElementsByClassName("flashcardform", "form", document.getElementById("content"));

    for (var k=0; k<forms.length; k++)
    {
    	var checks = forms[k].getElementsByTagName('label');
    	var checksLnt = checks.length;

    	for(var i=0; i<checksLnt; i++)
    	{
    		var curr = checks[i];

    		var box = curr.firstChild;
    			box.className = 'lost';

    		curr.className += box.type;
    		curr.className += (box.checked) ? '-on' : '-off';

    		box.onclick = function()
    		{
    			var label = this.parentNode;

    			if(this.type == 'checkbox')
    			{
    				label.className = (label.className.indexOf('-on')+1) ? label.className.replace('-on','-off') : label.className.replace('-off','-on');
    			}

    			if(this.type == 'radio')
    			{
    				var siblings = label.parentNode.parentNode.getElementsByTagName('input');
    				var siblingsLnt = siblings.length;

    				for(var j=0; j<siblingsLnt; j++)
    				{
    					if(siblings[j].name == this.name) {
    						var check = siblings[j].parentNode;
    						check.className = check.className.replace('-on','-off');
    					}
    				}

    				label.className = label.className.replace('-off','-on');
    			}
    		}
    	}

    }
}

//////////////// show promo

function show_promo(nodeId)
{
    document.getElementById('promo_info_1').style.display='none';
    document.getElementById('promo_info_2').style.display='none';
    document.getElementById('promo_info_3').style.display='none';
    document.getElementById('promo_info_4').style.display='none';
    document.getElementById('promo_info_5').style.display='none';


    document.getElementById('promo_info_'+nodeId).style.display='block';
}
function show_promo2(nodeId)
{
    document.getElementById('promo_info_6').style.display='none';
    document.getElementById('promo_info_7').style.display='none';
    document.getElementById('promo_info_8').style.display='none';
    document.getElementById('promo_info_9').style.display='none';
    document.getElementById('promo_info_10').style.display='none';

    document.getElementById('promo_info_'+nodeId).style.display='block';
}

function show_promo3(nodeId)
{
    document.getElementById('promo_info_11').style.display='none';
    document.getElementById('promo_info_12').style.display='none';
    document.getElementById('promo_info_13').style.display='none';
    document.getElementById('promo_info_14').style.display='none';
    document.getElementById('promo_info_15').style.display='none';

    document.getElementById('promo_info_'+nodeId).style.display='block';
}
function show_promo4(nodeId)
{
    document.getElementById('promo_info_16').style.display='none';
    document.getElementById('promo_info_17').style.display='none';
    document.getElementById('promo_info_18').style.display='none';
    document.getElementById('promo_info_19').style.display='none';

    document.getElementById('promo_info_'+nodeId).style.display='block';
}


//////////////// Valid Form Contact Us

function valid_fields(){

  if (document.getElementById("first_name").value == ""){
    document.getElementById("first_name").focus();
    alert ("Please Input Your First Name");
    return false;
  }

  if (document.getElementById("last_name").value == ""){
    document.getElementById("last_name").focus();
    alert ("Please Input Your Last Name");
    return false;
  }

  if (document.getElementById("address").value == ""){
    document.getElementById("address").focus();
    alert ("Please Input Your Address");
    return false;
  }

  if (document.getElementById("city").value == ""){
    document.getElementById("city").focus();
    alert ("Please Input Your City");
    return false;
  }

  if (document.getElementById("zip").value == ""){
    document.getElementById("zip").focus();
    alert ("Please Input Your Zip");
    return false;
  }

  if (document.getElementById("phone").value == ""){
    document.getElementById("phone").focus();
    alert ("Please Input Your Phone");
    return false;
  }

  if (document.getElementById("country").value == ""){
    document.getElementById("country").focus();
    alert ("Please Input Your Country");
    return false;
  }

  if (document.getElementById("email").value == ""){
    document.getElementById("email").focus();
    alert ("Please Input Your E-mail");
    return false;
  }

  if (document.getElementById("your_comment").value == ""){
    document.getElementById("your_comment").focus();
    alert ("Please Input Your Comment");
    return false;
  }

  if (document.getElementById("capture_inp").value == ""){
    document.getElementById("capture_inp").focus();
    alert ("Please Input Capture");
    return false;
  }

  document.getElementById("contact_us").submit();

}