﻿function onload_js() {
	
}
function is_array(input) {
	return typeof(input)=='object'&&(input instanceof Array);
}
function is_int( mixed_var ) {
 
	if (typeof mixed_var !== 'number') {
		return false;
	}
 
	if (parseFloat(mixed_var) != parseInt(mixed_var, 10)) {
		return false;
	}
	
	return true;
}
function strpos( haystack, needle, offset){
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
}
function overeni_enteru(eventname,id,reload_url,div) {
	if (eventname.keyCode == "13") {
		odeslani_strankovani(id,reload_url,div);
	}
}
function odeslani_strankovani(id,reload_url,div) {
	ajaxWM(reload_url+'&r_limit='+document.getElementById(id).value,div);
}
	
function qedit2(zapnout, obj) {
	if (zapnout == 1) {
		document.getElementById(obj).style.display = 'block';
		document.getElementById(obj+'-div').style.display = 'block';
	} else if (zapnout == 2) {
		if (document.getElementById(obj).style.display == 'block') {
			document.getElementById(obj).style.display = 'none';
			document.getElementById(obj+'-div').style.display = 'none';
		} else {
			document.getElementById(obj).style.display = 'block';
			document.getElementById(obj+'-div').style.display = 'block';
		}
	} else {
		document.getElementById(obj).style.display = 'none';
		document.getElementById(obj+'-div').style.display = 'none';
	}
}
function qedit(zapnout, obj) {
	if (zapnout == 1) {
		document.getElementById(obj).style.display = 'block';
		document.getElementById(obj+'-div').style.display = 'block';
	} else if (zapnout == 2) {
		if (document.getElementById(obj).style.display == 'block') {
			document.getElementById(obj).style.display = 'none';
			document.getElementById(obj+'-div').style.display = 'none';
		} else {
			document.getElementById(obj).style.display = 'block';
			document.getElementById(obj+'-div').style.display = 'block';
		}
	} else {
		document.getElementById(obj).style.display = 'none';
		document.getElementById(obj+'-div').style.display = 'none';
	}
}
function only_integer(cislo) {
	var re = /[^0-9]/g;
	cislo.value = cislo.value.replace(re,"");
}
function only_float(cislo) {
	var re = /[^0-9\.\,]/g;
	var re2 = /(,)/; 
	cislo.value = cislo.value.replace(re,"");
	cislo.value = cislo.value.replace(re2,"."); // první čárku nahradím za tečku
}
function only_chars(cislo) {
	var re = /[^a-žAŽ]/g;
	cislo.value = cislo.value.replace(re,"");
}

