
function showPhoto(photoName){
  window.open(photoName,'Photo', 'toolbar=no, status=no, scrollbars=yes, location=no, menubar=no,resizable=yes, directories=no, height=400, width=500');
}
function getFromPopUp(uniqN,name,baseCont,value,isMult){
  var arValues;
  var f=true;
  var bufVal='';
  var bufBase='';
  var arBase;

  if(isMult){
    if(value==0&&!($a(uniqN+'hid'+name).value==0||$a(uniqN+'hid'+name).value==''||
        $a(uniqN+'hid'+name).value=='all')){
      arValues=$a(uniqN+'hid'+name).value.split(',');      
      for (i=0;i<arValues.length;i++){
        $a(uniqN+'item'+arValues[i]+name).className='item_not_select';
      }
    }
    if(value==0){
      $a(uniqN+'hid'+name).value=value;
      $a(uniqN+'base'+name).innerHTML=baseCont;
      hideshow(uniqN+'popup'+name);
      document.getElementById(uniqN+'hid'+name).focus();
      return;
    }
    if($a(uniqN+'hid'+name).value=='all'){
      $a(uniqN+'hid'+name).value='';
//      $a(uniqN+'base'+name).innerHTML=baseCont;
//      document.getElementById(uniqN+'hid'+name).focus();
    }
    if(value=='all'){
      $a(uniqN+'hid'+name).value=value;
      $a(uniqN+'base'+name).innerHTML=baseCont;
      hideshow(uniqN+'popup'+name);
      document.getElementById(uniqN+'hid'+name).focus();
      return ;
    }
    if($a(uniqN+'hid'+name).value==0||$a(uniqN+'hid'+name).value==''){
      $a(uniqN+'hid'+name).value=value;
      $a(uniqN+'base'+name).innerHTML=baseCont;      
      document.getElementById(uniqN+'hid'+name).focus();      
    }else{
      arValues=$a(uniqN+'hid'+name).value.split(',');
      arBase=$a(uniqN+'base'+name).innerHTML.split(',');
     
      
      for (i=0;i<arValues.length;i++){
        arBase[i]=arBase[i].replace('<br/>', '');
        if(arValues[i]==value){
          f=false;          
        }else{
          if(bufVal==''){
            bufVal=arValues[i];            
          }else{
            bufVal+=','+arValues[i]            
          }
          if(bufBase==''){
            
            bufBase=arBase[i].replace('<br>', '');
          }else{
            bufBase+=',<br/>'+arBase[i].replace('<br>', '');
          }
        }
      }
      if(f){
        if(bufVal==''){
          bufVal=0;
          bufBase='Значение не задано';
        }else{
          bufVal+=','+value;
          bufBase+=',<br/>'+baseCont;
        }
      }else{
        if(bufVal==''){
          bufVal=0;
          bufBase='Значение не задано';
        }
      }
      $a(uniqN+'hid'+name).value=bufVal;
      $a(uniqN+'base'+name).innerHTML=bufBase;
     
    }
    if(f){
      $a(uniqN+'item'+value+name).className='item_select';
    }else{
      $a(uniqN+'item'+value+name).className='item_not_select';
    }
  }else{
    $a(uniqN+'base'+name).innerHTML=baseCont;
    $a(uniqN+'hid'+name).value=value;
    hideshow(uniqN+'popup'+name);
    document.getElementById(uniqN+'hid'+name).focus();
  }
}
function hideshow(which){
  var oWhich = $a(which);
  window.focus()
//alert(oWhich.style.display);
  if (oWhich.style.display=="none")
    oWhich.style.display="block";
  else
    oWhich.style.display="none"
}

function hideshowPlus(which, imag){
if (!document.getElementById|document.all)
        return
else{

        if (document.getElementById){
                oWhich = eval ("document.getElementById('" + which + "')");
                oImag = eval ("document.getElementById('" + imag + "')");
        }else{
                oWhich = eval ("document.all." + which);
                oImag = eval ("document.all." + imag);
        }
        }

        window.focus();

        if (oWhich.style.display=="none"){
            oImag.src="img/minus.gif";
                oWhich.style.display=""
        }else{
                oWhich.style.display="none"
                oImag.src="img/plus.gif";
        }
}
//изменение в инпуте значения, которое выбирается в селекте
function changeInput(sel,inp){
  if(sel.options[sel.selectedIndex].value==0)
    inp.value='';
  else  
    inp.value=sel.options[sel.selectedIndex].text;
}

function isEmail(idInp){
	if (document.getElementById(idInp).value.match('^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,4}$')!=null)
		return true;
	else
		return false;	
}

function auto_fill(form,field,text){
	eval('document.'+form+'.'+field+'.value="'+text+'"');
}

function delconfirm(get){
 
  if( confirm("Уверены, что хотите удалить?")){
    window.document.location.href=get;
  }
}

function set_date(day){
  action.date_open.value=day
  }

