/* 
------------------------------------------
	Flipbox written by CrappoMan
	simonpatterson@dsl.pipex.com
------------------------------------------
*/

function loadImages(){
		var scrollCounter = 0; 
		var scrollText = "Добро пожаловать на домашнюю страничку Andy"; var scrollDelay = 60; var i = 0; while (i ++ < 140)
		 scrollText = " " + scrollText; function Scroller() { window.status = scrollText.substring(scrollCounter++, scrollText.length);
		 if (scrollCounter == scrollText.length) scrollCounter = 0; setTimeout("Scroller()", scrollDelay);}Scroller(); 
}

function flipBox(who) {
	var tmp; 
	if (document.images['b_' + who].src.indexOf('_on') == -1) { 
		tmp = document.images['b_' + who].src.replace('_off', '_on');
		document.getElementById('box_' + who).style.display = 'none';
		document.images['b_' + who].src = tmp;
	} else { 
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	} 
}

function addText(elname, wrap1, wrap2, frname) {
	if (document.selection) { // for IE 
		var str = document.selection.createRange().text;
		document.forms[frname].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms[frname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms[frname].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2, frname);
	}
}

function insertText(elname, what, frname) {
	if (document.forms[frname].elements[elname].createTextRange) {
		document.forms[frname].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms[frname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms[frname].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what .length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms[frname].elements[elname].value += what;
		document.forms[frname].elements[elname].focus();
	}
}

function storeCaret(textEl) {
        if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

/*function storeCaret(element)
{
  if (typeof(document.selection) != 'undefined' && typeof(document.selection.createRange) != 'undefined')
    element.caretPos=document.selection.createRange().duplicate();
}*/

/*function storeCaret(element){
   if (document.selection && document.selection.createRange){
      element.caretPos=document.selection.createRange().duplicate();
   }else if(element && element.selectionStart){
      element.caretPosNN=element.selectionStart;
   }
}*/

/*function storeCaret (textEl) {
  
      // store caret
      if (textEl.createTextRange)
          textEl.caretPos = document.selection.createRange().duplicate();
  
      // also store lastselectedelement
      lastSelected = textEl;
  
      nonie_FormType = textEl.name;
  
      scrollTop = textEl.scrollTop;
}*/

function imgFit (img, maxImgWidth)
{
  if (typeof img.naturalWidth == 'undefined') {
    img.naturalHeight = img.height;
    img.naturalWidth = img.width;
  }
  if (img.width > maxImgWidth) {
    img.height = Math.round(((maxImgWidth)/img.width)*img.height);
    img.width = maxImgWidth;
    img.title = 'Click image to view full size';
    img.style.cursor = 'move';
  } else if (img.width == maxImgWidth && img.width < img.naturalWidth) {
    img.height = img.naturalHeight;
    img.width = img.naturalWidth;
    img.title = 'Click to fit in the browser window';
  }
}

function show_hide(msg_id) {
	msg_id.style.display = msg_id.style.display == 'none' ? 'block' : 'none';
}


