var RectMarquee = false;
var changeTitle = false;
var chTitleInt = false;
var docTitle = document.title;

function changeTitleFunct(title) {
	if (document.title == title) {
		document.title = '***Новое сообщение***';
	} else {
		document.title = title;
	}
	changeTitle = 0;	
}

function onMarqueeUpdate() {
	var coords = RectMarquee.getCoords();
	$('coord_x').value = coords.x1;
	$('coord_y').value = coords.y1;
	$('coord_width').value = coords.width;
}
function initLoad(type) {
	if(RectMarquee) {
		$('rmt_landing_'+RectMarquee.activeId).parentNode.removeChild($('rmt_landing_'+RectMarquee.activeId));
		RectMarquee = false;
	}
		
	RectMarquee = new Marquee('loadedImage', {color: '#FFF', opacity: 0.45});
	RectMarquee.file = type;
	RectMarquee.accessHotKeys(false);
	switch(type) {
		case 'user':
			RectMarquee.setCoords(0, 0, 150, 150);
			break;
		case 'albums':
			RectMarquee.setCoords(0, 0, 210, 140);
			break;
		case 'video':
			RectMarquee.setCoords(0, 0, 400, 300);
			break;
	}
	
	onMarqueeUpdate();	
	RectMarquee.setOnUpdateCallback(onMarqueeUpdate);
}

function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
}

function randomString(lenght) {
	var string = '';
	for(i = 0; i < lenght; i++) {
		string += Math.round(Math.random()*1000);
	}
	return string;
}

function changeClassName(objId) {
    obj = $(objId);
    obj.style.display=='block'?obj.style.display='none':obj.style.display='block';
    if (objId == "interest_input" && obj.style.display=="block") $("tag_input").focus();
    if (objId == "fs_newcomment" && obj.style.display=="block") $("msgs").focus();
    if (objId == "fieldsetwall" && obj.style.display=="block") $("note").focus();
    if (objId == "user_add_info" && obj.style.display=="block") $("link_more_info").innerHTML = "скрыть подробности";
    if (objId == "user_add_info" && obj.style.display=="none") $("link_more_info").innerHTML = "подробнее";
    return false;
}
function showHideText(objId) {
	if ($(objId).innerHTML == "скрыть") $(objId).innerHTML = "показать";
		else $(objId).innerHTML = "скрыть";
}

function setCitateToTextArea(containeId, taId, formId, strClass) {
    objContainer = $(containeId);
    objTa = $(taId);
    objForm = $(formId);
    if (document.selection) {
        var range = document.selection.createRange();
        selText = range.text;
    } else {
        selText = document.getSelection();
    }
    
    if (objContainer && objTa && objForm) {
        	inText = objContainer.innerText ? objContainer.innerText : objContainer.textContent;
        	if(selText.length && inText && inText.indexOf(selText) != -1) {
				txt = '<q>' + selText + '</q>';
        	}
        	else {
        		txt = '<q>' + objContainer.innerHTML + '</q>';
        	}
        	
        objForm.className = strClass;           
       	insert_tag(taId, txt, '');
    }
    return false;
}

var nLastFormId = 0;
function cmntAdd(id) {
	if($('cmnt_links' + nLastFormId)) {
        divLinks = $('cmnt_links' + nLastFormId);
        divPlace = $('cmnt_place' + nLastFormId);
       	divPlace.innerHTML = '';
        divLinks.style.display = 'block';
    }
    nLastFormId = id;
    $('action').value = 'add';
    $('msg_id').value = id;
    $('fs_newcomment').style.display = 'none';
    
    divLinks = $('cmnt_links' + id);
    divPlace = $('cmnt_place' + id);
    strForm = '<div class="frm2"><fieldset><div class="input"><div id="newcomment_msg_err" class="hide"></div><textarea name="msg" id="msg" onkeypress="return sendComment(event, \'msg\')"></textarea></div><div class="input"><input type="submit" class="btn100" value="Ответить" /> <input type="button" class="btn75gray" value="Отмена" onclick="cmntAdd(0)"/></div></fieldset></div>';
    if(divLinks) {
    	divLinks.style.display = 'none';
   		divPlace.innerHTML = strForm;
    }
    if($("msg")) $("msg").focus();
    return false;
}

site_id = 0;
phone_id = 0;
mail_id = 0;
mesg_id = 0;

function contactAdd(type) {    
    if(type == 'site'){
	    divPlace = $(type +'_place' + site_id);
	    site_id++;
	    id = site_id; 
		strText = '<label for="link' + id + '">Ссылка:</label><input type="text" name="link' + id + '">&nbsp;<label for="site' + id + '">Название:</label><input type="text" name="site' + id + '">&nbsp;<label for="nickname' + id + '">Ник:</label><input type="text" name="nickname' + id + '"><div id="'+ type +'_place' + id + '"></div>';
    }
	if(type == 'phone'){
		divPlace = $(type +'_place' + phone_id);
	    phone_id++;
	    id = phone_id; 
		strText = '<label for="number' + id + '">Номер:</label><input type="text" name="number' + id + '">&nbsp;<label for="phone' + id + '">Название:</label><input type="text" name="phone' + id + '"><div id="'+ type +'_place' + id + '"></div>';	 
    }
	if(type == 'mail'){
		divPlace = $(type +'_place' + mail_id);
	    mail_id++;
	    id = mail_id; 
		strText = '<label for="mail' + id + '">Почта:</label><input type="text" name="mail' + id + '"><div id="'+ type +'_place' + id + '"></div>';
    }
    if(type == 'mesg'){
	    divPlace = $(type +'_place' + mesg_id);
	    mesg_id++;
	    id = mesg_id; 
		strText = '<label for="mesg_id' + id + '">Номер:</label><input type="text" name="mesg_id' + id + '">&nbsp;<label for="mesg' + id + '">Название:</label><input type="text" name="mesg' + id + '"><div id="'+ type +'_place' + id + '"></div>';
    }
            
    if(id == 1){
    	strForm = '<fieldset>' + strText + '<input type="submit" value="Сохранить" /></fieldset>';
    }else{
    	strForm = strText; 
    }    
    divPlace.innerHTML = strForm;
    return false;
}

function changeSubmit(type){
	globalSubmitName = type; 
}

function bodyResized() {
    objScreen = $('screen');
    if (objScreen) {
        objScreen.style.width = '1px';
        objScreen.style.height = '1px';
        scrl = getScrollSize();
        objScreen.style.width = scrl[0] + 'px';
        objScreen.style.height = scrl[1] + 'px';
    }
}

