


var over = 0
var oldEvent = null;
var flag = 0;
var activeBlock = "null"
function mouseLayerX(e)
{

//  if (!e) { e = window.event; e.target = e.srcElement}
//  var x = 0;
////  e.target = e.currentTarget;
//  
//  if(e.target.id == activeBlock) oldEvent = e;
//  else{ if(window.event)return; e = oldEvent; }
//  try
//  {
//      if (e.layerX)//Gecko
//      {
//        x = e.layerX
//      }
//      else if (e.offsetX)//IE, Opera
//      {
//        x = e.offsetX;
//      }
//  }
//  catch  (e){}  
//  return {"x":x};

    e = e || window.event;
    var t = e.target || event.srcElement;
    
    var x = 0;
    
    try
    {
          if (e.layerX)//Gecko
          {
            x = e.layerX
          }
          else if (e.offsetX)//IE, Opera
          {
            x = e.offsetX;
            //alert('offsetX: '+x+'; pageX: '+ e.pageX);
          }
    }
    catch  (e){ alert('event handling error') } 
     
    return {"x":x};

}

function mouseLayer(){
	flag = 0;	
}
var activeCursor = null;
var activeValue = null;
var pm1 = null;
var int1 = 35;
document.onmousemove = function(e){
	if(!activeCursor) return;
if(flag == 1){
	var mCur = mouseLayerX(e);
	with(document.getElementById(activeCursor).style){
		if(over == 1){curs = mCur.x -= 5; left = curs + 'px'; writeCoord(mCur.x);}
	}
	with(document.getElementById(activeValue)){
		if(over == 1){value = calculateValue(mCur.x += 5);}
	}
}
}

//document.onclick = function(e){
//	var mCur = mouseLayerX(e);
//	if(over == 1){document.getElementById(activeCursor).style.left = mCur.x -= 5; writeCoord(mCur.x);}
//	if(over == 1){document.getElementById(activeValue).value = calculateValue(mCur.x += 5)}
//}

function falg1(e){
	flag = 1;
	var mCur = mouseLayerX(e);
	var curs = mCur.x -= 5;
	document.getElementById(activeCursor).style.left = curs + 'px'; writeCoord(mCur.x);
	document.getElementById(activeValue).value = calculateValue(mCur.x += 5);
	
}

function setCoordByLink(val)
{
    activeValue = "value2";
    activeCursor = "imgId2";

    x = calculateCoord(val) - 5;
    document.getElementById(activeCursor).style.left = x + 'px';
    document.getElementById(activeValue).value = val;
    
    writeCoord(x);
}

function writeCoord(value)
{
    if(activeCursor.indexOf("imgId1")!=-1){wAdvDaysCoord = value;}
    if(activeCursor.indexOf("imgId2")!=-1){wAdvShowsCoord = value;}
    if(activeCursor.indexOf("imgId3")!=-1){wAdvClicksCoord = value;}
    //alert('wAdv='+value);
}

function posSlider()
{
    document.getElementById(activeValue).value = validate();
    var coord = calculateCoord(document.getElementById(activeValue).value); 
    var curs = coord -= 5;
    document.getElementById(activeCursor).style.left = curs + 'px';
    writeCoord(coord);
}

function validate()
{
    var re = /\d+(?!\.)/;
	var isOK = re.exec(document.getElementById(activeValue).value);
	var maximum = 0;
	
	if(activeCursor.indexOf("imgId1")!=-1){maximum = 180;}
    if(activeCursor.indexOf("imgId2")!=-1){maximum = 60000;}
    if(activeCursor.indexOf("imgId3")!=-1){maximum = 6000;}
    //alert(isOK);

    if (isOK == null && document.getElementById(activeValue).value != "") 
    {
        alert(markupList["slide_err1"]);
        return 60;
    }
    else if (isOK > maximum)
    {
        alert(markupList["slide_err2"]);
        return maximum;
    }
    else if (document.getElementById(activeValue).value == "")
        return document.getElementById(activeValue).value;
    
    return isOK;
}

