var __isClicked = false;

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';
     }
}


/* *********************************
        ON LOAD
********************************* */

window.onload = function()
{

}

function testOnLoad()
{
    document.getElementById('lastchild').style.backgroundPosition = '0 bottom';
}


/***** Select All *****/
function SelectAll(element, frm_name){

	element = document.getElementById(element);
	var section = document.getElementById(frm_name);
	for (var i = 0; i < section.childNodes.length; i++) {
		if(section.childNodes[i].type == 'checkbox'){
			if(section.childNodes[i].disabled == false){
				section.childNodes[i].checked = element.checked;				
			}
		}
	}

}

function switchSa(swId,sectionId){
	var section = document.getElementById(sectionId);
	var checkFlag = true;
	for (var i = 0; i < section.childNodes.length; i++) {
		if(section.childNodes[i].type == 'checkbox'){
			if(section.childNodes[i].checked == false){
				checkFlag = false;
			}
		}
	}
	document.getElementById(swId).checked = checkFlag;
}

function checkIsSelected(swId,sectionId){

	if (document.getElementById(swId))
	{
		document.getElementById(swId).onclick = function(){SelectAll(swId,sectionId);};
		var section = document.getElementById(sectionId);
		var checkFlag = true;
		for (var i = 0; i < section.childNodes.length; i++) {
			if(section.childNodes[i].type == 'checkbox'){
				section.childNodes[i].onclick = function(){switchSa(swId,sectionId);};
				if(section.childNodes[i].checked == false){
					checkFlag = false;
				}
			}
		}
	document.getElementById(swId).checked = checkFlag;	
	}
}

function viewMassgeStr(Str)
{
	alert(str);
	history.back();
}

/*B POPUP gallery*/
function show_photo_popup(the_img,img_title,is_default,id) {

	document.getElementById('photo_popup').style.display = "block";
	document.getElementById('users_photo').src = the_img;
	document.getElementById('id').value = id;
	if(document.getElementById('user_photo_title')){
		document.getElementById('user_photo_title').value = img_title;
	}
	if(document.getElementById('p_text_photo')){
		document.getElementById('p_text_photo').innerHTML = img_title;
	}
    window.scroll(0, 0);
}
function close_photo_popup() {
	document.getElementById('photo_popup').style.display = "none"
}
/*E POPUP gallery*/

/*** B POPUP popular kwinks ***/
function show_popular_kwinks(kwink_name,desc,id,is_change) {
    is_change = is_change || 0;
    document.getElementById('kwink_id').value = id;
    document.getElementById('your-kwink').value = id;
    document.getElementById('kwink_description').innerHTML = desc;
    document.getElementById('kwink_name').innerHTML = kwink_name;
	document.getElementById('popular_kwinks').style.display = "block";
	if(is_change==0)
	{
		//document.getElementById('change_kwink_btn').style.display = "none";
	   //document.getElementById('li_login_user').setAttribute("class", "only_close");
	}
	else
	{
		document.getElementById('change_kwink_btn').style.display = "block";
		//document.getElementById('change_kwink_btn').style.display = "none";
		document.getElementById('li_login_user').setAttribute("class", "");
	}
	document.getElementById('change_kwink_btn').style.display = "block";
    window.scroll(0, 0);
}
function show_popular_kwinks_user(kwink_name,desc,id,is_change) {
    is_change = is_change || 0;
    document.getElementById('kwink_id').value = id;
    document.getElementById('kwink_description_user').innerHTML = desc;
    document.getElementById('kwink_name_user').innerHTML = kwink_name;
	document.getElementById('popular_kwinks_user').style.display = "block";
	if(is_change==0)
	{
		//document.getElementById('change_kwink_btn').style.display = "none";
	   //document.getElementById('li_login_user').setAttribute("class", "only_close");
	}
	else
	{
		//document.getElementById('change_kwink_btn').style.display = "none";
		document.getElementById('li_login_user').setAttribute("class", "");
	}
    window.scroll(0, 0);
}
function close_popular_kwinks_user() {
	document.getElementById('popular_kwinks_user').style.display = "none";
}

function close_popular_kwinks() {
	document.getElementById('popular_kwinks').style.display = "none";
}
/*** E POPUP popular kwinks ***/


/*** B POPUP rate me ***/
function show_rate_me() {

	document.getElementById('rate_me').style.display = "block";
    window.scroll(0, 0);
}
function close_rate_me() {
	document.getElementById('rate_me').style.display = "none"
}
/*** E POPUP rate me ***/


lightgallery.init();

/*** S input[file] ***/
function replaceFile() {
	var _inputs = document.getElementsByTagName("input");
	for (var i= 0; i < _inputs.length; i++) {
		if(_inputs[i].className.indexOf("file-input-area") != -1) {
			var _file_input = _inputs[i];
			_file_input._fake_file_input = _inputs[i].parentNode.getElementsByTagName('input')[1];
			_file_input._fake_file_input.readOnly = true;
			_file_input.onkeypress = function() { this._fake_file_input.value = this.value;}
			_file_input.onchange = function() { this._fake_file_input.value = this.value;}
		}
	}
}
if (window.addEventListener){
	window.addEventListener("load", replaceFile, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", replaceFile);
}
/*** E input[file] ***/

function confirmHistoryBack(msg) {
	if (confirm(msg)) {
		history.back();
		return false;
	} else {
		return false;
	}
}


function formIsDirty(form)
{
    for (var i = 0; i < form.elements.length; i++)
    {
        var element = form.elements[i];
        var type = element.type;
        if (type == "checkbox" || type == "radio")
        {
            if (element.checked != element.defaultChecked)
            {
            	
                return true;
            }
        }
        else if (type == "hidden" || type == "password" || type == "text" ||
                 type == "textarea")
        {
            if (element.value != element.defaultValue)
            {
            	
                return true;
            }
        }
        else if (type == "select-one" || type == "select-multiple")
        {
            for (var j = 0; j < element.options.length; j++)
            {
                if (element.options[j].selected !=
                    element.options[j].defaultSelected)
                {
                    return true;
                }
            }
        }
    }
    return false;
}