function showPreviewLoad(type, index) {
    if(type == 'file'){
        $('previewFile_'+index).style.display = $('previewTimeLink_'+index).style.display = 'block';
        $('previewTime_'+index).style.display = $('previewFileLink_'+index).style.display = 'none';
        $('previewTime_'+index).value='';
    } else if(type == 'time'){
        $('previewFile_'+index).style.display = $('previewTimeLink_'+index).style.display = 'none';
        $('previewTime_'+index).style.display = $('previewFileLink_'+index).style.display = 'block';
        $('preview_'+index).innerHTML='';
    }
}

function changeVpath(){
    var title = $('title').value.toLowerCase();
    var cyrilicCharacters = "їєабвгдеёзийклмнопрстуфхъыэжцчшщьюя";
    var latinCharacters = ['i', "ie", 'a', 'b', 'v', 'g', 'd', 'e', 'e', 'z', 'i', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', '', 'i', 'e', "zh", "ts", "ch", "sh", "shch", "", "yu", "ya"];
    var pos = 0;
    var Vpath = "";                
    for( i = 0; i < title.length; i++ ){    
    	var char = title.substr(i, 1);	
        var pos = cyrilicCharacters.indexOf( char );
        if( pos != -1 ) {
            Vpath = Vpath + latinCharacters[pos];
        } else {
            Vpath = Vpath + char;
        }
    }                    
    var re = /[^a-z0-9_]+/gi;
    $('virtual_path').value = Vpath.replace(re, '-');
}

function sendMessage(evt, ajax) {
	if((evt.ctrlKey) && ((evt.keyCode == 0xA)||(evt.keyCode == 0xD))) {
		if(document.new_msg_form.new_msg_text.value != '') {
			if(ajax) {
				return sendFormRequest(document.new_msg_form, 'ajax/chat.php', handlerMessages);
			} else {
				return sendFormRequest(document.new_msg_form, 'controllers/user/messages.php', handlerMessages);
			}
		}
	} else {
		return true;
	}
}

function showPopupMessages (uid, id, act, width, height) {
	url = 'http://vpodzemke.ru/user/' + uid + '/messages/' + id + '.html?act='+act;
	popupWindow = window.open(url, 'user'+id, 'location=0,menubar=0,resizable=0,scrollbars=0,fullscreen=0,status=0,titlebar=0,toolbar=0,width='+width+',height='+height);
	if(act == 'popup') {
		window.location.href = 'http://vpodzemke.ru/user/' + uid + '/messages.html';
	}
	return false;
}
function showPopupChat (width, height) {
	url = 'http://vpodzemke.ru/chat.html';
	popupWindow = window.open(url, "", 'location=0,menubar=0,resizable=1,scrollbars=0,fullscreen=0,status=0,titlebar=0,toolbar=0,width='+width+',height='+height);
	return false;
}


function startUploadVideoFile(){
	$('btnSave').disabled = true;
}

function makeFileTitle (input, num) {
	if($('title_'+num).value.length == 0) {
		var title = input.value.substring(input.value.lastIndexOf('\\') + 1, input.value.lastIndexOf('.') );
		$('title_'+num).value = title;
	}
}

function prepareVideoForm (input) {
	makeFileTitle(input, 0);
	$('btnSave').disabled = false;
}

function showOriginalImage(id, width, height) {
	if(!$('org_img')){
		var img = document.createElement('img');
		img.src = '/files/foto/original/' + id + '.jpg';
		img.id	=  'org_img';
		if(width > 900) {
			img.width = 900;
			img.height = 900/width * height;
		}
		$('originalimageinner').appendChild(img);
	}
	

	getTopForPopup('originalimage');
	showPopup('originalimage');
	if($('org_img').clientHeight > $('screen').clientHeight) {
		$('screen').style.height = $('org_img').clientHeight + $('originalimage').offsetTop + 50 + 'px';
	} 
	return false;
}

function showInsertCode(objType, objId) {
	if(!$('insert_code')) {
		var code = ''; 
		switch(objType) {
			case 'img':
				code = '<a href="'+window.location.protocol+'//'+window.location.host+window.location.pathname+'?pid='+objId+'"> '
					 + '<img src="http://'+window.location.host+'/files/foto/big/' + objId + '.jpg" alt="" border="0" /> </a>';
				break;
		}
		ta = document.createElement('textarea');
		ta.id = 'insert_code';
		ta.rows = 5;
		ta.cols = 24;
		ta.style.fontSize = "12px";
		ta.value = code;
		ta.readOnly = true;
		ta.style.display = 'block';
		$('links').appendChild(ta);
	} else {
		changeClassName('insert_code');
	}
	return false;	
}

function changeBlogInput(val) {
	if(!val) {
		$('blog_message').style.display='block';
		$('load_object').style.display=$('blog_title').style.display='none';
	} else {
		switch(parseInt(val)) {
			case 0:
				$('blog_message').style.display='block';
				$('load_object').style.display=$('blog_title').style.display='none';
				if($('loadVideo')) $('loadVideo').style.display='none';
			case 1:
				$('blog_message').style.display='block';
				$('load_object').style.display=$('blog_title').style.display='none';
				if($('loadVideo')) $('loadVideo').style.display='none';
			break;
			case 2:
				$('blog_message').style.display='none';
				$('newBlogFile').innerHTML = '';
				$('load_object').style.display=$('blog_title').style.display='block';
				if($('loadVideo')) $('loadVideo').style.display='none';
			break;
			case 3:
				$('load_object').style.display=$('blog_message').style.display='none';
				$('newBlogFile').innerHTML = '';
				$('blog_title').style.display='block';
				if($('loadVideo')) $('loadVideo').style.display='block';
			break;/*
			case 4:
				swfu = new SWFUpload(videoSettings); 
				swfu2 = new SWFUpload(photoSettings); 
				$('blog_message').style.display='none';
				$('load_object').style.display=$('blog_title').style.display='block';
				*/
			break;
		}
	}
}

function preparePostForm() {
	ed = tinyMCE.get('anons');
	$('anons').value = ed.getContent();
	ed = tinyMCE.get('text');
	$('text').value = ed.getContent();
}

var numFields=0;
var selectedField=0;
var userTag;
var mouseSelect = 0;

function selectTagsList(evt) {
	mouseSelect = 0;
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode == 38) {
		if (numFields) {
			if (selectedField == 0) {
				selectTag(numFields);
			} else {
				selectTag (selectedField - 1);
			}
		}
		return false;
	} else if (charCode == 40) {
		if (numFields) {
			if (numFields == selectedField) {
				selectTag(0);
			} else {
				selectTag (selectedField + 1);
			}
		}
		return false;
	} else if (charCode == 13) {
		if(selectedField > 0){
			if($('epsent_int')) {
				$('epsent_int').style.display='none';
			}
			saveTag($('field_'+selectedField).innerHTML, $('field_'+selectedField).name);
			return false;
		} else if(!$('search_people')) {
			return saveTag($('tag_input').value, 0);
		} else {
			if($('tag_select')) {
				for(key in $('tag_select').childNodes){
					child = $('tag_select').childNodes[key];
					if(child.id) {
						if(child.innerHTML.toLowerCase()==$("tag_input").value.toLowerCase()){
							selectedField = child.id.substr(child.id.indexOf('_')+1);
							if($('epsent_int')) {
								$('epsent_int').style.display='none';
							}
							saveTag($('field_'+selectedField).innerHTML, $('field_'+selectedField).name);
							return false;
						}
					}
				}
			}			
			if($('epsent_int')) {
				$('epsent_int').style.display='block';
			}
			return false;
		}
	} else if (!selectedField) {
		var userTag = $("tag_input").value;
		/*
		var tagSelect = $('tags_list').innerHTML;
		var regEx = new RegExp("saveTag\\('"+userTag+"'\\, (\\d*)\\)", 'gi');
		var match = regEx.exec(tagSelect); 
		if(match) {
			saveTag(userTag, match[1]);
			return false;
		}
		*/
	}
	
	var findStr = $("tag_input").value;
	if (findStr.length > 0) {
		sendRequest ('POST', 'ajax/select_tags.php', 'q=' + myEscape(findStr), handlerSelectTags);
	} else {
		hideSelectTagsList ();	
	}
}

