var ImageWindow;

function WindowPopUp(path, name) {
  ImageWindow = window.open(path, name);
  ImageWindow.focus();
  }

function ImagePopUp(path, width, height) {
  ImageWindow = window.open(path , 'Picture',
        "copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no,status=yes,width=" + width + ",height=" + height);
  ImageWindow.focus();
  }
//------------- подсветка курсора
function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }
    start_c=0;
    var row_cells_cnt           = theRow.cells.length;
    for (var c =start_c; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }

    return true;
}
//-------------------------  
// --------------- проверка полей формы  mail_to
function checkForm_mail_to()
{
       if (document.form_mail_to.mail_adress.value=="")
       {
       alert('Введите Ваш e-mail !');
       document.form_mail_to.mail_adress.select();
       document.form_mail_to.mail_adress.focus();
       return;
       } else
       {
         document.form_mail_to.submit();
         }
}
//
// первый элемент массива - имя формы, второй элемент, имя переменной по которой определяем отправленна форма или нет
function checkForm(arr)
{
var form_name=arr[0];
var button_name=arr[1];
 	for ( i=2; i<arr.length; i++)	
			{
			var fname=arr[i];
			var s='document.'+form_name+'.'+fname;

			    if (eval(s).value=="")
     			{
     			alert('Не заполнено одно из полей, помеченное * ');
     			eval(s).select();
     			eval(s).focus();
				break;
      				
      			} 
			}
	if(arr.length==i){
			eval('document.'+form_name+'.'+button_name).value="ok";
        	eval('document.'+form_name).submit();	
			}
}
//------------------------------------
function GoFromSelect(form_name,select_name)
{
link='form_name.'+select_name+'.options[form_name.'+select_name+'.selectedIndex]';
//alert(eval(link).value);
if (eval(link).value) location.href=eval(link).value;
//form_name.submit();
}
//---------
function GoFromSelectA(form_name,select_name)
{
link='form_name.'+select_name+'.options[form_name.'+select_name+'.selectedIndex]';
form_name.submit();
}


//----------------------------------------

function confirm_del(link,msg)
{
if (confirm(msg)) window.location.href=link;
}
//----------------------------
function confirm_del_btn(form_name,msg)
{

if (confirm(msg)) 
	{
	document.form_name.submit();
	}
}

//-------------------------------- проверка типа файла
// CheckFileType(userfile[],'csv')
function CheckFileType(file,postfix)
{
var i=0,j=0,types_str='';
if(file) 
{
file=file.toLowerCase();
all_postfix = postfix.split("&");
array_size = all_postfix.length;

	if(all_postfix[0]=='gif')
	{
	for ( i=0; i<array_size; i++)	if(file.indexOf(all_postfix[i])<0) {types_str+=all_postfix[i]+' ';j++;}
	if(j==4){
			alert('Типа, файл не того типа! Нужен - '+types_str);
			return false;
			} else return true;
	}
	
	if(all_postfix[0]=='zip')
	{
 	for ( i=0; i<array_size; i++)	if(file.indexOf(all_postfix[i])<0) {types_str+=all_postfix[i]+' ';j++;}
	if(j==12){
			alert('Типа, файл не того типа! Нужен - '+types_str);
			return false;
			} else return true;
	}	
	
		if(all_postfix[0]=='csv')
				if(file.indexOf(all_postfix[0])<0) 
					{
					alert('Типа, файл не того типа! Нужен - '+postfix);
					return false;
					} else return true;
	
} else return true;
}
//--------------------------------
function insertAroundSel(textEl, textBefore, textAfter) {
  strSelection = document.selection.createRange().text
  if (strSelection == "")
    insertAtCaret (textEl, textBefore + textAfter)
  else
    document.selection.createRange().text = textBefore + strSelection + textAfter;
  //textEl.focus();
}

  function storeCaret(element) {
    if (document.selection && document.selection.createRange)
      element.caretPos=document.selection.createRange().duplicate();
      
  }

function insertAtCaret (textEl, text) {
  if (textEl.createTextRange && textEl.caretPos) {
    var caretPos = textEl.caretPos;
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
  else
    textEl.value  = textEl.value + text; // for non MSIE browsers just append it
  //textEl.focus();
}


function DoPrompt(textEl, action) {
      var currentMessage = textEl.value;

      if (action == "url") {
            var thisURL = prompt("Aaaaeoa iieiue URL nnueee:", "http://");
        if (thisURL == null){return;}

            insertAroundSel(textEl, "<a href='" + thisURL + "' target=_blank>", "</a>");
            return;
      }

      if (action == "email") {
            var thisEmail = prompt("Aaaaeoa email aa?an:", "");
        if (thisEmail == null){return;}

            insertAroundSel(textEl, "<a href='mailto:" + thisEmail + "'>", "</a>");
            return;
      }
}
//-------------------------------------------