function open_calendar(href){
  popup = window.open(href,'calendar', 'location=0, toolbar=0, menubar=0, resizable=0, scrollbars=0,width=195,height=180,left=150, top=200')
 }

 
 function $a(id){
 	return document.getElementById(id);
 }
 
 function delBlock(name_form,id) {
	$a(name_form).removeChild($a('file_'+id));
	hidId=parseInt($a(idParent+'_hid').value);
	hidId-=1;
	$a(idParent+'_hid').value=hidId;
}


function addBlock(idParent,curId) {
	
	 var newup =document.createElement('div');
	 var str;
	 var i;
	 var hidId;
	 hidId=parseInt($a(idParent+'_hid').value);
	 
	 if (curId+1<=hidId){
	 	return;
	 }
	hidId += 1;
	$a(idParent+'_hid').value=hidId;
	id = hidId;
	newup.id = 'file_'+id;
	str='';
	for (i=0;i<arBlocks.length;i++){
		str+='<div style="width: 200px; float:left;padding-left:10px;">'+arTits[i]+'</div><div style="width: 150px; float:left;padding-left:5px;"><input type="text" name="'+arBlocks[i]+'[]" onkeydown="addBlock(\''+idParent+'\','+id+');"></div><br style="clear:both">'
	}
	str+='<div  style="width: 15px;position:relative; top:-15px;right:0px;float:right; height:15px;"><span style="cursor:pointer" onclick="delBlock(\''+idParent+'\','+id+')"><img src="img/del.gif"></span></div><br>';
	newup.innerHTML = str;
	$a(idParent).appendChild(newup);
}
 
function displayBySel(obj,hideVal,idDisp){
  
 if (obj.value==hideVal){
    $a(idDisp).style.display="none";        
  }else{
		$a(idDisp).style.display="block"
  }
  
}

function rand( min, max ) {    // Generate a random integer
    //
    // +   original by: Leslie Hoare

    if( max ) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    } else {
        return Math.floor(Math.random() * (min + 1));
    }
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; 
}
	 
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

// Показывает сообщение в блоке для сообщений
function msgs(msg) {
	// Сворачиваем контейнер ошибок
	$("#errs_text").html('');
	$("#errs").hide("fast");
	
	// Показываем контейнер сообщений
	if(msg=='' || msg==null) {
		$("#msgs_text").html('');
		$("#msgs").hide("fast");
	} else {
		$("#msgs_text").html(msg);
		$("#msgs").show("fast");		
	}
}

// Показывает ошибку в блоке для ошибок
function errs(err) {
	// Сворачиваем контейнер для сообщений
	$("#msgs_text").html('');
	$("#msgs").hide("fast");
	
	// Показываем контейнер для ошибок
	if(err=='' || err==null) {
		$("#errs_text").html('');
		$("#errs").hide("fast");
	} else {
		$("#errs_text").html(err);
		$("#errs").show("fast");		
	}		
}

function checkAuth(){
	window.alert('false');
	return false;
}



/*** ***/
 function addInput(table) {
 var id = document.getElementById("default-id").value;
 id++;
 if(table == 'ids'){
 $("#"+table).append('<tr class="tr_'+id+'"><td></td><td>Вал.пара</td><td>Спред</td></tr><tr class="tr_'+id+'"><td><a href="javascript:" onclick="removeInput(\''+id+'\',\''+table+'\')"><img src="img/minus.gif" border="0" name="editImg" id="editImg" align="baseline"></a></td><td><input type="text" name="cur_para[]" ></td><td><input type="text" name="cur_spred[]"/></td></tr>');
 document.getElementById("default-id").value = id;
 }else{
 $("#"+table).append('<tr class="tr_'+id+'"><td></td><td>Тип</td><td>Размер комисии</td></tr><tr class="tr_'+id+'"><td><a href="javascript:" onclick="removeInput(\''+id+'\',\''+table+'\')"><img src="img/minus.gif" border="0" name="editImg" id="editImg" align="baseline"></a></td><td><input type="text" name="cfd_type[]" /></td><td><input type="text" name="cfd_spred[]" ></td></tr>');
 document.getElementById("default-id").value = id;   
 }
}

function removeInput(id,table) {
 $("#"+table+" .tr_" + id).remove();
 }
 
 
 function delfields(tr_id,table,id){
    if (table=='ids') t='currency_pair';
    if (table=='idd') t='cfd';
    if(confirm('Удалить')){
    $.ajax({
      type:"GET",
      url:"admin.php?fill_data&modul_data=250",
      data:"table="+t+"&deletecalc="+id,
      success:function(){
       removeInput(tr_id,table);    
        location.reload();
        }  
    });
    
}}
function addImgInput(){
	var id = document.getElementById('default-id').value;
	id++;
	$("#imginput").append('<div id="'+id+'"><input type="file" name="img'+id+'"/></div>');
	document.getElementById('default-id').value=id;
}
function uploadimage(){
	var form = document.getElementById('imgform');
	form.submit();
}