function saveTag(name, id) {
	if(!$('selectedTags') && $('tags_interests_list')) {
		$("tag_input").value = name;
		hideSelectTagsList ();
		return sendRequest('post', 'controllers/interest.php', 'action=add&tag='+myEscape($('tag_input').value)+'&url='+window.location, handlerManageTags, true);
	} else if ($('selectedTags') && !$('tags_interests_list') && name.length > 0) {
		if(id > 0){		
			hideSelectTagsList ();
			$('epsent_int').style.display='none';
			$("tag_inp").style.display = 'none';
			$("tag_input").value = '';
			$('tag_input').name = "";
			reg = new RegExp('\>'+name+' \<a','gi');
			var present = $('selectedTags').innerHTML.search(reg);
			if(present == -1){
				newLi = document.createElement('li');
				newLi.id = 'selectedInterest_'+id;
				newLi.innerHTML = name+' ';
				delLink = document.createElement('a');
				delLink.href="#";
				delLink.onclick = function() {
									return delSelectedTag(this.parentNode.id);
								};
				delLink.innerHTML = 'x';
				delLink.title = 'Удалить';
				newLi.appendChild(delLink);		 
				$('selectedTags').appendChild(newLi);
				$('interests_ids').value += id+',';
			}		
			return false;
		} else if($('tag_select')) {
			for(key in $('tag_select').childNodes){
				child = $('tag_select').childNodes[key];
				if(child.id) {
					if(child.innerHTML.toLowerCase()==$("tag_input").value.toLowerCase()){
						selectedField = child.id.substr(child.id.indexOf('_')+1);
						if($('epsent_int')) {
							$('epsent_int').style.display='none';
						}
						saveTag($('field_'+selectedField).innerHTML, $('field_'+selectedField).name);
						return false;
					}
				}
			}
		} else if($('epsent_int')) {
			$('epsent_int').style.display='block';
		}
		
	} else if ( $('selectedTags') && !$('tags_interests_list') && (name.length = 0 || !id) && $('epsent_int')) {
		$('epsent_int').style.display='block';
	}
}

function selectTag(field, mSel) {
	if(mouseSelect || !mSel) {
		for (var i=1;i<=numFields;i++) {
			if (i == field) $('field_'+i).className="selectOn";
				else $('field_'+i).className="selectOff";
		}
		if (field>0) {
			$('tag_input').value = $('field_'+field).innerHTML;	
			$('tag_input').name = $('field_'+field).name;	
		} else {
			$('tag_input').value = userTag;
			$('tag_input').name = "";
		}  
		selectedField = field;
	}
}

function deselectTag(field) {
	$('field_'+field).className="selectOff";
}

function hideSelectTagsList () {
	setTimeout('hideSelectTagsList2()', 200);
}

function hideSelectTagsList2 () {
	$("tags_list").style.display = 'none';
	numFields = selectedField = 0;
}

/***Статус***/
var numStatus=0;
var selectedStatus=0;
var userStatus;
var mouseSelectStatus = 0;

function selectStatusList(evt) {
	mouseSelectStatus = 0;
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode == 38) {
		if (numStatus) {
			if (selectedStatus == 0) {
				selectStatusTag(numStatus);
			} else {
				selectStatusTag(selectedStatus - 1);
			}
		}
		return false;
	} else if (charCode == 40) {
		if (numStatus) {
			if (numStatus == selectedStatus) {
				selectStatusTag(0);
			} else {
				selectStatusTag(selectedStatus + 1);
			}
		}
		return false;
	} else if (charCode == 13) {
		if(selectedStatus > 0){
			if($('epsent_status')) $('epsent_status').style.display='none';
			saveStatus($('s_field_'+selectedStatus).innerHTML, $('s_field_'+selectedStatus).name);
			return false;
		} else if(!$('search_people')) {
			return saveStatus($('status_input').value, 0);
		} else {
			if($('status_select')) {
				for(key in $('status_select').childNodes){
					child = $('status_select').childNodes[key];
					if(child.id) {
						if(child.innerHTML.toLowerCase()==$("status_input").value.toLowerCase()){
							selectedStatus = child.id.substr(child.id.lastIndexOf('_')+1);
							if($('epsent_status')) $('epsent_status').style.display='none';
							saveStatus($('s_field_'+selectedStatus).innerHTML, $('s_field_'+selectedStatus).name);
							return false;
						}
					}
				}
			}
			if($('epsent_status')) $('epsent_status').style.display='block';
			return false;
		}
	} else if (!selectedStatus) {
		userStatus = $("status_input").value;
		if($('status_id')) $('status_id').value = '';
		var statSelect = $('status_list').innerHTML;
		var regEx = new RegExp("saveStatus\\('"+userStatus+"'\\, (\\d*)\\)", 'gi');
		var match = regEx.exec(statSelect); 
		if(match) {
			saveStatus(userStatus, match[1]);
			return false;
		}
	}
	var findStr = $("status_input").value;
	if (findStr.length > 0) {
		sendRequest ('POST', 'ajax/select_status.php', 'q=' + myEscape(findStr), handlerSelectStatus);
	} else {
		if($('status_id')) $('status_id').value = '';
		hideSelectStatusList ();	
	}
}

