/*

// ENTER TEXT BELOW. CAN *NOT* INCLUDE NORMAL HTML CODE.
var text='Ваш текст';

var delay=40; // SPEED OF TRAIL
var Xoff=0; // PIXEL COUNT FROM THE LEFT OF THE CURSOR (- VALUES GO TO LEFT)
var Yoff=-30; // PIXEL COUNT FROM THE TOP OF THE CURSOR (- VALUES GO UP)
var txtw=14; // AMOUNT OF PIXEL SPACE EACH CHARACTER OCCUPIES
var beghtml='<font color="blue"><b>'; // OPTIONAL HTML CODE THAT EFFECTS WHOLE TEXT STRING SUCH AS FONT COLOR, SIZE, ETC.
var endhtml='</b></font>'; // END HTML CODE. MOSTLY USED IF ABOVE SETTING IS USED.

//********** NO NEED TO EDIT BELOW HERE **********\\

ns4 = (navigator.appName.indexOf("Netscape")>=0 && document.layers)? true : false;
ie4 = (document.all && !document.getElementById)? true : false;
ie5 = (document.all && document.getElementById)? true : false;
ns6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var txtA=new Array();
text=text.split('');
var x1=0;
var y1=-1000;
var t='';

for(i=1;i<=text.length;i++){
t+=(ns4)? '<layer name="txt'+i+'" top="-100" left="0" width="'+txtw+'" height="1">' : '<div id="txt'+i+'" style="position:absolute; top:-100px; left:0px; height:1px; width:'+txtw+'; visibility:visible;">';
t+=beghtml+text[i-1]+endhtml;
t+=(ns4)? '</layer>' : '</div>';
}
document.write(t);


function moveid(id,x,y){
if(ns4)id.moveTo(x,y);
else{
id.style.left=x+'px';
id.style.top=y+'px';
}}

function animate(evt){
x1=Xoff+((ie4||ie5)?event.clientX+document.body.scrollLeft:evt.pageX);
y1=Yoff+((ie4||ie5)?event.clientY+document.body.scrollTop:evt.pageY);
}

function getidleft(id){
if(ns4)return id.left;
else return parseInt(id.style.left);
}

function getidtop(id){
if(ns4)return id.top;
else return parseInt(id.style.top);
}

function getwindowwidth(){
if(ie4||ie5)return document.body.clientWidth+document.body.scrollLeft;
else return window.innerWidth+pageXOffset;
}

function movetxts(){
for(i=text.length;i>1;i=i-1){
if(getidleft(txtA[i-1])+txtw*2>=getwindowwidth()){
moveid(txtA[i-1],0,-1000);
moveid(txtA[i],0,-1000);
}else moveid(txtA[i], getidleft(txtA[i-1])+txtw, getidtop(txtA[i-1]));
}
moveid(txtA[1],x1,y1);
}

window.onload=function(){
for(i=1;i<=text.length;i++)txtA[i]=(ns4)?document.layers['txt'+i]:(ie4)?document.all['txt'+i]:document.getElementById('txt'+i);
if(ns4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=animate;
setInterval('movetxts()',delay);
}


*/
function switchElement(viewEl, notviewEl) {
	document.getElementById(viewEl).style.display='';
	document.getElementById(notviewEl).style.display='none';
}