function color_over (ten, vol) {
	if (vol == 1) return ten.style.backgroundImage='url(\'/images/pozadi_bunky2.gif\')';
	if (vol == 2) return ten.style.backgroundImage='url(\'/images/pozadi_bunky.gif\')';
	if (vol == 3) return ten.style.backgroundImage='url(\'/images/pozadi_bunky3.gif\')';
	if (vol == 4) return ten.style.backgroundImage='url(\'/images/pozadi_bunky4.gif\')';
	if (vol == 5) return ten.style.backgroundImage='url(\'/images/pozadi_bunky5.gif\')';
}
zi = 0;
function showObject(objID, zobraz) {
	if(zobraz == 1) {
		getObj(objID).style.display = '';
		getObj(objID).style.zIndex = '100'+zi;
	} else if(zobraz == 2) {
		getObj(objID).style.display = 'none';
		getObj(objID).style.zIndex = '0';
	} else if(getObj(objID).style.display != 'none') {
		getObj(objID).style.display = 'none';
		getObj(objID).style.zIndex = '0';
	} else {
		getObj(objID).style.display = '';
		getObj(objID).style.zIndex = '100'+zi;
	}
	zi += 1;
}
function disable(objID, disable) {
	if(disable == 1) {
		getObj(objID).disabled = true;
	} else if(disable == 2) {
		getObj(objID).disabled = false;
	} else if(getObj(objID).disabled == true) {
		getObj(objID).disabled = false;
	} else {
		getObj(objID).disabled = true;
	}
}
function disableCheckboxes(name, disable) {
	if(is_array(name)) {
		for(var i = 0; i < name.length; i++) {
			document.getElementById(name[i]).disabled = ( (document.getElementById(name[i]).disabled == true || disable == 0) && disable != 1) ? false : true;
		}
	} else {
		for(var i = 0; i < document.getElementsByName(name).length; i++) {
			document.getElementsByName(name)[i].disabled = ( (document.getElementsByName(name)[i].disabled == true || disable == 0) && disable != 1) ? false : true;
		}
	}
}
function checkCheckboxes(name, check) {
	if(is_array(name)) {
		for(var i = 0; i < name.length; i++) {
			document.getElementById(name[i]).checked = ( ((document.getElementById(name[i]).checked == true || check == 0) && check != 1) || (document.getElementById(name[i]).disabled == true)) ? false : true;
		}
	} else {
		for(var i = 0; i < document.getElementsByName(name).length; i++) {
			document.getElementsByName(name)[i].checked = ( ((document.getElementsByName(name)[i].checked == true || check == 0) && check != 1) || (document.getElementsByName(name)[i].disabled == true)) ? false : true;
		}
	}
}
function opacity(id, opacStart, opacEnd, millisec, obj) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
		}
		if(obj != "") {
			text2value(obj,'');
		}
		Effect.BlindUp(id);; return false;
		//setTimeout("showObject('"+id+"',0)",millisec+150);
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		Effect.BlindDown(id);; return false;
		//setTimeout("showObject('"+id+"',1)",0);
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
function activeNdeactive(zaktivnit, zneaktivnit) { // aktivní může být pouze jeden
	for(var a = 0; a < zneaktivnit.length; a++) {
		getObj(zneaktivnit[a]).disabled = true;
	}
	getObj(zaktivnit).disabled = false;
	getObj(zaktivnit).focus();
}
// klávesové zkratky
var isAltKeyPressed = false;
var isCtrlKeyPressed = false;
var isShiftKeyPressed = false;
var hotkeyactive = true;
function hotkey(eventname) {
	/*if (eventname.keyCode == 18) isAltKeyPressed = true;
	if (eventname.keyCode == 17) isCtrlKeyPressed = true;
	if (eventname.keyCode == 16) isShiftKeyPressed = true;*/
	
	if (hotkey1[eventname.keyCode] && hotkeyactive) {
		window.location.href = hotkey1[eventname.keyCode];
	}
}
function hotkeysetfocus() {
	for (var i = 0; i < document.forms.length; i++) {
		for (var i2 = 0; i2 < document.forms[i].length; i2++) {		
			if (document.forms[i].elements[i2].type != 'submit' && document.forms[i].elements[i2].type != 'button' && document.forms[i].elements[i2].type != 'reset') {
				document.forms[i].elements[i2].onfocus = fnc_hotkeydeactive;
				document.forms[i].elements[i2].onblur = fnc_hotkeyactive;
			}
		}
	}
}
function fnc_hotkeydeactive() {
	hotkeyactive = false;
}
function fnc_hotkeyactive() {
	hotkeyactive = true;
}