function saveStatus(name, id) {
	if(!$('search_people') && $('tags_status_list')) {
		$("status_input").value = name;
		hideSelectStatusList ();
		return sendRequest('post', 'controllers/status.php', 'action=add&status='+myEscape($('status_input').value), handlerManageStatus, true);
	} else if ($('search_people') && !$('tags_status_list') && name.length > 0) {
		if(id > 0){		
			hideSelectStatusList ();	
			$("epsent_status").style.display = 'none';
			$("status_input").value = name;
			$('status_id').value = id;
			return false;
		} else if($('status_select')) {
			for(key in $('status_select').childNodes){
				child = $('status_select').childNodes[key];
				if(child.id) {
					if(child.innerHTML.toLowerCase()==$("status_input").value.toLowerCase()){
						selectedStatus = child.id.substr(child.id.indexOf('_')+1);
						if($('epsent_status')) {
							$('epsent_status').style.display='none';
						}
						saveStatus($('s_field_'+selectedStatus).innerHTML, $('s_field_'+selectedStatus).name);
						return false;
					}
				}
			}
		} else if($('epsent_status')) {
			$('epsent_status').style.display='block';
		}		
	} else if ( $('search_people') && !$('tags_status_list') && (name.length = 0 || !id) && $('epsent_status')) {
		$('epsent_status').style.display='block';
	}
}		

function selectStatusTag(field, mSel) {
	if(mouseSelectStatus || !mSel) {
		for (var i=1;i<=numStatus;i++) {
			if (i == field) $('s_field_'+i).className="selectOn";
				else $('s_field_'+i).className="selectOff";
		}
		if (field>0) {
			$('status_input').value = $('s_field_'+field).innerHTML;	
			$('status_input').name = $('s_field_'+field).name;	
		} else {
			$('status_input').value = userStatus;
			$('status_input').name = "";
		}  
		selectedStatus = field;
	}
}

function deselectStatus(field) {
	$('s_field_'+field).className="selectOff";
}

function hideSelectStatusList () {
	setTimeout('hideSelectStatusList2()', 200);
}

function hideSelectStatusList2 () {
	$("status_list").style.display = 'none';
	numStatus = selectedStatus = 0;
}
/***------***/

function selectMetropoliten (id, addst) {
	if(!addst) addst = 0;
	if (id) sendRequest ('POST', 'ajax/select_metropoliten.php', 'id=' + id + '&addst=' + addst, handlerSelectMetropoliten);
}

function selectBranch(id, num)
{
	if (id > 0) sendRequest ('POST','ajax/select_branch.php', 'id=' + id + (num!==undefined?'&num='+num:''), handlerSelectBranch);
	else if(num > 0) {
		$('station_'+num).value=0;
		$('add_station_'+num).style.display='none';
		$('add_station_link_'+(parseInt(num)-1)).style.display='block';
	}
}

function removeSelect(id, fix) {
	if(!fix) fix = '';
	$('invite'+fix+'_form').parentNode.removeChild($('invite'+fix+'_form'));
	$('invite'+fix+'_link_'+id).style.display = 'block';
}

function selectCover (id, albumId) {
	$('loadedFileName').value = id + '.jpg';
	$('loadedImage').src = '/files/foto/big/' + id + '.jpg';	
	if (window.scrollY) {
		$('loadedPicture').style.top = window.scrollY + 20 + 'px';
	} else if (document.body.scrollTop) {
		$('loadedPicture').style.top = document.body.scrollTop + 20 + 'px';
	} else {
		$('loadedPicture').style.top = "20px";
	}
	showPopup('loadedPicture');
	if($('loadedImage').clientHeight > $('screen').clientHeight) {
		$('screen').style.height = $('loadedImage').clientHeight + $('loadedPicture').offsetTop + 50 + 'px';
	}
	//window.location.hash = "top";
	return false;
}

function saveAlbum(form) {
	/*
	if($('loadedFileName').value == '' || ($('covercontainer').style.display=='none' && $('loadedCover').style.background=='')) {
		var firstId = $('tableUploadProgress').childNodes[0];		
		while(firstId.nodeType=='3') {
			i++;
			firstId = $('tableUploadProgress').childNodes[i];
		}
		ID = firstId.id; 
		ID = ID.substr(ID.lastIndexOf('_')+1);
		return selectCover(ID);		
	} else {
	*/
	return sendFormRequest(document.newalbum, 'controllers/albums.php', handlerNewAlbum);
	//}
}

function flashScroll(delta) {
    window.scrollBy(0, delta*(-15));
}

function fixIETagsList()
{
	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 )
	{
		if ($("tags_list")) {
			$("tags_list").style.margin = "25px 0 0 -156px";
		}
		
		if ($("status_list")) {
			$("status_list").style.margin = "25px 0 0 -156px";
		};
		
	}
}
/*
function showAjaxPopup () {
	if (window.scrollY) {
		$('ajaxloading').style.top = window.scrollY + 200 + 'px';
	} else if (document.body.scrollTop) {
		$('ajaxloading').style.top = document.body.scrollTop + 200 + 'px';
	} else {
		$('ajaxloading').style.top = "200px";
	}
    if($('ajaxscreen').style.display != 'block') {
    	$('ajaxscreen').style.display = 'block';
    	scrl = getScrollSize();
    	$('ajaxscreen').style.width = scrl[0] + 'px';
    	$('ajaxscreen').style.height = scrl[1] + 'px';
    }
    $('ajaxloading').style.display = 'block';
}
function hideAjaxPopup() {
	$('ajaxscreen').style.width = 0;
    $('ajaxscreen').style.height = 0;
    $('ajaxscreen').style.display = 'none';
    $('ajaxloading').style.display = 'none';
}
*/
function flashStationClick(stationId, metropoliten) {
/*
	$('stationId').value = stationId;
	$('metropoliten').value = metropoliten;
	$('stationsform').submit();
*/
	window.location.href = '/user.html' + '?station_id=' + stationId + '&metropoliten=' + metropoliten;
}

function checkAllFriends(checkbox) {
	if(checkbox.checked) {		
		for(key in $('invite_friends_form').elements) {
			if($('invite_friends_form').elements[key].type == 'checkbox') {
				$('invite_friends_form').elements[key].checked = true;
			}
		}
		$('checkAllText').innerHTML = 'снять выделение';
	} else {
		for(key in $('invite_friends_form').elements) {
			if($('invite_friends_form').elements[key].type == 'checkbox') {
				$('invite_friends_form').elements[key].checked = false;
			}
		}
		$('checkAllText').innerHTML = 'выделить всех';
	}
}

function checkAllRequests(checkbox) {
	if(checkbox.checked) {		
		for(key in $('domenrequests_form').elements) {
			if($('domenrequests_form').elements[key].type == 'checkbox') {
				$('domenrequests_form').elements[key].checked = true;
			}
		}
		$('checkAllText').innerHTML = 'снять выделение';
	} else {
		for(key in $('domenrequests_form').elements) {
			if($('domenrequests_form').elements[key].type == 'checkbox') {
				$('domenrequests_form').elements[key].checked = false;
			}
		}
		$('checkAllText').innerHTML = 'выделить всех';
	}
}

