function confirmLink(theLink, theMessage)
{
    var confirmMsg  = 'Вы действительно желаете ';
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {return true;}
    var is_confirmed = confirm(confirmMsg + ' \n' + theMessage);
    if (is_confirmed) {theLink.href += '/confirm/1';}
    return is_confirmed;
}

 function fieldAppendText(id,text){
     var oldText = document.getElementById(id).value;
     var doc = document.getElementById(id);
    doc.focus();
    doc.value = oldText+((oldText)?' ':'')+text+' ';
    

}

function blockTrigger(id){
    var block = document.getElementById(id);
        //document.getElementById(id).appendChild(div);
    if (block.style.display=='inline') {
	block.style.display = 'none';}
	else {block.style.display = 'inline';}
}
function check(id)
{
 var btn = document.getElementById(id)
 if (btn.value=='Отметить все') {
  var fl = true;
  btn.value='Снять отметку';
 }
 else {
  var fl = false;
  btn.value='Отметить все';
 }
 var arr = document.getElementsByTagName('input');
 for(var i = 0; i < arr.length; i++) {
  if(arr[i].type=='checkbox')
   arr[i].checked = fl;
 }
}
function OpenImagePopup(imgPath, title, alt) {
    var win = window.open('','preview',
    'width=100,height=100,left=0,top=0,screenX=0,screenY=0,resizable=1,scrollbar=0,status=0,menubar=0,toolbar=0,titlebar=0');
    imgPath = imgPath.replace(/^\s+|\s+$/g,"");//trim spaces
    var imgW = window.screen.width;
    var user_agent=navigator.userAgent;
    var winDoc = win.document;
    if (title == undefined) title = 'My Image, Click to Close';
    if (alt   == undefined) alt   = 'My Image, Click to Close';
    var content = '<html><head><title>' + title + '</title>' +
    			  '<style>body{overflow: hidden;margin:0;}img{border:0;}</style>' +
    			  '</head><body><a href="javascript:self.close()">' +
    			  '<img '+((user_agent.indexOf('iPhone')!=-1)?'':('width="'+imgW/2+'px"'))+' alt="'+alt+'" id="image" src="'+imgPath+'" /></a></body></html>'
    win.document.write(content);
    winDoc.body.onload = function() {
    	var obj = winDoc.getElementById('image');
    	var w = obj.width, h = obj.height;
    	
    	var iHeight= document.body.clientHeight, iWidth = self.innerWidth;

    	var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
    	var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;
    	win.resizeTo(w+10, h+26+20);
    	win.moveTo(left, top);
    };
    
    win.onload = winDoc.body.onload; // special for Mozilla

    // !!! Important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
}

function lockEnter(element){
	var inputType=element.getAttribute("type");
	var prevEvent=document.onkeypress;
	document.onkeypress=function(e){
		if(e.keyCode==13 && inputType=="text") return false;
	};
}

function resizeImg(imgOrigPath,imgElement){
	var img=document.createElement('img');
	img.src=imgOrigPath;
	if((img.width)/(img.height)<(1024/768)){
		imgElement.src=img.src;
		imgElement.width=240;
	}
}

