<!--
try {
Event.observe(window, 'load', init, false);
} catch (e) {}

function init() {
    // menu initialization
    var ii;
    var errOccured = false;
    try {
        var cnt = totalTopoindexes;
    } catch(e) {
        errOccured = true;
    }
    if (!errOccured) {
        for (ii=0;ii<totalTopoindexes;ii++) {
            var menu_id = "menu_" + ii.toString();
            var menu = $(menu_id);
            var menu_offsets = Element.positionedOffset(menu);
            submenu_id = "submenu_" + ii.toString();
            var submenu = $(submenu_id);
            var submenu_size = Element.getDimensions(submenu); //submenu_size.width, submenu_size.height
            submenu.style.top = (menu_offsets[1] + menu.offsetHeight) + 'px';
            if ((menu_offsets[0] + submenu_size.width) > (screen.availWidth - 24)) {
                submenu.style.left = (screen.availWidth - 24 - submenu_size.width) + 'px';
            } else {
                submenu.style.left = menu_offsets[0] + 'px';
            }
        	Event.observe(menu_id, 'mouseover', showSub.bindAsEventListener(menu, ii));
        	Event.observe(menu_id, 'mouseout', hideSub.bindAsEventListener(menu, ii));
        }
    }
}


function showSub(e) {
    var data = $A(arguments);
    data.shift();
    $("submenu_" + data).style.display="inline";
//    var obj = $("submenu_" + data);
//    new Effect.SlideDown(obj);
}


function hideSub(e) {
    var data = $A(arguments);
    data.shift();
    $("submenu_" + data).hide();
}


function openCloseSendFriend() {
    var sf = $("send_friend");
    if (sf.style.display == "none") {
        var l = $("sendLink");
        sf.style.position = "absolute";
        var offsets = Position.cumulativeOffset(l);
        sf.style.top = (offsets[1] + l.offsetHeight - 100) + 'px';
        sf.style.left = offsets[0] + 'px';
        new Effect.SlideDown(sf);
    } else
        new Effect.SlideUp(sf);
}

    
var submitted = false;

function validateContact(theForm) {
  if (!submitted) {
	if(theForm.username.value.length < 1) {
		 alert("Поле \"Ім`я/Нік\" обов`язкове для заповнення!");
		 theForm.username.focus();
		 return(false);
	}
	if(theForm.email.value.length < 1) {
		 alert("Поле \"e-mail\" обов`язкове для заповнення!");
		 theForm.email.focus();
		 return(false);
	}
	if(!isEmail(theForm.email.value)) {
		 alert("Вкажіть Вашу справжню поштову скриньку.");
		 theForm.email.focus();
		 return(false);
	}
	if(theForm.subject.value.length < 1) {
		 alert("Поле \"тема повідомлення\" обов`язкове для заповнення!");
		 theForm.subject.focus();
		 return(false);
	}
	if(theForm.message.value.length < 1) {
		 alert("Поле \"текст повідомлення\" обов`язкове для заповнення!");
		 theForm.message.focus();
		 return(false);
	}
	submitted = true;
	return (true);
  } else {
  	return (false);
  }
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function isInteger (s)
{   var i;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}



function isEmail (s)
{      
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function trim(inputString)
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ")
   { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ")
   { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1)
   { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function errImage(obj) {
	obj.src = "./img/sp.gif";
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function chColor(newcolor) {
    createCookie('test_c','test_v')
    if (readCookie('test_c') == 'test_v') {
        if (newcolor != '') {
            createCookie('newcolor',newcolor, 30);
        }
    } else {
        alert('Please enable cookies in browser!');
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function changeImage(obj, pointer, inc) {
    gcurPointer += inc;
    if (gcurPointer < 1) gcurPointer = gmaxPointer;
    if (gcurPointer > gmaxPointer) gcurPointer = 1;
    var cnt = getObj(pointer);
    if (cnt !== false) cnt.innerHTML = gcurPointer;
    var objImage = getObj(obj);
    if (cnt !== false) objImage.src = arrImages[gcurPointer-1];
}

function getObj(objName) {
    if(document.getElementById && document.getElementById(objName)) {
        return document.getElementById(objName);
    }
    else if (document.all && document.all(objName)) {  
        return document.all(objName);
    } 
    else if (document.forms && document.forms[objName]) { 
        return document.forms[objName];
    } else {
        return false;
    }
}
//-->