function changeAvatarUpload(type) {
	switch(type) {
		case 'select':
			changeClassName('fieldsetselectavatar');
			$('fieldsetuploadavatar').style.display = 'none';
			break;
		case 'upload': 
			$('fieldsetselectavatar').style.display = 'none';
			$('fieldsetuploadavatar').style.display = 'block'; 
			break;
	}
	return false;
}

function hideContact(type) {
	$(type).value='';
	$(type+'_title').value='';
	changeClassName('fieldsetmetroskop');
}

function stationOnClick (id, name, city) {
	return true;
	if($('search_people') && false){
		clearSearch(0);
		$('station_id').value = id;
		$('inp_metro').value = city;
		$('station_input').value = name;
		return searchUsers();
	} else {
		return true;
	}
}

function interestOnClick(id) {
	return true;
	if($('search_people')) {
		clearSearch(0);
		$('interests_ids').value = id;
		return searchUsers();
	}
	return true;
}

function statusOnClick(id) {
	return true;
}

function pathOnClick(id) {
	return true;
	if($('search_people')){
		clearSearch(0);
		$('path_id').value=id;
		searchUsers();
		return hidePopup('pathpopup');
	} else {
		return true;
	}
}

function insertSmile(text, obj)
{
	$(obj).focus();	 
	if (document.selection) {
		var s = document.selection.createRange();
		s.text = text;   
		s.select();
		return false;
	}
	else if (typeof($(obj).selectionStart)=="number") {
		var start = $(obj).selectionStart;
     	var end = $(obj).selectionStart + text.length;

    	rs = text;
    	$(obj).value = $(obj).value.substr(0,start)+rs+$(obj).value.substr(start);
    	$(obj).setSelectionRange(end,end);
		return false;
	}	
	return false;
}

function addProfileStation(num) {
	$('add_station_'+num).style.display = 'block';
	$('add_station_link_'+(parseInt(num)-1)).style.display = 'none';
	return false;
}

function changeUploadType(type, objType) {
	var html = '';
	switch(type) {
		case 'standart':
			if(objType == 'photo') {
				html = '<fieldset id="loadPhoto">'				
					 + '<input type="hidden" name="action" value="addphoto" /><div id="addphoto_0">'
					 + '<div id="frm_newphoto_photo_0_err" class="hide"></div>'
					 + '<span class="label"><label for="title_0">Название: </label></span>'
					 + '<span class="input"><input type="text" name="title[0]" id="title_0" /></span>'
					 + '<span class="input"><input type="file" name="picture[0]" onchange="makeFileTitle(this, 0)" ACCEPT="image/*" /></span>'
					 + '</div>'
					 + '<div class="link" id="addlink" ><a href="#" onclick="return addPhoto(0)">Добавить фотографию</a></div>'
					 + '<div class="actions" id="submitContainer" ><input type="submit" id="btnSave" class="btn100" value="Опубликовать" /></div>' 
					 + '</fieldset>'
					 + '<a href="#" onclick="return changeUploadType('+"'flash', 'photo'"+')">Вернуть прежний вариант</a>';
			} else if (objType == 'video') {
				html = '<input name="action" type="hidden" value="addvideo" />'
    				 + '<fieldset id="loadVideo">'
    				 + '<input type="file" name="video" onchange="prepareVideoForm(this);" />'
					 + '<div id="uploadWait" style="display: none"><img src="/img/loading.gif" alt="loading" /> Идёт загрузка файла...</div>'
					 + '<div class="label"><label for="title_0">Заголовок:</label></div>'
       				 + '<div class="input">'
       				 + '<div id="multiuploadform_title_0_err" class="hide"></div>'
       				 + '<input name="fileTitle" type="text" id="title_0" value="" />'
       				 + '</div>'
					 + '<div class="label"><label for="preview">Картинка предпросмотра:</label></div>'
					 + '<div class="input">'
					 + '<div id="multiuploadform_previewTime_err" class="hide"></div>'
					 + '<a href="javascript:showPreviewLoad('+"'file'"+', 0)" id="previewFileLink_0" class="smlink">Выбрать файл</a><br/>'
					 + '<a href="javascript:showPreviewLoad('+"'time'"+', 0)" id="previewTimeLink_0" class="smlink">Указать время</a>'
					 + '<div id="previewFile_0" style="display:none"><input type="file" name="filePreview" ACCEPT="image/*" id="previewFileInput_0" /></div>'
					 + '<div id="previewTime_0" style="display:none"><input type="text" name="previewTime" value=""/><br>Формат времени: hh:mm:ss</div>'
					 + '<div id="preview_0"></div>'            	
					 + '</div>'			
					 + '<div class="label"><label for="description">Описание:</label></div>'
					 + '<div class="input"><textarea name="fileDescription" id="fileDescription"></textarea></div>'
					 + '<div class="actions">'
					 + '<input type="submit" id="btnSave" class="btn100" value="Опубликовать" disabled="disabled" onclick="$('+"'uploadWait'"+').style.display='+"'block'"+'" />'
					 + '</div>'
					 + '</fieldset>'
					 + '<a href="" onclick="return changeUploadType('+"'flash', 'video'"+')">Вернуть прежний вариант</a>';
			}
			break;
		case 'flash':
			if(objType == 'photo') {
				html = '<fieldset class="flash" id="fsUploadProgress">'
					 + '<input name="action" type="hidden" value="multiadd" />'
					 + '<legend>Очередь загрузки</legend>'
			         + '<table width="100%"><tbody id="tableUploadProgress" class="hide"></tbody></table>'
		        	 + '</fieldset>'
					 + '<div id="divStatus">Ни одного файла не загружено</div>'
					 + '<fieldset><div id="actions" class="actions">'
					 + '<input type="button" class="btn125" value="Выбрать файлы" onclick="swfu.selectFiles()" />'
					 + '<input id="btnCancel" class="btn110gray" type="button" value="Отменить все" onclick="cancelUpload(swfu);" disabled="disabled" />'
					 + '<input id="btnSave" class="btn125" type="button" value="Сохранить файлы" onclick="saveFiles('+"'albums.php'"+')" disabled="disabled" />'
					 + '</div></fieldset>'
					 + 'Не получается загрузить фотографии? Воспользуйтесь <a href="#" onclick="return changeUploadType('+"'standart', 'photo'"+')">альтернативным вариантом загрузки</a>';
			} else if (objType == 'video') {
				html = '<input name="action" type="hidden" value="multiadd" />'
    				 + '<fieldset class="flash" id="fsUploadProgress">'
    				 + '<legend>Очередь загрузки</legend>'
        			 + '<table><tbody id="tableUploadProgress" class="hide"></tbody></table>'
					 + '</fieldset>'
    				 + '<div id="divStatus">Ни одного файла не загружено</div>'
    				 + '<fieldset><div id="actions" class="actions">'
    				 + '<input type="button" class="btn125" value="Выбрать файлы" onclick="swfu.selectFiles()" />'
					 + '<input id="btnCancel" class="btn110gray" type="button" value="Отменить все" onclick="cancelUpload(swfu);" disabled="disabled" />'
					 + '<input id="btnSave" class="btn125" type="button" value="Сохранить файлы" onclick="saveFiles('+"'video.php'"+')" disabled="disabled" />'
					 + '</div></fieldset>'
					 + 'Не получается загрузить видео? Воспользуйтесь <a href="#" onclick="return changeUploadType('+"'standart', 'video'"+')">альтернативным вариантом загрузки</a>';
			}
			break;
				
	}
	$('upload').innerHTML = html;
	return false;
}