function readyToSubmit(str_id) {
	   str =  document.getElementById(str_id).value;
	   str = str.replace(/\n/g, '<br>');
	   str = str.replace(/\+/g, '~plus~');  
	   str = str.replace(/\`/g, '\"');  
	   str = str.replace(/\&/g, '~amp~');
	   return str;
}




var parent = document.getElementsByTagName('BODY')[0];
var IDW = 'myPId';

function Chek_input_news() {
    str_login =    /^[^\`]+$/;
    str = '';
    if (!str_login.test(document.getElementById("newTema").value))
        str = "Вы наверное забыли ввести заголовок статьи.\n";
    if (!str_login.test(document.getElementById("page").value))
        str = "Вы наверное забыли ввести текст статьи.\n";
    if (document.getElementById("Tema_select").value == '0')
        str = "Вы забыли ввести тему для этой статьи.\n";
    if ((document.getElementById("Tema_select").value == '1') && 
       (document.getElementById("CountrySelect").value == '0'))
    	str = "Вы забыли ввести страну для которой описана эта река.\n";
    if (str != "") {
         alert(str);
         return false;
    }
    document.ff_form50.submit();   //Tema_select
    return true;
}
function Menu_podmenu_veiw(ono) {  
	if (document.getElementById("podmenu").style.display == 'none') {
        document.getElementById("podmenu").style.display='';
        ono.src = 'images/arr_4.png';
	}
    else {
    	document.getElementById("podmenu").style.display='none';
    	ono.src = 'images/arr_3.png';
    }
}
function AddNewCountry() {
	if (document.getElementById("CountrySelect").value == 'Add') 
		document.getElementById("InpunNewCount").style.display = 'block';
	else document.getElementById("InpunNewCount").style.display = 'none';
}

function Check_spase_cont() { 
	str_content =  /^[^\`]+$/;
	str = ''; 
    if (!str_content.test(document.getElementById("cont_id").value))
        str = "Вы наверное забыли ввести коментарий или использовали запрещенные символы.\n";
    if (str != "") {
        alert(str);
        return false;
   }
   document.getElementById("comentBox").style.display = "none";
   document.getElementById("cont_id").value = readyToSubmit("cont_id");
   return true;
}
function Check_spase_contMB_comment() {   
	str_content =  /^[^\`]+$/;
	str = ''; 
    if (!str_content.test(document.getElementById("cont_idMB").value))
        str = "Вы наверное забыли ввести коментарий или использовали запрещенные символы.\n";
    if (!str_content.test(document.getElementById("NameUser").value))
        str = str + "Вы не ввели Имя.\n";
    if (str != "") {
        alert(str);
        return false;
   }
    document.getElementById("comentBoxMB").style.display = "none";
    str1_e = readyToSubmit("cont_idMB")+'`'+readyToSubmit("NameUser");
    

   document.getElementById("my_elemAJAXMBcom").value = document.getElementById("my_elemAJAXMBcom").value+'`'+str1_e;
   return true;
}
function Check_spase_contMB_Email() {  
	str_content =  /^[^\`]+$/;
	str_email = /^([:?a-z0-9A-Z_\.\-])+([:?@]){1,1}([:?a-z0-9A-Z\.\-])+\.([:?a-z0-9A-Z\.\-]{2,4})$/;
	str = ''; 
    if (!str_content.test(document.getElementById("cont_idMBE").value))
        str = "Вы наверное забыли ввести текст письма, или использовали запрещенные символы.\n";
    if (!str_content.test(document.getElementById("NameUserE").value))
        str = str + "Вы не ввели Имя.\n";
    if (!str_email.test(document.getElementById("emailUser").value))
        str = str + "Вы не правильно ввели е-mail.\n";
    if (str != "") {
        alert(str);
        return false;
   }
   switchElement('alert_messages', 'comentBoxMB_E');
   str1_e = readyToSubmit("cont_idMBE")+'`'+readyToSubmit("NameUserE"); //alert(str1_e);
   document.getElementById("my_elemAJAXMBcomE").value = document.getElementById("my_elemAJAXMBcomE").value+'`'+str1_e+'`'+document.getElementById("emailUser").value;
   //alert( document.getElementById("my_elemAJAXMBcomE").value);
   return true;
}
function Check_message_board() {
	str_content =  /^[^\`]+$/;
	str = ''; 
    if (!str_content.test(document.getElementById("NameUser").value))
        str = "Вы наверное забыли ввести Ваше имя.\n";
    if (!str_content.test(document.getElementById("covername").value))
        str = str + "Вы наверное забыли ввести заголовок вашего объявления.\n";  
    if (!str_content.test(document.getElementById("cont_id").value))
        str = str + "Вы наверное забыли ввести текст для вашего объявления.\n"; 
    if (str != "") {
        alert(str);
        return false;
   } 
   document.getElementById("cont_id").value = readyToSubmit("cont_id");  
   document.getElementById("covername").value = readyToSubmit("covername");
   document.getElementById("NameUser").value = readyToSubmit("NameUser");
   document.ff_form70.submit(); 
}




function uplodemoreFileplus(id, maxcount, ihave_pic) {
	document.getElementById("fileblock".concat(id)).style.display = '';
	if (id > maxcount-2) document.getElementById("more_file1").style.display = 'none';
	if (id > ihave_pic) document.getElementById("more_file2").style.display = '';
}
function uplodemoreFileminus(id, maxcount, ihave_pic) {
    document.getElementById("fileblock".concat(id)).style.display = 'none';
	if (id < maxcount) document.getElementById("more_file1").style.display = '';
	if ((id) == ihave_pic+1) document.getElementById("more_file2").style.display = 'none';
}
/*

function Check_spase_WOC() {
   str = "";
    str_login = /^[(:?A-Za-z\d)]+$/;
    str_cap   = /^[(:?\d)]+$/;
    if (!str_login.test(document.getElementById("mod_login_username").value))
        str = "Логин может содержать только символы латинского алфавита и цифры. \n";
    if (!str_login.test(document.getElementById("mod_login_password").value))
        str = str+"Пароль может содержать только символы латинского алфавита и цифры. \n";
    if ((Capa_Ajax) && (!str_cap.test(document.getElementById("capcha_id").value))) {
       str = str+"Введите пожалуйсто цифирки с картинки. \n";
    }
    if (str != "") {
         alert(str);
         return false;
    }
    document.getElementById("my_elemAJAX").value =
    document.getElementById("mod_login_username").value+"`"+
    document.getElementById("mod_login_password").value+"`"+
    document.getElementById("mod_login_remember").checked;
    document.ff_form51.submit();
    return true;
}
function Check_spase_Cap() {
    str = "";
    str_login = /^[(:?A-Za-z\d)]+$/;
    str_cap   = /^[(:?\d)]+$/;
    if (!str_login.test(document.getElementById("mod_login_username").value))
        str = "Логин может содержать только символы латинского алфавита и цифры. \n";
    if (!str_login.test(document.getElementById("mod_login_password").value))
        str = str+"Пароль может содержать только символы латинского алфавита и цифры. \n";
    if ((Capa_Ajax) && (!str_cap.test(document.getElementById("capcha_id").value))) {
       str = str+"Введите пожалуйсто цифирки с картинки. \n";
    }
    if (str != "") {
         alert(str);
         return false;
    }
    document.getElementById("my_elemAJAX").value =
    document.getElementById("mod_login_username").value+"`"+
    document.getElementById("mod_login_password").value+"`"+
    document.getElementById("mod_login_remember").checked+"`"+
    document.getElementById("capcha_id").value;
    document.ff_form51.submit();
    return true;
}*/
function fill_main_win() {
	document.getElementById("MainScreen").innerHTML = '';
}


function view_question () {
	document.getElementById("button_question").style.display = "none";
	document.getElementById("question_area").style.display = "block";
}
function view_new_tema () {
	document.getElementById("button_new_tema").style.display = "none";
	document.getElementById("new_tema_area").style.display = "block";
}
function view_new_tema_back() {
	document.getElementById("button_new_tema").style.display = "block";
	document.getElementById("new_tema_area").style.display = "none";
}
function My_fun() {
	parent.removeChild(document.getElementById(IDW));
	IDW = 'myPId';
}
function my_window_button(param) {
	if (IDW != 'myPId') {
		alert('Не надо пытаться открыть много окон, открыл посмотрел закрой.');
		return;
	}
	//alert(param);
    var WW = 200;
    var HW = 200;
    var TB = 'Ok';
    var TW = '100';
    var text = "текст для вставки";
    if (param) {
    	for (key in param) {
    		if (param[key] == 'WWin') WW = param[((Number(key)+Number(1)))];
    		if (param[key] == 'HWin') HW = param[((Number(key)+Number(1)))];
    		if (param[key] == 'TBut') TB = param[((Number(key)+Number(1)))];
    		if (param[key] == 'TWid') TW = param[((Number(key)+Number(1)))];
    		if (param[key] == 'IDPar') parent = document.getElementById(param[Number(key)+Number(1)]);
    		if (param[key] == 'text') text = document.getElementById(param[((Number(key)+Number(1)))]).innerHTML;
    		if (param[key] == 'IDWin') IDW = param[Number(key)+Number(1)];
    	}
    }
    for (i=0; i < parent.childNodes.length; i++)
    	if (parent.childNodes[i].id == IDW) {
    		parent.removeChild(document.getElementById(IDW));
    		return;
    	}
    var newP = document.createElement('div');
    newP.id = IDW;
    newP.style.width = String(WW).concat('px');
    if (navigator.appName=="Microsoft Internet Explorer"){
    	newP.style.height = String(Number(HW)+20).concat('px');
    }
    else
       newP.style.height = String(HW).concat('px');
    newP.style.background = '#c5c5c5';//'#B2C9F3';//;'#0077AA';
    newP.style.border = '#0077AA solid 1px';  //#333399
    newP.style.borderTop = '#0077AA solid 20px';
    newP.style.color = '#000';
    newP.style.position="absolute";
    newP.style.textAlign = 'center';
    newP.style.padding = '0';
    newP.style.margin = '0';
    var WinCoordX = String((window.screen.width-WW-14)/2);
    var WinCoordY = String((screen.availHeight-HW-400-40)/2);
    newP.style.left = WinCoordX.concat("px");
    newP.style.top = WinCoordY.concat("px");

    var box =  document.createElement('div');
    box.style.position="absolute";
    box.style.left = '10px';
    box.style.top  = '15px';
    box.style.width  = String(Number(WW)-20).concat('px');
    box.style.height = String(Number(HW)-70).concat('px');
    box.style.border = '1px solid black';
    box.style.background = '#eeeeee';
    newP.appendChild(box);

    var textNode =  document.createElement('div');
    textNode.innerHTML = text;
    box.appendChild(textNode);

    var button = document.createElement('input');
    button.className = 'button';
    button.setAttribute('value', TB);
    button.style.width = TW.concat('px');
    button.style.position="absolute";
    button.style.top = String(Number(HW)-Number('40')).concat('px');
    button.style.left = String(Number(Number(WW)/2)-Number(Number(TW)/2)).concat('px');
    if (navigator.appName=="Microsoft Internet Explorer")
        button.setAttribute("onclick",function(){My_fun();});
     else
        button.setAttribute("onclick", 'My_fun();');
    button.type = "button";
    newP.appendChild(button);
    parent.appendChild(newP);
}
function ff_trim(s)
{
	var n = s.length;
	if (n == 0) return '';
	var b = 0;
	var ws = ' \r\n\t';
	while (b<n && ws.indexOf(s.charAt(b))>=0) b++;
	if (b == n) return '';
	while (ws.indexOf(s.charAt(n-1))>=0) n--;
	return s.substring(b,n);
} // ff_trim

function my_redirect(url)
{
	var target = 'self';
	if (arguments.length>1) target = arguments[1].toLowerCase();
	var method = 'post';
	if (arguments.length>2) method = arguments[2].toLowerCase();
	switch (method) {
		case 'get':
			switch (target) {
				case 'top':
					top.location.href = url;
					break;
				case 'parent':
					parent.location.href = url;
					break;
				default: // self
					document.location.href = url;
			} // switch
			break;
		default: { // post
			var f = document.createElement('form');
			var pos = url.indexOf('?');
			var params = new Array();
			if (pos < 0) {
				f.action = url;
			} else {
				f.action = url.substring(0, pos);
				var pms = url.substring(pos+1, url.length).split('&');
				for (var p = 0; p < pms.length; p++) {
					var pm = pms[p].split('=');
					var prop = '';
					if (pm.length > 0) prop = ff_trim(pm[0]);
					var val = '';
					if (pm.length > 1) val = ff_trim(unescape(pm[1]));
					if (prop!='' && val!='') params[params.length] = new Array(prop, val);
				} // for
			} // if
			f.name = 'ff_redirect';
			f.method = 'post';
			f.enctype = 'multipart/form-data';
			switch (target) {
				case 'blank' : f.target = '_blank';  break;
				case 'top'   : f.target = '_top';    break;
				case 'parent': f.target = '_parent'; break;
				default      : f.target = '_self';
			} // switch
			var p;
			for (p = 0; p < params.length; p++) {
				var e = document.createElement('input');
				e.type = 'hidden';
				e.name = params[p][0];
				e.value = params[p][1];
				f.appendChild(e);
			} // for
			document.body.appendChild(f);
			f.submit();
		} // post
	} // switch
} // ff_redirect
