function $(id){return document.getElementById(id);}
function translit(from, to){
	var str = from.value.replace(/[^a-zà-ÿ0-9]+/gi, '');
	var symbols = {'À':'a','Á':'b','Â':'v','Ã':'g','Ä':'d','Å':'e','¨':'e','Æ':'zh','Ç':'z','È':'i','É':'j','Ê':'k','Ë':'l','Ì':'m','Í':'n','Î':'o','Ï':'p','Ð':'r','Ñ':'s','Ò':'t','Ó':'u','Ô':'f','Õ':'h','Ö':'c','×':'ch','Ø':'sh','Ù':'csh','Ý':'e','Þ':'yu','ß':'ya','Û':'y','Ú':'','Ü':'','à':'a','á':'b','â':'v','ã':'g','ä':'d','å':'e','¸':'e','æ':'zh','ç':'z','è':'i','é':'j','ê':'k','ë':'l','ì':'m','í':'n','î':'o','ï':'p','ð':'r','ñ':'s','ò':'t','ó':'u','ô':'f','õ':'h','ö':'c','÷':'ch','ø':'sh','ù':'csh','ý':'e','þ':'yu','ÿ':'ya','û':'y','ú':'','ü':''};
	var len = str.length;
	var character;
	var res = '';
	for(i = 0; i < len; i++) {
		character = str.charAt(i,1);
		res += !symbols[character] ? character : symbols[character];
	}
	to.value = res;
}
function FillHeight(){
    yScroll = 0;
    if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX){
        yScroll = window.innerHeight + window.scrollMaxY;
        xScroll = window.innerWidth + window.scrollMaxX;
        var deff = document.documentElement;
        var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
        xScroll -= (window.innerWidth - wff);
        yScroll -= (window.innerHeight - hff);
    } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth) {
        yScroll = document.body.scrollHeight;
        xScroll = document.body.scrollWidth;
    }  else  {
        yScroll = document.body.offsetHeight;
        xScroll = document.body.offsetWidth;
    }
    return yScroll;
}

function show_preloader(logobg){
    return "<table cellspacing=\'0\' cellpadding=\'0\' width=\'246\' id=\'preloader\'><tr><td width=\'246\' align=\'center\' valign=\'middle\' id=\'preloader_cell\'><object classid=\'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\' codebase=\'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\' width=\'88\' height=\'88\' id=\'ibc_loader\' align=\'center\'><param name=\'allowScriptAccess\' value=\'sameDomain\' /><param name=\'movie\' value=\'/ibc_loader.swf\' /><param name=\'quality\' value=\'high\' /><param name=\'FlashVars\' value=\'colorforBack=0x"+logobg+"\' id=\'urlvariables\'><param name=\'bgcolor\' value=\'transparent\' /><param name=\'wmode\' value=\'transparent\' /><embed src=\'/ibc_loader.swf\' quality=\'high\' FlashVars=\'colorforBack=0x"+logobg+"\' bgcolor=\'transparent\' width=88 height=88 name=\'ibc_loader\' align=\"center\' allowScriptAccess=\'sameDomain\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' /></object></td></tr></table>";
}

function GetColors(){
    $('form_colors').style.display = 'block';
    $('screen').style.height = FillHeight()+'px';
    $('form_colors').style.top = (getPageScroll()+200)+'px'; //(Math.round(document.all.screen.scrollHeight / 2)-100) + 'px';
    $('form_colors').style.left = (Math.round(document.body.clientWidth / 2)-200) + 'px';
    $('screen').style.zIndex = 1000000;
    $('screen').style.display = 'block';
    var links = document.links;
    for(i=0; i < links.length; i++){links[i].onclick = function(){return false}}
    return true;
}

function customSave(id, content) {
    alert(id + "=" + content);
}

function getPageScroll(){
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    return yScroll;
}

var divclick = 0;
function LoadTiny() {
    if(!divclick) {
        $('page_content').style.display = 'none';
        $('page_content_editable').style.display = 'block';
        $('page_title').style.display = 'none';
        $('page_title_editable').style.display = 'block';
        $('page_subtitle_editable').style.display = 'block';
        divclick = 1;
    }
}

var target_field = 'm_bg';
/*
var color_container = $('colors_container');
var color_table = $('def_txt');
var def_color_box = $('def_color');
*/
function MoveColors() {
	$('screen').style.display = 'none';
	$('screen').style.zIndex = 0;
	$('form_colors').style.display = 'none';
	$('colors_container').style.display = 'none';
	$('colors_container').style.zIndex = 0;
	$('comment_form').style.display = 'none';

	var links = document.links;
    for(i=0; i < links.length; i++){ links[i].onclick = function(){return true}}

    $('colors_link').onclick = function(){ GetColors(); return false; }
    $('comment_link').onclick = function(){ showCommentForm(); return false; }
    $('bm_bg').style.backgroundColor = smbgr;
    $('bm_txt').style.backgroundColor = smtxt;
    $('bd_bg').style.backgroundColor = sdbgr;
    $('bm_ln').style.backgroundColor = smlnk;
    document.forms[0].reset();
    return true;
}

function OpenColorPicker(color_picker){
    $('colors_container').style.zIndex = 1000100;
    $('colors_container').style.left = (Math.round(document.body.clientWidth / 2)+220) + 'px';
    if(color_picker==1){
        target_field = 'm_bg';
        $('def_color').style.backgroundColor = mbgr;
        $('def_txt').onclick = function(){SetColor(mbgr);return false}
        $('colors_container').style.top = (getPageScroll()+238) + 'px';
    } else if(color_picker==2){
        target_field = 'm_txt';
        $('def_color').style.backgroundColor = mtxt;
        $('def_txt').onclick = function(){SetColor(mtxt);return false}
        $('colors_container').style.top = (getPageScroll()+267) + 'px';
    } else if(color_picker==3){
        target_field = 'd_bg';
        $('def_color').style.backgroundColor = dbgr;
        $('def_txt').onclick = function(){SetColor(dbgr);return false}
        $('colors_container').style.top = (getPageScroll()+294) + 'px';
    } else {
        target_field = 'm_ln';
        $('def_color').style.backgroundColor = mlnk;
        $('def_txt').onclick = function(){SetColor(mlnk);return false}
        $('colors_container').style.top = (getPageScroll()+322) + 'px';
    }
    $('colors_container').style.display = 'block';
}

function SetColor(what){
    document.forms[0].elements[target_field].value = what;
    $('b'+target_field).style.backgroundColor = what;
    return false;
}

function showCommentForm(){
    $('screen').style.zIndex = 1000000;
    $('screen').style.display = 'block';
    $('screen').style.height = FillHeight()+'px';
    $('comment_form').style.display = 'block';
    $('comment_form').style.zIndex = 1000001;
    $('comment_form').style.top = (getPageScroll()+200)+'px'; //(Math.round(document.all.screen.scrollHeight / 2)-100) + 'px';
    $('comment_form').style.left = (Math.round(document.body.clientWidth / 2)-200) + 'px';
}

/* function */

var lastkey;

function checkKeycode(e){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    if(keycode == 27 && lastkey != 13 && $('screen').style.display == 'block')
        MoveColors();
    else if (lastkey == 17 && keycode == 13)
        postComment('comment_send');
    lastkey = keycode;
    return;
}

document.onkeyup = checkKeycode;