function addPhoto (num) {
	var newDiv = $('addphoto_'+num).cloneNode(true);
	var nextNum = num + 1;
	newDiv.id = 'addphoto_' + nextNum;
	var regExp = new RegExp(num, 'g');
	var inHtml = newDiv.innerHTML.replace(regExp, nextNum);
	if(num == 0) {
		inHtml += '<span class="link"><a href="#" onclick="return delPhoto('+nextNum+')">Удалить фотографию</a></span>';
	}
	newDiv.innerHTML = inHtml;
	$('addlink').innerHTML = '<a href="#" onclick="return addPhoto('+nextNum+')">Добавить фотографию</a>';
	$('loadPhoto').insertBefore(newDiv, $('addlink'));
	return false;
}
function delPhoto (num) {
	if(num > 0) { 
		$('loadPhoto').removeChild($('addphoto_'+num));
	}
	return false;
}

function addFriend(userId) {	
	$('friendid').value = userId;
	getTopForPopup('invitefriendpopup', 200);
	showPopup('invitefriendpopup');
	return false;
}

var mouseTempX = 0;
var mouseTempY = 0;

function getMousePosition(ev) {
	if (document.all) { 
		mouseTempX = event.clientX + document.body.parentNode.scrollLeft;
		mouseTempY = event.clientY + document.body.parentNode.scrollTop;
	} else {  
		mouseTempX = ev.pageX;
		mouseTempY = ev.pageY;
	}  
	if (mouseTempX < 0) mouseTempX = 0;
	if (mouseTempY < 0) mouseTempY = 0;  
	return true;
}

var _showBuble = 0;
var bubleWidth;
var bubleMsg = "";
var bublePosition = 0;

function showBubleSmart()
{
	if (_showBuble == 1 && $('buble')) {
		$('buble').style.top = "-2000px";
		$('buble').style.left = "-2000px";
		$('buble').style.display = 'block';
		if (mouseTempX < 500) {
			$('buble').style.left = mouseTempX+10+"px";
			bublePosition = 1;
		} else {
			bubleWidth = $('bubleContainer').clientWidth;
			$('buble').style.left = (mouseTempX-35-bubleWidth)+"px";
			bublePosition = 2;
		}
		$('buble').style.top = mouseTempY-32+"px";
	}
} 

function hideBubleSmart()
{
	if (_showBuble == 0 && $('buble')) $("buble").style.display = "none";
}

function showBuble(msg) {
	if($('buble')) {
		_showBuble = 1;
		$('buble').style.display = "none";
		bubleMsg = msg;
		if (mouseTempX < 500) {
	//		$('buble').innerHTML = '<div class="buble_left"></div><div id="bubleContainer" class="buble_middle">'+msg+'</div><div class="buble_right"></div>';
			bublePosition = 1;
			$('buble').innerHTML = '<table cellpadding="0" cellspacing="0" class="buble_left" ><tr><td><img src="/img/1px.gif" width="15" height="27" alt=""/></td><td class="buble_middle">'+bubleMsg+'</td><td class="buble_right"><img src="/img/1px.gif" width="15" height="27" alt=""/></td></tr></table>';
		} else {
	//		$('buble').innerHTML = '<div class="buble_left2"></div><div id="bubleContainer" class="buble_middle">'+msg+'</div><div class="buble_right2"></div>';
			bublePosition = 2;
			$('buble').innerHTML = '<table cellpadding="0" cellspacing="0"><tr><td class="buble_left2"><img src="/img/1px.gif" width="15" height="27" alt=""/></td><td id="bubleContainer" class="buble_middle">'+bubleMsg+'</td><td class="buble_right2"><img src="/img/1px.gif" width="15" height="27"/></td></tr></table>';
		}
		setTimeout('showBubleSmart()', 300);
	}
}

function moveBuble(ev) {
	if($('buble')) {
		getMousePosition(ev);
		if (mouseTempX < 500) {
			if (bublePosition == 2) {
				$('buble').innerHTML = '<table cellpadding="0" cellspacing="0" class="buble_left" ><tr><td><img src="/img/1px.gif" width="15" height="27" alt=""/></td><td class="buble_middle">'+bubleMsg+'</td><td class="buble_right"><img src="/img/1px.gif" width="15" height="27" alt=""/></td></tr></table>';
				bublePosition = 1;
			} 
			$('buble').style.left = mouseTempX+10+"px";
		} else {
			if (bublePosition == 1) {
				$('buble').innerHTML = '<table cellpadding="0" cellspacing="0"><tr><td class="buble_left2"><img src="/img/1px.gif" width="15" height="27" alt=""/></td><td id="bubleContainer" class="buble_middle">'+bubleMsg+'</td><td class="buble_right2"><img src="/img/1px.gif" width="15" height="27"/></td></tr></table>';		
				bublePosition = 2;
			}
			if (!bubleWidth) bubleWidth = $('bubleContainer').clientWidth;
			if (bubleWidth) $('buble').style.left = (mouseTempX-35-bubleWidth)+"px";
		}
		$('buble').style.top = mouseTempY-32+"px";
	}
}

function hideBuble() {
	_showBuble = 0;
	setTimeout ('hideBubleSmart()',300);
}

function sendComment(evt, id) {
	if((evt.ctrlKey) && ((evt.keyCode == 0xA)||(evt.keyCode == 0xD))) {
		if($(id).value != '') {
			return sendFormRequest(document.newcomment, 'ajax/lists/comments.php', handlerUserNewComment);
		}
	} else {
		return true;
	}
}

