﻿//------------------- Form Validation -------------------//
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
  var a=arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];dv = o.defaultValue;
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if ((r&&v.length==0)||v==dv){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+=a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('Поля, обозначенные звездочкой *, обязательны для заполнения!\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}
var newWindow = null;


function formrule(field)
{
	if (field.defaultValue == field.value) field.value = "";
}
function formrule2(field) {
  if (field.value == "") {
    field.value = field.defaultValue;
  }
}
var newWindow = null;


function pageup(e)
{
	UAGENT = navigator.userAgent.toUpperCase();
	if (UAGENT.indexOf("MSIE") >=0) { posi = event.y; }
	else { posi = e.pageY; }
	moveObje(posi);
}

function moveObje(position)
{
	move = position / 15;
	point = parseInt(position - move);
	scrollTo(0,point);
	if (point > 0) { setTimeout("moveObje(point)",15); }
}


/***********************************************
* Floating image script- By Virtual_Max (http://www.geocities.com/siliconvalley/lakes/8620)
* Modified by Dynamic Drive for various improvements
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var vmin=2;
var vmax=3;
var vr=2;
var timer=0;

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function Chip(chipname,width,height){
 this.named=chipname;
 this.vx=vmin+vmax*Math.random();
 this.vy=vmin+vmax*Math.random();
 this.w=width+1.5;
 this.h=height;
 this.xx=0;
 this.yy=0;
 this.timer1=null;
}

function movechip(chipname){
if (document.getElementById){
eval("chip="+chipname);
   if (window.innerWidth || window.opera){
		 pageX=window.pageXOffset;
     pageW=window.innerWidth-99;
     pageY=window.pageYOffset;
     pageH=window.innerHeight-20;
    }
   else if (document.body){
		 pageX=iecompattest().scrollLeft;
     pageW=iecompattest().offsetWidth-99;
     pageY=iecompattest().scrollTop;
     pageH=iecompattest().offsetHeight-20;
    } 

   chip.xx=chip.xx+chip.vx;
   chip.yy=chip.yy+chip.vy;
   
   chip.vx+=vr*(Math.random()-0.5);
   chip.vy+=vr*(Math.random()-1.0);
   if(chip.vx>(vmax+vmin))  chip.vx=(vmax+vmin)*2-chip.vx;
   if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
   if(chip.vy>(vmax+vmin))  chip.vy=(vmax+vmin)*2-chip.vy;
   if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;

   if(chip.xx<=pageX){
			chip.xx=pageX;
      chip.vx=vmin+vmax*Math.random();
     }
   if(chip.xx>=pageX+pageW-chip.w){
			chip.xx=pageX+pageW-chip.w;
      chip.vx=-vmin-vmax*Math.random();
     }
   if(chip.yy<=pageY)
     {chip.yy=pageY;
      chip.vy=vmin+vmax*Math.random();
     }
   if(chip.yy>=pageY+pageH-chip.h)
     {chip.yy=pageY+pageH-chip.h;
      chip.vy=-vmin-vmax*Math.random();
     }

document.getElementById(chip.named).style.left=chip.xx+"px";
document.getElementById(chip.named).style.top=chip.yy+"px";


   chip.timer1=setTimeout("movechip('"+chip.named+"')",119);
  }
}


/*
Originally written by paul sowden <paul@idontsmoke.co.uk> | http://idontsmoke.co.uk
modified and localized by alexander shurkayev <alshur@narod.ru> | http://htmlcoder.visions.ru
images preview function added by anton shchors <anton.shchors@gmail.com> | http://www.nova-star.ru/
*/

tooltip = {
        attr_name: "tooltip", 
        blank_text: "(Откроется в новом окне!)", 
        newline_entity: "~", 
        max_width: 0, 
        delay: 600, 

        t: document.createElement("DIV"),
        c: null,
        g: false,

        m: function(e){
                if (tooltip.g){
                        oCanvas = document.getElementsByTagName(
                        (document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
                        )[0];
                        x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
                        y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
                        tooltip.a(x, y);
                }
        },

        d: function(){
                tooltip.t.setAttribute("id", "tooltip");
                //tooltip.t.style.filter = "alpha(opacity=75)"; // buggy in ie5.0
                document.body.appendChild(tooltip.t);
                a = document.all ? document.all : document.getElementsByTagName("*");
                aLength = a.length;
                for (var i = 0; i < aLength; i++){

                        //if (a[i].tagName == "A" || a[i].tagName == "BUTTON" || (a[i].tagName == "INPUT" && (a[i].type == "submit" || a[i].type == "button" || a[i].type == "reset"))) a[i].onclick = self.focus;

                        if (!a[i]) continue;

                        tooltip_title = a[i].getAttribute("title");
                        tooltip_alt = a[i].getAttribute("alt");
                        tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip.blank_text;
                        if (tooltip_title || tooltip_blank){
                                a[i].setAttribute(tooltip.attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip.blank_text : tooltip.blank_text) : tooltip_title);
                                if (a[i].getAttribute(tooltip.attr_name)){
                                        a[i].removeAttribute("title");
                                        if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
                                        tooltip.l(a[i], "mouseover", tooltip.s);
                                        tooltip.l(a[i], "mouseout", tooltip.h);
                                }
                        }else if (tooltip_alt && a[i].complete){
                                a[i].setAttribute(tooltip.attr_name, tooltip_alt);
                                if (a[i].getAttribute(tooltip.attr_name)){
                                        a[i].removeAttribute("alt");
                                        tooltip.l(a[i], "mouseover", tooltip.s);
                                        tooltip.l(a[i], "mouseout", tooltip.h);
                                }
                        }
                        if (!a[i].getAttribute(tooltip.attr_name) && tooltip_blank){
                                //
                        }
                }
                document.onmousemove = tooltip.m;
                window.onscroll = tooltip.h;
                tooltip.a(-99, -99);
        },

        s: function(e){
                d = window.event ? window.event.srcElement : e.target;
                if (!d.getAttribute(tooltip.attr_name)) return;
                s = d.getAttribute(tooltip.attr_name);
                if (tooltip.newline_entity){
                        s = s.replace(/\&/g,"&amp;");
                        s = s.replace(/\</g,"&lt;");
                        s = s.replace(/\>/g,"&gt;");
                        s = s.replace(eval("/" + tooltip.newline_entity + "/g"), "<br />");
                        tooltip.t.innerHTML = s;
                }else{
                        if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
                        tooltip.t.appendChild(document.createTextNode(s));
                        //tooltip.t.innerText = s;
                }
                tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", tooltip.delay);
                tooltip.g = true;
        },

        h: function(e){
                tooltip.t.style.visibility = "hidden";
                if (!tooltip.newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
                clearTimeout(tooltip.c);
                tooltip.g = false;
                tooltip.a(-99, -99);
        },

        l: function(o, e, a){
                if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera 7b workaround!
                else if (o.attachEvent) o.attachEvent("on" + e, a);
                        else return null;
        },

        a: function(x, y){
                oCanvas = document.getElementsByTagName(
                (document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
                )[0];

                w_width = oCanvas.clientWidth ? oCanvas.clientWidth + oCanvas.scrollLeft : window.innerWidth + window.pageXOffset;
                w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop; 

                tooltip.t.style.width = ((tooltip.max_width) && (tooltip.t.offsetWidth > tooltip.max_width)) ? tooltip.max_width + "px" : "auto";

                t_width = tooltip.t.offsetWidth;
                t_height = tooltip.t.offsetHeight;

                tooltip.t.style.left = x + 8 + "px";
                tooltip.t.style.top = y + 8 + "px";

                if (x + t_width > w_width) tooltip.t.style.left = w_width - t_width + "px";
                if (y + t_height > w_height) tooltip.t.style.top = w_height - t_height + "px";
        }
}

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
        if (root.addEventListener) root.addEventListener("load", tooltip.d, false);
        else if (root.attachEvent) root.attachEvent("onload", tooltip.d);
}


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
window.attachEvent("onload", correctPNG);


var http;

function login()
{
    var username = document.getElementById("private-username").value;
    var password = document.getElementById("private-password").value;
    if (username=="" || password=="") {
	alert("Введены некорректные данные!         ");
	return false;
    }

    var URL="/clients/passwords.php?username="+username+"&password="+password;
    http.open("get", URL, false, username, password);
    http.send("");
    if (http.status == 200) {
        document.location = URL;
        //alert("Correct username and/or password.");

    } else {
        alert("Incorrect username and/or password.");
    }
    return false;
}

function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}

window.onload = function()
{
    http = getHTTPObject();

}



function openMaximized(imageId, width, height) {
  openMaximizedURL("/exec/gallery/maximized/" + imageId, width, height);
}

function openMaximizedURL(url, width, height) {
  var wh = calcMaxProportions(width, height, screen.width, screen.height);
  width = wh[0];
  height = wh[1];
  var winl = (screen.width - width) / 2;
  var wint = (screen.height - height) / 2;
  winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=0,resizable=0';
  win = window.open(url, '', winprops);
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}


function onBodyLoad() {
  initFormHandlers();
  if(typeof(HTMLArea) != "undefined" && typeof(_html_area_id) != "undefined") {
    if(_html_area_id == '') {
      HTMLArea.replaceAll();
    } else {
      HTMLArea.replace(_html_area_id);
    }
  }
}


function showNextUploadFile(rowId, nextButtonId) {
  var row = document.getElementById(rowId);
  var nextButton = document.getElementById(nextButtonId);
  row.style.display='';
  nextButton.style.visibility='hidden';
}

function closeWindow() {
  window.opener = window;
  window.close();
}

function resizeWindow(w, h) {
  var left = (screen.width - width) / 2;
  var top = (screen.height - height) / 2;

  winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=0,resizable=0';
  win = window.open("/exec/gallery/maximized/" + imageId, '', winprops);
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

//------------------- imgFadeObjects -------------------//

imgFadeObjects = new Object();
imgFadeTimers = new Object();
function imgFade(object, destOp, rate, delta){
if (!document.all)
return
    if (object != "[object]"){
        setTimeout("imgFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }

    clearTimeout(imgFadeTimers[object.sourceIndex]);

    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){
        direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;

    if (object.filters.alpha.opacity != destOp){
        imgFadeObjects[object.sourceIndex]=object;
        imgFadeTimers[object.sourceIndex]=setTimeout("imgFade(imgFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}