// AJAX FUNCTIONS
// metoda GET s intervalem opakování 1/1000
function ajaxWMrefresh(url, div, interval) {
	setInterval('ajaxWM(\''+url+'\', \''+div+'\')', interval);
}
// metoda GET
function ajaxWM(url, div, fce) {
	var ajaxWMhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

	ajaxWMhttp.open("get", url, true);
	ajaxWMhttp.onreadystatechange = function () {
		if (ajaxWMhttp.readyState == 4 && (ajaxWMhttp.status == 200 || ajaxWMhttp.status == 304)) {
			document.getElementById(div).innerHTML = ajaxWMhttp.responseText;
			if (fce != undefined) {
				try {
					for(var i = 0; i < fce.length; i++) {
						eval(fce[i]);
					}
				} catch(e) {
					
				}
			}
		}
	};
	ajaxWMhttp.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
	ajaxWMhttp.send(null);
}
// metoda POST
function ajaxWMpost(oForm, div, fce) {
	var sBody = getRequestBody(oForm);
	var ajaxWMhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
	
	ajaxWMhttp.open("post", oForm.action, true);
	ajaxWMhttp.onreadystatechange = function () {
		if (ajaxWMhttp.readyState == 4 && (ajaxWMhttp.status == 200 || ajaxWMhttp.status == 304)) {
			if (getObj(div).style.display == 'none') getObj(div).style.display = '';
			
			document.getElementById(div).innerHTML = ajaxWMhttp.responseText;
			
			if (fce != undefined) {
				try {
					for(var i = 0; i < fce.length; i++) {
						eval(fce[i]);
					}
				} catch(e) {
					
				}
			}
		} else {
			// 1 - loading - metoda open() byla zavolána, ale požadavek nebyl odeslán
			// 2 - loaded - poažadavek byl odeslán
			// 3 - interactive - část odpovědi byla přijata
			// 4 - všechna data byla přijata a spojení bylo uzavřeno
			// alert(ajaxWMhttp.readyState);
		}
	};
	ajaxWMhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxWMhttp.send(sBody);
}

var hledani_stopky = '';
function hledani(form,div){ // funkce, která zajišťuje volání ajaxu až po uběhnutí určitého času
	clearInterval(hledani_stopky);
	hledani_stopky = setInterval("hledani_ajax('"+form+"','"+div+"')", 0.25 * 1000);
}
function hledani_ajax(form,div) { // zavolá funkci, která znovu odešle data a načte nový výsledek hledání
	clearInterval(hledani_stopky);
	ajaxWMpost(getObj(form), div, Array("initCheckBoxes('seznam-seznamu')"));
}
function encodeNameAndValue(sName, sValue) {
	var sParam = encodeURIComponent(sName);
	sParam += "=";
	sParam += encodeURIComponent(sValue);
	return sParam;
}
function getRequestBody(oForm) {
	var aParams = new Array();
	for (var i=0; i < oForm.elements.length; i++) {
		var oField = oForm.elements[i];
		switch (oField.type) {
			case "button":
			case "submit":
			case "reset":
				break;
			
			case "checkbox":
				if (!oField.checked) {
					break;
				}
			case "radio":
				if (!oField.checked) {
					break;
				}
				
			case "text":
			case "hidden":
			case "password":
				aParams.push(encodeNameAndValue(oField.name, oField.value));
				break;
			default:
				switch(oField.tagName.toLowerCase()) {
					case "select":
						aParams.push(encodeNameAndValue(oField.name, oField.options[oField.selectedIndex].value));
						break;
					default:
						aParams.push(encodeNameAndValue(oField.name, oField.value));
				}
		}
	}
	return aParams.join("&");
}
// KONEC AJAX FUNCTIONS
// číslo na tisíce
function number_format(cislo) { // -1000.10 - 1001
	var str = "";
	var str2 = "";
	var cislo_des = "";
	var pos = 0;
	
	cislo_des = cislo + "";
	pos = cislo_des.lastIndexOf(".");
	if (pos > 0) {
		cislo_des = "." + cislo_des.slice(pos + 1);
	} else {
		cislo_des = "";
	}
	
	if (cislo < 0) { // ošetření zaokrouhlení na celá čísla
		cislo = Math.ceil(cislo);
	} else {
		cislo = Math.floor(cislo);
	}
	
	str = cislo + "";
	if (str.length > 3 && str.length < 7) {
		str2 = str.substr(0, 0 + str.length - 3) + " " + str.substr(0 + str.length - 3);
		str2 = str2 + cislo_des; if (cislo_des.length == 2) str2 = str2 + "0";
		return str2;
	} else if (str.length > 6 && str.length < 10) {
		str2 = ( str.substr(0, 0 + str.length - 6) + " ");
		str = str.substr(str.length - 6);
		
		str2 = str2 + "" + ( str.substr(0, 0 + str.length - 3) + " " + str.substr(0 + str.length - 3) );
		str2 = str2 + cislo_des; if (cislo_des.length == 2) str2 = str2 + "0";
		return str2;
	} else if (str.length > 9 && str.length < 13) {
		str2 = ( str.substr(0, 0 + str.length - 9) + " ");
		str = str.substr(str.length - 9);
		
		str2 = str2 + "" + ( str.substr(0, 0 + str.length - 6) + " ");
		str = str.substr(str.length - 6);
		
		str2 = str2 + "" + ( str.substr(0, 0 + str.length - 3) + " " + str.substr(0 + str.length - 3) );
		str2 = str2 + cislo_des; if (cislo_des.length == 2) str2 = str2 + "0";
		return str2;
	}
	
	str = str + cislo_des; if (cislo_des.length == 2) str = str + "0";
	return str;
}