function sendWallNote(evt, id) {
	if((evt.ctrlKey) && ((evt.keyCode == 0xA)||(evt.keyCode == 0xD))) {
		if($(id).value != '') {
			return sendFormRequest(document.addnote, 'ajax/wall.php', handlerWall);
		}
	} else {
		return true;
	}
}

function saveYouTubeForm () {
	if($('youtubeform')) {
		if($('act').value == 'add') {
			if($('youtube_id').value == '' && $('yt_type').value == 1) {
				if($('title').value == '') {
					$('title_err').className = 'err';
					return false;
				} else {
					$('title_err').className = 'hide';
				}
				if($('description').value == '') {
					$('description_err').className = 'err'
					return false;
				} else {
					$('description_err').className = 'hide';
				}
				if($('file').value == '') {
					$('file_err').className = 'err'
					return false;
				} else {
					$('file_err').className = 'hide';
				}
				getTopForPopup('youtubeloading', 200);
				showPopup('youtubeloading');
				sendFormRequest(document.youtubeform, 'ajax/youtube.php', handlerYoutube);			
			} else if($('youtube_id').value.match(/watch\?v=([^\s\&\?]{11})/i) && $('yt_type').value == 2) {
				getTopForPopup('youtubeloading', 200);
				showPopup('youtubeloading');
				prepareForm($('youtubeform'));
				$('youtubeform').submit();
			} else {
				$('youtube_link_error').className = 'err';
			}
		} else if($('act').value == 'edit') {
			if($('title').value == '') {
				$('title_err').className = 'err';
				return false;
			} else {
				$('title_err').className = 'hide';
			}
			if($('description').value == '') {
				$('description_err').className = 'err'
				return false;
			} else {
				$('description_err').className = 'hide';
			}
			prepareForm($('youtubeform'));
			$('youtubeform').submit();
		}
	}
}

function changeYoutubeType (type) {
	switch(type) {
		case 'youtube_id':
			$('youtube_file_container').style.display = 'none';
			$('youtube_id_container').style.display = 'block';
			$('file').value = $('youtube_id').value = '';
			$('yt_type').value = 2;
			break;
		case 'file':
			$('youtube_file_container').style.display = 'block';
			$('youtube_id_container').style.display = 'none';
			$('file').value = $('youtube_id').value = '';
			$('yt_type').value = 1;
			break;
	}
	return false;
}

function escapeFormValues(obj, data) {
	if(!data) data = {};
    obj = obj.firstChild;    
    while (obj) {
    	if ( obj.tagName && obj.name 
		    	&& ( (obj.tagName.toLowerCase() == 'input' && (obj.type.toLowerCase() == 'text' || obj.type.toLowerCase() == 'hidden') )
		    	|| obj.tagName.toLowerCase() == 'textarea') ) {
    		if(obj.name != 'token') {
	    		data[obj.name] = myEscape(obj.value);
	    		obj.name = '';
    		}
		}
		data = escapeFormValues(obj, data)
        obj = obj.nextSibling;
    }    
    return data;
}

function prepareForm(form) {
	var data = escapeFormValues(form, '');
	for(key in data) {
		var hidden = document.createElement('input');
		hidden.type = 'hidden';
		hidden.name = key;
		hidden.value = data[key];
		form.appendChild(hidden);
	}
	return true;
}

function submitBlogForm(needPrepare) {
	$('btnSave').disabled='disabled';
	if(needPrepare) preparePostForm();
	if(!$('type') || $('type').value !== '3') {
		sendFormRequest(document.newblog, 'controllers/blogs.php', handlerShowFormErrors, true);
	} else {
		if($('youtube_id').value == '' && $('yt_type').value == 1) {
			if($('title').value == '') {
				$('title_err').className = 'err';
				return false;
			} else {
				$('title_err').className = 'hide';
			}
			if($('file').value == '') {
				$('file_err').className = 'err'
				return false;
			} else {
				$('file_err').className = 'hide';
			}
			prepareForm($('newblog'));
			var descr = document.createElement('input');
			descr.type = 'hidden';
			descr.name = 'description';
			descr.value = $('title').value;
			$('newblog').appendChild(descr);
			getTopForPopup('youtubeloading', 200);
			showPopup('youtubeloading');
			sendFormRequest(document.newblog, 'ajax/youtube.php', handlerYoutube);
		} else  if($('youtube_id').value.match(/watch\?v=([^\s\&\?]{11})/i) && $('yt_type').value == 2) {
			getTopForPopup('youtubeloading', 200);
			showPopup('youtubeloading');
			prepareForm($('newblog'));
			descr = document.createElement('input');
			descr.type = 'hidden';
			descr.name = 'description';
			descr.value = myEscape($('title').value);
			$('newblog').appendChild(descr);
			$('newblog').submit();
		} else {
			$('youtube_link_error').className = 'err';
		}
	}
}

function showhidelink (hash, txt)
{
	$('end_'+hash).style.display='inline';
	$('link_'+hash).innerHTML='<a href="#" onclick="return showhidelink2(\''+hash+'\', \''+txt+'\')">Скрыть</a>';
	return false;
}

function showhidelink2 (hash, txt)
{
	$('end_'+hash).style.display='none';
	$('link_'+hash).innerHTML='<a href="#" onclick="return showhidelink(\''+hash+'\', \''+txt+'\')">'+txt+'</a>';
	return false;
}

function addStation() {
	var clonedDiv = $('add_station_link').previousSibling;
	var lastNum = parseInt(clonedDiv.id.substr(clonedDiv.id.lastIndexOf('_') + 1));
	var nextNum = lastNum + 1;
	var newDiv = $('add_station_link').previousSibling.cloneNode(true);
	newDiv.id = 'home_station_' + nextNum;
	var re = new RegExp('_' + lastNum + '"', 'g');
	newDiv.innerHTML = newDiv.innerHTML.replace(re, '_'+nextNum+'"'); 
	var re = new RegExp("\\[" + lastNum + "\\]", 'g');
	newDiv.innerHTML = newDiv.innerHTML.replace(re, '['+nextNum+']');
	var re = new RegExp("\\, " + lastNum + "\\)", 'g');
	newDiv.innerHTML = newDiv.innerHTML.replace(re, ', '+nextNum+')');
	$('add_station_link').parentNode.insertBefore(newDiv, $('add_station_link'));
	$('del_station_link').style.cssText = '';
	return false;
}

function delStation() {
	var id = parseInt($('add_station_link').previousSibling.id.substr($('add_station_link').previousSibling.id.lastIndexOf('_') + 1));
	if(id > 1) {
		$('add_station_link').parentNode.removeChild($('add_station_link').previousSibling);
		if(id == 2) {
			$('del_station_link').style.cssText = 'color: gray; text-decoration: none; cursor: default';
		}
	}
	return false;
}

