﻿/*--------  Menus v2.0 --------*/
function PopupMenus(count, li_prefix, div_prefix) {
	var c = count;
	var li_id_prefix = li_prefix;
	var div_id_prefix = div_prefix;
	this.li_id = '';
	this.div_id = '';
	var prev_id = -1;
	this.Popup = function(id) {
		this.li_id = li_id_prefix + id;
		this.div_id = div_id_prefix + id;
		if (prev_id != -1) {
			util.Set_ElementStyle(div_id_prefix + prev_id, "class", "MenuOut");
		}
		prev_id = id;
		var coords = util.Find_ElementCoords(this.li_id);
		var size = util.Get_ElementSize(this.li_id);
		util.Set_ElementStyle(this.div_id, "left", coords.x + size.width);
		util.Set_ElementStyle(this.div_id, "top", coords.y);
		util.Set_ElementStyle(this.div_id, "class", "MenuHover");
	}
	this.Popout = function(id, evt) {
		var cursor = util.Cursor_Position(evt);
		var coords = util.Find_ElementCoords(this.div_id);
		var size = util.Get_ElementSize(this.div_id);
		var out = false;
		if (cursor.x <= coords.x || cursor.x >= coords.x + size.width) {
			out = true;
		}
		if (cursor.y <= coords.y || cursor.y >= coords.y + size.height) {
			out = true;	
		}
		if (out) {
			util.Set_ElementStyle(this.div_id, "class", "MenuOut");
		}
	}
	this.OnBody = function() {
		for (var i = 1; i <= c; i++) {
			if (util.Check_ElementClass(div_id_prefix + i) == "MenuHover") {
				util.Set_ElementStyle(div_id_prefix + i, "class", "MenuOut");
				return true;
			}
		}
		return false;
	}
	this.OnMouseOut = function(evt) {
	    var coords = util.Find_ElementCoords(this.li_id);
	    var size = util.Get_ElementSize(this.li_id);
	    var cursor = util.Cursor_Position(evt);
	    if (cursor.x < coords.x + size.width) {
	        this.OnBody();
	    }
	}
}
var pm = new PopupMenus(8, "li", "div");
/*-------  End Menus v2.0  --------*/
function ForumPostAdd_Validate(id) {
    var isValid = true;
    var errors = '';
    var pip = util.Find_Control(id + "_pipTextBox").value;
    var comment = util.Find_Control(id + "_responseArea").value;
    if (pip.length < 3) {
        isValid = false;
        errors += "-Вкажіть Ім'я <br />";
    }
    if (comment.length < 5) {
        isValid = false;
        errors += "-Напишіть свій відгук";
    }
    if (!isValid) {
        util.Find_Control("ForumPostAdd_ErrorPanel").style.display = "block";
        util.Find_Control("ForumPostAdd_ErrorPanel_Content").innerHTML = errors;
        return false;
    }
    else {
        return true;
    }
}
function ForumPostAdd_Clear(id) {
    util.Find_Control(id + "_pipTextBox").value = '';
    util.Find_Control(id + "_responseArea").value = '';
    util.Find_Control(id + "_dateFromTextBox").value = '';
    util.Find_Control(id + "_dateToTextBox").value = '';
    util.Find_Control("ForumPostAdd_ErrorPanel").style.display = "none";
}
/*-------- Cookies Data ---------*/
cookieData = function() {
    this.getCookie = function(cookie_name) {
        var doc_all_cookies = document.cookie.split(';');
	    var doc_temp_cookie = '';
	    var doc_cookie_name = '';
	    var doc_cookie_value = '';
	    
	    for (var i = 0; i < doc_all_cookies.length; i++) {
		    doc_temp_cookie = doc_all_cookies[i].split('=');
    		
		    doc_cookie_name = doc_temp_cookie[0].replace(/^\s+|\s+$/g, ''); // trim
		    
		    if (doc_cookie_name == cookie_name) {
			    
			    if (doc_temp_cookie.length > 1)
			    {
				    doc_cookie_value = unescape(doc_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			    }
			    return doc_cookie_value;
			    break;
		    }
		    doc_temp_cookie = null;
		    doc_cookie_name = '';
	    }
	    return null;
    }
    this.setCookie = function(name, value, expires, path, domain, secure) {
	    var today = new Date();
	    today.setTime(today.getTime());
	    if (expires) {
		    expires = expires * 1000 * 60 * 60 * 24;
	    }
	    var expires_date = new Date(today.getTime() + (expires));
	    document.cookie = name + "=" +escape(value) +
		    ((expires) ? ";expires=" + expires_date.toGMTString() : "" ) +
		    ((path) ? ";path=" + path : "" ) + 
		    ((domain) ? ";domain=" + domain : "" ) +
		    ((secure) ? ";secure" : "" );
    }
    this.delCookie = function(name, path, domain) {
        if (this.getCookie(name)) {
            document.cookie = name + "=" +
			    ((path) ? ";path=" + path : "") +
			    ((domain) ? ";domain=" + domain : "") +
			    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			return "deleted";
	    }
	    else {
	        return null;
	    }
    }
}
var cd = new cookieData();
/*-------- End Cookies Data ---------*/
function sound(v) {
    if (v) {
        cd.delCookie("SoundPlay");
        cd.setCookie("SoundPlay", "on", '1000', '/', '', '');
    }
    else {
        cd.delCookie("SoundPlay");
        cd.setCookie("SoundPlay", "off", '1000', '/', '', '');
    }
}
var flash;
function FlashCode(url, id, width, height, container) {
    flash =
        "<OBJECT movie=\"" + url + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" id=\"" + id + "\" name=\"name\">\n" +
        "<PARAM NAME=\"movie\" VALUE=\"" + url + "\" />\n" +
        "<PARAM NAME=\"quality\" VALUE=\"high\" />\n" +
        "<PARAM NAME=\"wmode\" VALUE=\"transparent\" />\n" +
        "<PARAM NAME=\"bgcolor\" VALUE=\"#FFFFFF\" />\n" +
        "<EMBED wmode=\"transparent\" src=\"" + url + "\" quality=\"high\" bgcolor=\"#FFFFFF\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" ID=\"" + id + "\" NAME=\"" + id + "\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED></OBJECT>";
    
    document.getElementById(container).innerHTML = flash;
}