function vypsat_video(sirka, vyska, nazev, typ) {
	//if (typ == 0) {
		//document.write('<object id="WMPlay" ' + sirka + ' ' + vyska + ' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,70" standby="Loading ..." type="application/x-oleobject">');
		//document.write('<param name="url" value="/video/' + nazev + '">');
		/*document.write('<param name="displaysize" value="0">');
		document.write('<param name="allowchangedisplaysize" value="1">');
		document.write('<param name="showcontrols" value="1">');
		document.write('<param name="windowlessvideo" value="0">');
		document.write('<param name="showdisplay" value="1">');
		document.write('<param name="showstatusbar" value="1">');
		document.write('<param name="autostart" value="1">');
		document.write('<param name="Invokeurls" value="0">');*/
	//}
	//if (typ == 1) {
		document.write('<embed name="WMplay" ' + sirka + ' ' + vyska + ' src="/video/' + nazev + '" loop="0" autoplay="0"></embed>');
	//}
	//if (typ == 0) { 
		//document.write('</object>');
	//}
}
function otevri(url, sirka, vyska) {
	window.open(url, "_blank", "width="+sirka+", height="+vyska+", menubar=1, directories=no, toolbar=no, location=no, status=yes, scrollbars=yes, resizable=yes");
}
function img_nahled(adresa, sirka_okna, vyska_okna) {
	window.open("/img_nahled.php?foto="+adresa, "_blank", "width="+sirka_okna+", height="+vyska_okna+", menubar=no, directories=no, toolbar=no, location=no, status=no, scrollbars=no, resizable=no");
}
function img_nahled2(foto) {
	window.open("/img_nahled2.php?foto="+foto, "_blank", "width=1024, height=768, menubar=no, directories=no, toolbar=no, location=no, status=no, scrollbars=yes, resizable=yes");
}
function img_nahled_galerie(adresa, foto, strana, sirka_okna, vyska_okna) {
	window.open("/img-nahled.php?adresa="+adresa+"&foto="+foto+"&strana="+strana, "_blank", "width="+sirka_okna+", height="+vyska_okna+", menubar=no, directories=no, toolbar=no, location=no, status=no, scrollbars=yes, resizable=yes");
}
function spam_email(vol1, vol2, vol3, vol4) {
	var vol = vol4 + vol2 + vol3 + vol1; 
	document.write("<a href=\"mailto:"+ vol +"\">" + vol + "</a>");
}
function vypsat_flash(adresa,sirka,vyska,pozadi) {
	document.write('<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="'+sirka+'" height="'+vyska+'" id="flashik" align="middle"><param name="wmode" value="opaque"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+adresa+'"><param name="quality" value="high"><param name="bgcolor" value="'+pozadi+'">');
	document.write('<embed wmode="opaque" src="'+adresa+'" quality="high" bgcolor="'+pozadi+'" width="'+sirka+'" height="'+vyska+'" name="flash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
	document.write('</object>');
}
function AddFavorite(linkObj,addUrl,addTitle) 
{ 
  if (document.all && !window.opera) 
  { 
    window.external.AddFavorite(addUrl,addTitle); 
    return false; 
  } 
  else if (window.opera && window.print) 
  { 
    linkObj.title = addTitle; 
    return true; 
  } 
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) 
  { 
    if (window.confirm('Přidat oblíbenou stránku jako nový panel?')) 
    { 
      window.sidebar.addPanel(addTitle,addUrl,''); 
      return false; 
    } 
  } 
  window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.'); 
  return false; 
}

function getObj(name)
{
 if (document.getElementById) {
   return document.getElementById(name);
 } else
		if (document.all) {
			return document.all[name];
		} else
			if (document.layers) {
				return document.layers[name];
			} else return false;
}

function doBox() {
	var state = doBox.arguments[0];
	var i;
	for (i=1; i<doBox.arguments.length; i++) {
		switch(state) {
			case 'on':
				doEnableItem( doBox.arguments[i] );
			break;
			case 'off':
				doDisableItem( doBox.arguments[i] );
			break;
			default:
			;
		}
	}
}

function doCheck() {
	var i;
	for (i=0; i<doCheck.arguments.length; i++) {
		var obj = document.getElementById(doCheck.arguments[i]);
		if (obj!='undefined' && obj!=null) {
				obj.checked = true;
		}
	}
}

function doEnableItem(id) {
	var obj = document.getElementById(id);
	if (obj!='undefined' && obj!=null) {
			obj.disabled = false;
	}
	var obj = getObj(id+'T');
	if (obj!='undefined' && obj!=null) {
		getObj(id+'T').style.color = '#000000';
	}

}

function doDisableItem(id) {
	var obj = document.getElementById(id);
	if (obj!='undefined' && obj!=null) {
		obj.disabled = true;
	}
	var obj = getObj(id+'T');
	if (obj!='undefined' && obj!=null) {
		getObj(id+'T').style.color = '#888888';
	}
}

function selectAll(id) {
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function hvezdicky(num, stav, produkt) {
	var zbytek = 5 - stav;
	zbytek = 6 - zbytek;
	if(stav == 0 && num > 0) {
		for(i = 1; i <= 5; i++) {
			getObj('hvezdicka'+produkt+i).src = '/images/icons/star-blank.gif';	
		}
		for(j = 1; j <= num; j++) {
			getObj('hvezdicka'+produkt+j).src = '/images/icons/star.gif';	
		}
	} else if(stav > 0 && num == 0) {
		for(k = 1; k <= stav; k++) {
			getObj('hvezdicka'+produkt+k).src = '/images/icons/star.gif';	
		}
		for(k2 = zbytek; k2 <= 5; k2++) {
			getObj('hvezdicka'+produkt+k2).src = '/images/icons/star-blank.gif';	
		}
	} else if(stav == 0 && num == 0) {
		for(i = 1; i <= 5; i++) {
			getObj('hvezdicka'+produkt+i).src = '/images/icons/star-blank.gif';	
		}
	}
}

function trim(str) {
	return ltrim(rtrim(str));
}

function ltrim(str) {
	if (typeof(str) == 'string'){
		chars = "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	} else{
		return '';
	}
}

function rtrim(str) {
	if (typeof(str) == 'string'){
		chars = "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	} else{
		return '';
	}
}

var lastvscroll = 0;
function scroll_position() {
	if (window.pageYOffset) vscroll = window.pageYOffset;
    else vscroll = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	
	if (lastvscroll != vscroll) {
		if (vscroll > 0) {
			getObj("scroll-top-active").style.display = '';
			getObj("scroll-top").style.display = 'none';
		} else {
			getObj("scroll-top-active").style.display = 'none';
			getObj("scroll-top").style.display = '';
		}
		lastvscroll = vscroll;
	}
}
function scroll_top() {
	window.scrollTo(0,0);
}
function sentSelect(volba, akce, loc) {
	var volba = document.getElementById(volba);
	var hodnota = volba.options[volba.selectedIndex].value;
	
	if(loc == 0 || loc == undefined || loc == "") {
		if(hodnota != "" && akce != "") window.location.href = '?'+akce+'='+hodnota;
	} else {
		if(hodnota != "" && akce != "") window.location.href = '/'+akce+'&volba='+hodnota;
	}
}
function procenta(zaklad, cast) {
	var procento = parseFloat(zaklad)/100;
	return Math.round(cast/procento);
}
function dialogBox(obj, zavrit) {// if (zavrit == 1) clona se nezavře po kliknutí mimo div
	if(zavrit == undefined) var zavrit = 0;
	
	if(getObj(obj).style.display == 'none') {
			
		if(getObj('clona') != undefined) {
			document.body.removeChild(getObj('clona'));
		}
		
		getObj(obj).style.visibility = 'hidden';
		getObj(obj).style.display = '';
		
		// pomocné
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			browserWidth = window.innerWidth;
			browserHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			browserWidth = document.documentElement.clientWidth;
			browserHeight = document.documentElement.clientHeight;
		}
		
		var leftPosition = ( ( browserWidth ) - parseFloat( getObj(obj).offsetWidth ) ) / 2;
		var topPosition = ( ( browserHeight ) - parseFloat( getObj(obj).offsetHeight ) ) / 3;
		leftPosition = procenta(browserWidth, leftPosition);
		topPosition = procenta(browserHeight, topPosition);
		
		// vytvořím element "clona"
		var clona = document.createElement('div');
		clona.setAttribute('id', 'clona');
		
		// nastylování clony
		clona.style.width = '100%';
		clona.style.height = '100%';
		clona.style.backgroundColor = '#000000';
		clona.style.opacity = '0.7';
		clona.style.filter = 'alpha(opacity=70)';
		clona.style.position = 'fixed';
		clona.style.top = '0px';
		clona.style.left = '0px';
		clona.style.zIndex = '2000';
		
		// skrytí clony po kliknutí
		if (zavrit == 0) clona.onclick = function() { dialogBox(obj) } ; 
		
		// vložím clonu
		document.body.appendChild(clona);
		
		// zobrazím objekt a nastyluji
		//clona.appendChild(getObj(obj));
		getObj(obj).style.visibility = '';
		getObj(obj).style.zIndex = '2002';
		getObj(obj).style.opacity = '1';
		getObj(obj).style.top = ((topPosition > 0) ? topPosition : '0')+'%';
		getObj(obj).style.left = ((leftPosition > 0) ? leftPosition : '0')+'%';
	} else {
		getObj('clona').style.display = 'none';
		getObj('clona').style.zIndex = '0';
		getObj(obj).style.display = 'none';
	}
}
function valueOff(text,id) {
	if(document.getElementById(id).value == '') {
		document.getElementById(id).value = text;
		document.getElementById(id).style.color = '#BBBBBB';
	} else if (document.getElementById(id).value == text) {
		document.getElementById(id).value = '';
		document.getElementById(id).style.color = '#000000';
	}
}

var checkedValue = null;	
function initCheckBoxes(obj) {
	var cells = document.getElementById(obj).getElementsByTagName('tr');
	for(var i = 0; i < cells.length; i++) {
		var checkbox = cells[i].getElementsByTagName('input');
		if (checkbox.length > 0 && checkbox[0].type.toLowerCase() == 'checkbox') {
			cells[i].checkBoxObj = checkbox[0];
			cells[i].onmousedown = tdOnMouseDown;
			cells[i].onmouseover = tdOnMouseOver;
			//cells[i].onclick = function() { return false; };
		}
	}
}

function tdOnMouseDown(ev) {
	if (this.checkBoxObj) {
		checkedValue = this.checkBoxObj.checked = !this.checkBoxObj.checked;
		document.onmouseup = function() {
			document.onmouseup = null;
			document.onselectstart = null;
			checkedValue = null;	
		};
		(this.checkBoxObj.checked == true) ? this.setAttribute("class", "tr2_border7") : this.setAttribute("class", "tr2_border")
		document.onselectstart = function() { return false; }; // for IE
	}
}

function tdOnMouseOver() {
	if (checkedValue != null && this.checkBoxObj) this.checkBoxObj.checked = checkedValue;
	if (this.checkBoxObj.checked == true) this.setAttribute("class", "tr2_border7"); else this.setAttribute("class", "tr2_border");
}
function mktime () {
    var no=0, i = 0, ma=0, mb=0, d = new Date(), dn = new Date(), argv = arguments, argc = argv.length;

    var dateManip = {
        0: function (tt){ return d.setHours(tt); },
        1: function (tt){ return d.setMinutes(tt); },
        2: function (tt){ var set = d.setSeconds(tt); mb = d.getDate() - dn.getDate(); d.setDate(1); return set;},
        3: function (tt){ var set = d.setMonth(parseInt(tt, 10)-1); ma = d.getFullYear() - dn.getFullYear(); return set;},
        4: function (tt){ return d.setDate(tt+mb);},
        5: function (tt){
            if (tt >= 0 && tt <= 69) {
                tt += 2000;
            }
            else if (tt >= 70 && tt <= 100) {
                tt += 1900;
            }
            return d.setFullYear(tt+ma);
        }
        // 7th argument (for DST) is deprecated
    };

    for (i = 0; i < argc; i++){
        no = parseInt(argv[i]*1, 10);
        if (isNaN(no)) {
            return false;
        } else {
            // arg is number, let's manipulate date object
            if (!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }
    for (i = argc; i < 6; i++) {
        switch (i) {
            case 0:
                no = dn.getHours();
                break;
            case 1:
                no = dn.getMinutes();
                break;
            case 2:
                no = dn.getSeconds();
                break;
            case 3:
                no = dn.getMonth()+1;
                break;
            case 4:
                no = dn.getDate();
                break;
            case 5:
                no = dn.getFullYear();
                break;
        }
        dateManip[i](no);
    }

    return Math.floor(d.getTime()/1000);
}

function date ( format, timestamp ) {
    var that = this;
    var jsdate=(
        (typeof(timestamp) == 'undefined') ? new Date() : // Not provided
        (typeof(timestamp) == 'object') ? new Date(timestamp) : // Javascript Date()
        new Date(timestamp*1000) // UNIX timestamp (auto-convert to int)
    ); // , tal=[]
    var pad = function (n, c){
        if ( (n = n + "").length < c ) {
            return new Array(++c - n.length).join("0") + n;
        } else {
            return n;
        }
    };
    var _dst = function (t) {
        // Calculate Daylight Saving Time (derived from gettimeofday() code)
        var dst=0;
        var jan1 = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
        var june1 = new Date(t.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
        var temp = jan1.toUTCString();
        var jan2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        temp = june1.toUTCString();
        var june2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
        var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);

        if (std_time_offset === daylight_time_offset) {
            dst = 0; // daylight savings time is NOT observed
        } else {
            // positive is southern, negative is northern hemisphere
            var hemisphere = std_time_offset - daylight_time_offset;
            if (hemisphere >= 0) {
                std_time_offset = daylight_time_offset;
            }
            dst = 1; // daylight savings time is observed
        }
        return dst;
    };
    var ret = '';
    var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday",
        "Thursday", "Friday", "Saturday"];
    var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
    var txt_months =  ["", "January", "February", "March", "April",
        "May", "June", "July", "August", "September", "October", "November",
        "December"];

    var f = {
        // Day
            d: function (){
                return pad(f.j(), 2);
            },
            D: function (){
                var t = f.l();
                return t.substr(0,3);
            },
            j: function (){
                return jsdate.getDate();
            },
            l: function (){
                return txt_weekdays[f.w()];
            },
            N: function (){
                //return f.w() + 1;
                return f.w() ? f.w() : 7;
            },
            S: function (){
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
            },
            w: function (){
                return jsdate.getDay();
            },
            z: function (){
                return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
            },

        // Week
            W: function (){

                var a = f.z(), b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;

                if (b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
                    return 1;
                } 
                if (a <= 2 && nd >= 4 && a >= (6 - nd)){
                    nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                    return that.date("W", Math.round(nd2.getTime()/1000));
                }
                
                var w = (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);

                return (w ? w : 53);
            },

        // Month
            F: function (){
                return txt_months[f.n()];
            },
            m: function (){
                return pad(f.n(), 2);
            },
            M: function (){
                var t = f.F();
                return t.substr(0,3);
            },
            n: function (){
                return jsdate.getMonth() + 1;
            },
            t: function (){
                var n;
                if ( (n = jsdate.getMonth() + 1) == 2 ){
                    return 28 + f.L();
                }
                if ( n & 1 && n < 8 || !(n & 1) && n > 7 ){
                    return 31;
                }
                return 30;
            },

        // Year
            L: function (){
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
            },
            o: function (){
                if (f.n() === 12 && f.W() === 1) {
                    return jsdate.getFullYear()+1;
                }
                if (f.n() === 1 && f.W() >= 52) {
                    return jsdate.getFullYear()-1;
                }
                return jsdate.getFullYear();
            },
            Y: function (){
                return jsdate.getFullYear();
            },
            y: function (){
                return (jsdate.getFullYear() + "").slice(2);
            },

        // Time
            a: function (){
                return jsdate.getHours() > 11 ? "pm" : "am";
            },
            A: function (){
                return f.a().toUpperCase();
            },
            B: function (){
                // peter paul koch:
                var off = (jsdate.getTimezoneOffset() + 60)*60;
                var theSeconds = (jsdate.getHours() * 3600) +
                                 (jsdate.getMinutes() * 60) +
                                  jsdate.getSeconds() + off;
                var beat = Math.floor(theSeconds/86.4);
                if (beat > 1000) {
                    beat -= 1000;
                }
                if (beat < 0) {
                    beat += 1000;
                }
                if ((String(beat)).length == 1) {
                    beat = "00"+beat;
                }
                if ((String(beat)).length == 2) {
                    beat = "0"+beat;
                }
                return beat;
            },
            g: function (){
                return jsdate.getHours() % 12 || 12;
            },
            G: function (){
                return jsdate.getHours();
            },
            h: function (){
                return pad(f.g(), 2);
            },
            H: function (){
                return pad(jsdate.getHours(), 2);
            },
            i: function (){
                return pad(jsdate.getMinutes(), 2);
            },
            s: function (){
                return pad(jsdate.getSeconds(), 2);
            },
            u: function (){
                return pad(jsdate.getMilliseconds()*1000, 6);
            },

        // Timezone
            e: function () {

                return 'UTC';
            },
            I: function (){
                return _dst(jsdate);
            },
            O: function (){
               var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
               t = (jsdate.getTimezoneOffset() > 0) ? "-"+t : "+"+t;
               return t;
            },
            P: function (){
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2));
            },
            T: function () {

                return 'UTC';
            },
            Z: function (){
               return -jsdate.getTimezoneOffset()*60;
            },

        // Full Date/Time
            c: function (){
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
            },
            r: function (){
                return f.D()+', '+f.d()+' '+f.M()+' '+f.Y()+' '+f.H()+':'+f.i()+':'+f.s()+' '+f.O();
            },
            U: function (){
                return Math.round(jsdate.getTime()/1000);
            }
    };

    return format.replace(/[\\]?([a-zA-Z])/g, function (t, s){
        if ( t!=s ){
            // escaped
            ret = s;
        } else if (f[s]){
            // a date function exists
            ret = f[s]();
        } else {
            // nothing special
            ret = s;
        }
        return ret;
    });
}