function savePlace() {
	$('btnSave').disabled = 'disabled';
	if($('place_type').value == -1) {
		$('addplace_type_err').className = 'err';
		$('btnSave').disabled = false;
		return false;
	} else {
		$('addplace_type_err').className = 'hide';
	}
	sendFormRequest(document.addplace, 'controllers/place/add.php', handlerShowFormErrors)
}

var is_move_preview = 0;
var move_interval;
var preview_images_array = [];
var preview_image_hide = 1;
var imagesSize;
var imagesSizeArray = [];

function move_preview_right_ie()
{
	if (!(preview_images_array[preview_image_hide+1]) || imagesSize<$("preview_photos_ie").offsetWidth) return false;
	$('img_preview_link_'+preview_images_array[preview_image_hide]).style.display = "none";
	imagesSize -= imagesSizeArray[preview_image_hide];
	preview_image_hide++;
	return false;
}
function move_preview_left_ie()
{
	if (preview_image_hide == 1) {
		return false;
	}
	preview_image_hide--;
	imagesSize += imagesSizeArray[preview_image_hide];
	$('img_preview_link_'+preview_images_array[preview_image_hide]).style.display = "inline";
	return false;
}

function move_preview_right(step) {
	curpos = $('preview_photos_container').style.left;
	curpos = parseInt(curpos.replace("px",""));
	if (!curpos) curpos=0;

	containerWidth = $('preview_photos_container').clientWidth;
	containerOffset = $('preview_photos_container').style.left;
	containerOffset = parseInt(containerOffset.replace("px",""));
	if (!containerOffset) containerOffset = 0;
	
	divWidth = $('preview_photos').clientWidth;
//	$('messs').innerHTML = containerWidth + " : " + containerOffset + " : " + divWidth + " : " + (containerWidth + containerOffset);
	if ((containerWidth + containerOffset)<=divWidth) return;
	$('preview_photos_container').style.left=curpos-step+"px";
}
function move_preview_left(step) {
	curpos = $('preview_photos_container').style.left;
	curpos = parseInt(curpos.replace("px",""));
	if (!curpos || curpos>0) {
		$('preview_photos_container').style.left = 0 +"px";
		return;
	}
	$('preview_photos_container').style.left=curpos+step+"px";
}

function move_preview_image_right(step)
{
	if (!is_move_preview) {
		is_move_preview = 1;
		move_interval = setInterval("move_preview_right("+step+")",10);
	}
	return false;
}

function move_preview_image_left(step)
{
	if (!is_move_preview) {
		is_move_preview = 1;
		move_interval = setInterval("move_preview_left("+step+")",20);
	}
	return false;
}

function stop_move_preview_image()
{
	is_move_preview = 0;
	clearInterval (move_interval);
}

function onEvPlaceTypeChange (value, postfix) {
	if(!postfix) postfix = '';
	else postfix = '_' + postfix;
	switch (value) {
		case '-1':
			$('place_select_cont' + postfix).innerHTML = '';
			$('station_select_container').style.display = 'none';
			break;
		case '100':
			sendRequest ('POST', 'ajax/select_metropoliten.php', 'id=' + $('inp_city').value + '&addst=0', handlerSelectMetropoliten);
			$('station_select_container').style.display = 'block';
			$('place_select_cont' + postfix).innerHTML = '';
			break;
		default:
			sendRequest ('POST', 'ajax/makePlaceSelect.php', 'city_id=' + $('inp_city' + postfix).value + '&type=' + value + '&postfix=' + postfix, handlerSelectPlaceType);
			$('station_select_container').style.display = 'none';
			break;
	}
}

function showFullPoster (url) {
	$('posterImage').src = url;
	showPopup('posterPopup');
}

function checkDomen(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode == 13) {
		sendRequest('post', 'controllers/user/profile.php', 'formid=domen&val='+myEscape($('domen').value), handlerDomen);
	} else {
		var reg = new RegExp("^([a-zA-Z0-9\-]*)$");
		var nonum = new RegExp("[^0-9]+");		
		var val = $('domen').value;
		
		if(val.match(reg) && val.match(nonum)) {
			$('bad_symbols').style.display = 'none';	
			$('only_digits').style.display = 'none';
			if(val.length > 1) {
				sendRequest('post', 'ajax/checkDomen.php', 'val='+myEscape($('domen').value), handlerDomen);
			}
		} else {
			if(val.length > 1) {
				if(!val.match(reg)) {
					$('bad_symbols').style.display = 'block';
					$('only_digits').style.display = 'none';
				} else if (!val.match(nonum)) {
					$('only_digits').style.display = 'block';
					$('bad_symbols').style.display = 'none';
				}
			} else {
				$('only_digits').style.display = 'none';
				$('bad_symbols').style.display = 'none';
			}
			$('domendeclared').style.display = 'none';
			$('domenfree').style.display = 'none';
			$('registerdomen').disabled = 'disabled';
		}
	}
}

function movePhotoTr(curOrder, value) {
	var newOrder = parseInt($('photo_order_'+curOrder).value) + value;
	if(newOrder < 1 || newOrder > $('count_photos').value ) return false;
	var parentTable = $('img_'+curOrder).parentNode;
	var movedNode = $('img_'+curOrder).cloneNode(true);
	parentTable.removeChild($('img_'+curOrder));
	
	var reg = new RegExp('([_\\>\\(])'+newOrder+'(["\\.\\,])', "g");
	$('img_'+newOrder).innerHTML = $('img_'+newOrder).innerHTML.replace(reg, '$1'+curOrder+'$2');
	$('img_'+newOrder).id = 'img_'+curOrder;
	$('sel_'+curOrder).value = curOrder;
	$('photo_order_'+curOrder).value = curOrder;
	
	var reg = new RegExp('([_\\>\\(])'+curOrder+'(["\\.\\,])', "g");
	movedNode.innerHTML = movedNode.innerHTML.replace(reg, '$1'+newOrder+'$2');
	movedNode.id = 'img_'+newOrder;
	
	parentTable.insertBefore(movedNode, $('img_' + parseInt(newOrder + 1)))	
	$('photo_order_'+newOrder).value = newOrder;
	$('sel_'+newOrder).value = newOrder;
	return false;
}

function multiMovePhoto(curOrder, newOrder) {
	if(curOrder > newOrder) {
		var value = -1;
	} else if(curOrder < newOrder) {
		var value = 1;
	} else {
		return false;
	}
	var int = 0;
	while(curOrder != newOrder) {
		setTimeout('movePhotoTr('+curOrder+','+value+')', int);
		curOrder += value;
		int += 100;
	}
	return false;
}

function changeCategory(id)
{
	if (id > 0) sendRequest ('POST','ajax/select_category.php', 'id=' + id, handlerChangeCategory);
	else $('category').disabled = 'disabled'; 
	
}