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';
     }
}
// Modal windows

function show_contact() {
	document.getElementById('contact_window').style.display = "block";
}
function close_contact() {
	document.getElementById('contact_window').style.display = "none"
}

function show_login() {
	document.getElementById('login_window').style.display = "block"
}
function close_login() {
	document.getElementById('login_window').style.display = "none"
}

/* validate form */
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 validFormRegister(f)
{
  var err="";
  if (f.name.value == ""){
    err = err + "<li>First Name</li>";
  }
  if ((f.email.value == "") || (!check_mail(f.email.value))){
    err = err + "<li>Valid E-mail address</li>";
  }
  if (f.cemail.value == ""){
    err = err + "<li>Confirm E-mail address</li>";
  }

  if (f.email.value != f.cemail.value){
    err = err + "<li>Emails don't match.</li>";
  }
  if (f.pass.value == ""){
    err = err + "<li>Password</li>";
  }
  if (f.c_pass.value == ""){
    err = err + "<li>Confirm Password</li>";
  }
  if (f.pass.value != f.c_pass.value){
    err = err + "<li>Passwords don't 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();
}

function validFormRegister2(f)
{
  var err="";
  if (f.r_url.value == "http://"){
    err = err + "<li>Website URL</li>";
  }

  if (f.r_details.value == ""){
    err = err + "<li>Task Details</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();
}