function calculateValue(coord)
{
    if(activeCursor.indexOf("imgId1")!=-1)
    {
       return (coord<36?0:
                        (coord<72?1:
                                   (coord<107?2:
                                               (coord<142?3:
                                                           (coord<177?4:
                                                                       (coord<212?5:
                                                                                   (coord<246?6:
                                                                                               (coord>=246&&coord<316?parseInt((coord-246)/70*23)+7:
                                                                                                        (coord>=316&&coord<386?parseInt((coord-316)/70*60)+30:
                                                                                                            (coord>=386&&coord<456?parseInt((coord-386)/70*90)+90:
                                                                                                                                     (coord>456?180:0)
                                                                                                            )
                                                                                                        )
                                                                                               )
                                                                                   )
                                                                       )
                                                           )
                                               )
                                   )
                        )
              );
    }
    if(activeCursor.indexOf("imgId2")!=-1)
    {
                
        return (coord<36?0:(coord>=36 && coord<=107 ? parseInt((coord-36)*126.761)+1000: 
                                       (coord<=456 && coord>107 ? parseInt((coord-107)*143.2665) + 10000 : 60000
                                       )
                           )
                );
    }
    if(activeCursor.indexOf("imgId3")!=-1)
    {
        return (coord<36?0:(coord <= 456 && coord>=36 ? parseInt((coord-36)*2.357)+10 : 1000))*6;
    }
    return activeCursor;
}

function calculateCoord(value) 
{


        return (value<1000?36:(value>=1000 && value<=10000 ? (value-1000)/126.76056338 + 36: 
                                    (value>10000 && value<=60000 ? (value-10000)/140.47619 + 107 : 0
                                    )
                            )
               );

}

//function setupRuller(value)
//{
//	document.getElementById(activeCursor).style.left = calculateCoord(value);
//	document.getElementById(activeValue).value = value;
//}

document.onmouseup = function falg0(){
	flag = 0;
}
function overDiv1(){
	over = 1
	wStrategy = 1;
	activeCursor = "imgId1";
	activeValue = "value1";
	activeBlock = "moveBlock1";
}
function outDiv1(){
	over = 0
}

function overDiv2(){
	over = 1
	wStrategy = 2;
	activeCursor = "imgId2";
	activeValue = "value2";
	activeBlock = "moveBlock2";
}
function outDiv2(){
	over = 0
}

function overDiv3(){
	over = 1
	wStrategy = 3;
	activeCursor = "imgId3";
	activeValue = "value3";
	activeBlock = "moveBlock3";
}
function outDiv3(){
	over = 0
}

function overDiv4(){
	over = 1
	activeCursor = "imgId4";
	activeValue = "value4";
	activeBlock = "moveBlock4";
}
function outDiv4(){
	over = 0
}



// showe block


function visibilitiCalc(changeBg, activeCalc, opacity, frame){
bgCol = document.getElementById(changeBg).style
checkCalc = document.getElementById(activeCalc).checked
opacity = document.getElementById(opacity).style
frame = document.getElementById(frame).style
	if(checkCalc == true){
		bgCol.background = '#e1e3d8'
		opacity.filter='alpha(opacity=100)'
		opacity.opacity = (1);
		opacity.MozOpacity = (1);
		opacity.KhtmlOpacity = (1);
		frame.zIndex = '13'
	}
bgCols1 = document.getElementById('changeBg1').style
bgCols2 = document.getElementById('changeBg2').style
bgCols3 = document.getElementById('changeBg3').style
checkCalcs1 = document.getElementById('activeCalc1').checked
checkCalcs2 = document.getElementById('activeCalc2').checked
checkCalcs3 = document.getElementById('activeCalc3').checked
opacitys1 = document.getElementById('opacity1').style
opacitys2 = document.getElementById('opacity2').style
opacitys3 = document.getElementById('opacity3').style
frames1 = document.getElementById('frame1').style
frames2 = document.getElementById('frame2').style
frames3 = document.getElementById('frame3').style
	if(checkCalcs1 == false){
		bgCols1.background = '#fcfcf2'
		opacitys1.filter='alpha(opacity=30)'
		opacitys1.opacity = (0.3);
		opacitys1.MozOpacity = (0.3);
		opacitys1.KhtmlOpacity = (0.3);
		frames1.zIndex = '16'
	}	
	if(checkCalcs2 == false){
		bgCols2.background = '#fcfcf2'
		opacitys2.filter='alpha(opacity=30)'
		opacitys2.opacity = (0.3);
		opacitys2.MozOpacity = (0.3);
		opacitys2.KhtmlOpacity = (0.3);
		frames2.zIndex = '16'
	}	
	if(checkCalcs3 == false){
		bgCols3.background = '#fcfcf2'
		opacitys3.filter='alpha(opacity=30)'
		opacitys3.opacity = (0.3);
		opacitys3.MozOpacity = (0.3);
		opacitys3.KhtmlOpacity = (0.3);
		frames3.zIndex = '16'
	}	
}


























