var fcid;

function actionForValidator(cid, vid)
{
   cid = $(cid); if (!cid) return;
   if (!fcid) fcid = cid;
   cid.className = 'errorhere';
   cid.onclick = function(){this.className = 'errorhereunset'; if (vid) $(vid).setHTML('');};
}

function actionValidator(cid, vid, class1, class2)
{
   cid = $(cid); if (!cid) return;
   cid.className = class2;
   cid.onclick = function(){this.className = class1; if ($(vid)) $(vid).setHTML('');};
}

function unactionValidator(cid, vid, class1)
{
   cid = $(cid); if (!cid) return;
   cid.className = class1;
   if ($(vid)) $(vid).setHTML('');
}

function showMenu(menuid, divid)
{
   var menu = $(menuid);
   var div = $(divid);
   if (menu == undefined || div == undefined) return;
   var size = menu.getSize();
   var coor = menu.getCoordinates();
   div.style.top = coor.top + size.y;
   div.style.left = coor.left;
   div.style.visibility = 'visible';
}

function shBlock(menuid, divid)
{
   var menu = $(menuid);
   var el = $(divid);
   if (menu == undefined || el == undefined) return;
   var coor = menu.getCoordinates();
   el.style.zIndex = '999';
   el.style.position = 'absolute';
   el.style.top = coor.top - 1 + 'px';
   el.style.left = coor.left + 26 + 'px';
   el.display();
}

function shBlockA(menuid, divid)
{
   var menu = $(menuid);
   var el = $(divid);
   if (menu == undefined || el == undefined) return;
   var coor = menu.getCoordinates();
   el.style.zIndex = '999999999';
   el.style.position = 'absolute';
   el.style.top = coor.top - 1 + 'px';
   el.style.left = coor.left + 26 + 'px';
   el.display();
}

function selectZone(id)
{
  id = id - 1;
  zones = new Array('topleftzone','skyscrapers','topzone','contentleftzone','contentrightzone','right1','popupmes','popunder');
  for (i = 0; i < zones.length; i++)
  {
    if (i == id) {
      if(i == 6 ) {
      	//ajax.call('updateCode');
      	continue;
      }

      if(i == 7 ) {
      	continue;
      }

      if(i == 5) {
  	    $('right1').style.background = 'red';
  	    $('right2').style.background = 'red';
  	    $('right3').style.background = 'red';
  	    //ajax.call('updateCode');
  	  } else {
  	  	$(zones[i]).style.background = 'red';
		//ajax.call('updateCode');
  	  	$('right1').style.background = '#757575';
        $('right2').style.background = '#757575';
        $('right3').style.background = '#757575';
  	  }

    }
    else
    {
      if (i == 6) {
      	continue;
      }
      if (i == 7) {
      	 continue;
      } else {
  	    $(zones[i]).style.background = '#757575';
  	    $('right1').style.background = '#757575';
        $('right2').style.background = '#757575';
        $('right3').style.background = '#757575';
      }
  	}
  }
}

function selectRadio(zone)
{
  zones = new Array('topleftzone','skyscrapers','topzone','contentleftzone','contentrightzone','right1');
  $('zone' + zone).checked = true;
  cell = zone - 1;
  for (i = 0; i < zones.length; i++) {
  	if (i == cell) {
    	if (cell == 5) {
      	  $('right1').style.background = 'red';
          $('right2').style.background = 'red';
          $('right3').style.background = 'red';
    	} else {
          $(zones[cell]).style.background = 'red';
      	  $('right1').style.background = '#757575';
          $('right2').style.background = '#757575';
          $('right3').style.background = '#757575';
        }
    } else {
      $(zones[i]).style.background = '#757575';
  	  $('right1').style.background = '#757575';
      $('right2').style.background = '#757575';
      $('right3').style.background = '#757575';
    }
  }
}

function parseSiteURL( strURL )
{
   if ( strURL == '#' ) return strURL;
   var s = strURL.replace(/[^a-zA-Z0-9-\.]/g,'-');
   return s.toLowerCase();
}

function createCrop(id, w, h)
{
   if (!$(id)) return;
   var crop = new MooCrop(id, {imgwidth: w, imgheight: h});
   var indicator = new Element('span', {'styles': {'position': 'absolute', 'display': 'none', 'padding': '4px', 'opacity': '.7', 'background': '#ffffff', 'border': '1px solid #525252', 'font-size': '11px'}}).injectInside(crop.wrapper);
   indicator.setStyles({'top': crop.getCropInfo().bottom + 10, 'left': crop.getCropInfo().left}).set('text', 'w: ' + crop.getCropInfo().width + ' h: ' + crop.getCropInfo().height);
   crop.addEvent('onBegin', function(imgsrc,crop,bound,handle){indicator.setStyle('display', 'block');});

   var extWidth = 'imgwidth';
   var extHeight = 'imgheight';
   if ( id == 'imgsourcelogo' )
   {
      extWidth = 'imgwidthlogo';
      extHeight = 'imgheightlogo';
   }

   crop.addEvent('onCrop', function(imgsrc,crop,bound,handle){indicator.setStyles({'top': crop.bottom + 10, 'left': crop.left}).set('text', 'w: ' + crop.width + ' h: ' + crop.height); $(extWidth).value = crop.width; $(extHeight).value = crop.height;});
   crop.addEvent('onComplete' , function(){indicator.setStyle('display', 'none');});
   return crop;
}

function selectDefaultZone(id)
{
  id = id - 1;
  zones = new Array('skyscrapers','topzone','contentleftzone','contentrightzone','right1','topleftzone','right2','right3');
  for (i = 0; i < zones.length; i++) {
    $(zones[i]).style.background = '#757575';
  }
  $(zones[id]).style.background = 'red';
  id = id + 1;
  ajax.call('getDefaultValue', id, '');
  return false;
}

function selectDefaultRadio(zone)
{
  zones = new Array('skyscrapers','topzone','contentleftzone','contentrightzone','right1','topleftzone','right2','right3');
  $('zone' + zone).checked = true;
  for (i = 0; i < zones.length; i++) {
   $(zones[i]).style.background = '#757575';
  }
  cell = zone - 1;
  $(zones[cell]).style.background = 'red';
  ajax.call('getDefaultValue', zone);
}

// table mouseover animation for DIV.options hide IE bug
function tableHighlight2(id,tag,classn) {
   $each($(id).getElements(tag), function(obj) {
      obj.addEvent('mouseenter',function(){
         this.addClass(classn);
         var divs = this.getElementsByTagName("div");
         for (i=0;i<=divs.length;i++)
         {
            var j = divs[i];
            if ( typeof j!=='undefined' )
            if (j.className == 'options' || j.className == 'optionsDomain')
            { j.style.visibility='visible'; };
         };
      });

      obj.addEvent('mouseleave',function(){
         this.removeClass(classn);
         var divs = this.getElementsByTagName("div");
         for (i=0;i<=divs.length;i++)
         {
            var j = divs[i];
            if ( typeof j!=='undefined' )
            if (j.className == 'options' || j.className == 'optionsDomain' )
            { j.style.visibility='hidden'; };
         };
      });
   });
}