var _ISLOAD = false;
var mousex, mousey;
var Seted;
var _close;
var _msg_width;

isDOM = document.getElementById;
isOpera=isOpera5=window.opera && isDOM; //Opera 5+
isOpera6=isOpera && window.print; //Opera 6+
isOpera7=isOpera && document.readyState; //Opera 7+
isMSIE=document.all && document.all.item && !isOpera; //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE; //MSIE 5+
isNetscape4=document.layers; //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape"; //Mozilla или Netscape 6.*
isFirefox=isDOM && navigator.userAgent.toLowerCase().indexOf('firefox') != -1;


function addLoadEvent(fn) {
      var old = window.onload;
      if (typeof window.onload != 'function') {
         window.onload = fn;
      }
      else {
         window.onload = function() {
         old();
         fn();
         }
      }
   }


document.onmousemove = function _onMove(e) {
 if(!_ISLOAD)
   return false;


 if(!e)
   e = window.event;
   _getmousePos(e);

// window.status = mousex;
}



/*
function _onMove(e) {
 if(!e)
   e = window.event;
   _getmousePos(e);

// window.status = mousex;
}
*/

function getBodyScrollTop() {
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft() {
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


document.onclick = function () {
 if(!_ISLOAD)
   return true;

  _unsetId(Seted);
  _unsetId('_closeDiv');
}

function _getmousePos(e) {
   if (!e) 
     e = window.event;

    if (e.pageX || e.pageY) {
     mousex = e.pageX;
     mousey = e.pageY;
    }
  else if (e.clientX || e.clientY) {
    mousex = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    mousey = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }
}


function getEl(el) {
 if(document.getElementById(el))
   return document.getElementById(el);
 else 
   return false;
}

function _unsetId(id) {
  if(getEl(id)) {
//    getEl(id).style.display = 'none';
    getEl(id).style.left = -1000+'px';
    getEl(id).style.top = -1000+'px';
    getEl(id).style.visibility = 'hidden';  
  }
}


function _msg(txt) {
 if(!_ISLOAD)
   return false;

_id = '_closeDiv';

 if(!getEl(_id)) {

   var div = document.createElement("DIV") ;
    div.id = _id ;
    div.style.height = 12+'px' ;
    div.style.position = 'absolute' ;
    div.style.padding = '0 2px 0 2px';
    div.style.border = '1px solid #cccccc';
    div.style.zIndex = 200000;
    div.style.textAlign = 'left';
    div.style.fontFamily = 'Verdana';
    div.style.fontSize = 11+'px';
    div.style.whiteSpace = 'nowrap';
    div.style.fontWeight = 'normal';
    div.style.color = '#000000';
    div.style.backgroundColor= '#f0f0f0'
    div.innerHTML = txt;

    div.style.visibility = 'visible';

    document.body.insertBefore(div, document.body.lastChild);

    div.style.left = parseInt(mousex) + 15 + 'px';
    div.style.top = parseInt(mousey)  + 10 +'px';

    _msg_width = div.clientWidth;

   } 
  else {
   el = getEl(_id);
   el.innerHTML = '';
   el.innerHTML = txt;
   el.style.left = parseInt(mousex) + 15 + 'px';
   el.style.top = parseInt(mousey)  + 10 +'px';

   el.style.visibility = 'visible'; 
   el.style.display = 'block'; 
  } 

   if( parseInt(mousex) + (_msg_width + 40) < screen.width) {
    getEl('_closeDiv').style.left = mousex + 15 + 'px';;
    }
    else
      return true;

 getEl('_closeDiv').style.top = mousey + 10 + 'px';;

}

var III = 0;
var z1;
var z2;
function _resize(id, _H, _W) {

x = screen.width / 2;
y = screen.height / 2;

_w = parseInt(_W) + 2;
_h = parseInt(_H) + 2;

 if(III < _w) {
  getEl(id).style.width = III ;
  getEl(id).style.left = x - III / 2; 
 }
 else 
  z1 = true;

 if(III < _h) {
  getEl(id).style.height = III;
  getEl(id).style.top = y - III / 2;
 }
 else 
  z2 = true;

 III = III+10;

 if (z1 && z2) {
  clearInterval(_tm);
  getEl(id).innerHTML = _img;
  III = 0;
  z1 = false;
  z2 = false;
 }

}


var _tm;
var _img;
function _popUpImg(id, _target, _name, _alt, _border, _H, _W) {
  if(!_ISLOAD)
   return false;

 var trueId = 'popup0001';//+id;

// _msg_close = 'onmousemove=\"_msg(_CLOSEMSG);\" onmouseout=\"_unsetId(\'_closeDiv\');\"';
 _msg_close = '';

 _unsetId(trueId);
 _unsetId(Seted);

	x = screen.width ;
	y = screen.height;

 _left = parseInt(mousex) - parseInt(_W);
 _top = parseInt(mousey) -  parseInt(_H);

   if( _top < 0 || _top <= getBodyScrollTop() )
      _top = 1 + getBodyScrollTop();
   if( _left < 0 || _left <= getBodyScrollLeft() ) 
      _left = 1 + getBodyScrollLeft();

   _img = '<img id=\"layer'+id+'\" src=\"'+_name+'\" border=\"'+_border+'\" onClick=\"_unsetId(Seted)\" '+_msg_close+' alt\"'+_alt+'\"  title=\"'+_alt+'\" style=\"cursor:pointer\"/>';


   if (_target != '') {
    getEl('bigpic').innerHTML = '<img id=\"layer'+id+'\" src=\"'+_name+'\" border=\"'+_border+'\" onClick=\"_unsetId(Seted)\" alt\"'+_alt+'\"  />';;
    return true;
   }


    
 if(!getEl(trueId)) {

   var div = document.createElement("DIV") ;
    div.id = trueId ;
    div.style.position = 'absolute' ;
    div.style.left = 0 +'px';
    div.style.top =  0 +'px';
    div.style.width = getEl('body0').clientWidth +'px';
	  div.style.height =  getEl('body0').clientHeight +'px'; 
    div.style.textAlign = 'left';
    div.style.whiteSpace = 'nowrap';
    div.style.fontWeight = 'normal';
    div.style.padding = '2px 2px 2px 2px';
    div.style.zIndex = 10000;
    div.style.color = '#000000';
    div.style.backgroundColor= '#cbee88';
    div.style.border= '0px solid #90b744';

    div.style.visibility = 'visible';

    document.body.insertBefore(div, document.body.lastChild);
      if(isMSIE5) {
        div.style.zIndex = 150000;
      }

    Seted = trueId;
   } 
  else {
   el = getEl(trueId);
   el.style.width = getEl('body0').clientWidth+'px';
   el.style.height = getEl('body0').clientHeight+'px';
   el.innerHTML = '';
   el.style.left = 0+'px';
   el.style.top =  0+'px';
   el.style.visibility = 'visible'; 
//   el.style.display = 'block'; 
  }
  getEl(trueId).innerHTML = '<div style="position:absolute;left:50%;top:50%;margin-left:-'+_W/2+';margin-top:-'+_H/2+'">'+_img +'</div>';
}



function CheckForm(_alert) {
var arr;
  for(var z=0;z< document.contacts.elements.length;z++)  {
     if(document.contacts.elements[z].type == 'text' || document.contacts.elements[z].type == 'textarea')  {
        arr = document.contacts.elements[z].id.split('_') ;        
        if(document.contacts.elements[z].value == '' && arr[1] != 's')  {
          ttl = document.contacts.elements[z].name;

          alert(_alert+" : " +ttl+"!");
          document.contacts.elements[z].focus();
          return false;
          }
      }

  }
  document.contacts.submit();
}


function focusON (frm, thisname) {
 if ( (frm.value == thisname ) && (frm.defaultValue == thisname) ) frm.value = '';
// frm.style.backgroundColor = '#fff';
 frm.className = frm.defaultClassName;
}

function focusOFF (frm, thisname) {
 if ( (frm.value == '' ) && (frm.defaultValue == thisname) ) frm.value = thisname;
}



var lastopen;
function rjspopup (el) {
 if(getEl(lastopen)) {
    _unsetId(lastopen); 
    lastopen = '';
 }
// else {
    lastopen = el;
    getEl(el).style.display = 'block';
    getEl(el).style.visibility = 'visible';
// }	

}






/*
function _NewEL(_what, Id) {

var _NEW = document.createElement(_what);
    _NEW.id = Id ;
    _NEW.style.visibility = 'hidden';
    document.body.insertBefore(_NEW, document.body.lastChild);
}

_NewEL.prototype.action = function (_id, act) {
    _new = getEl(_id);
    _new.style.visibility = act;
}

function _popUpImg(id, _name, _alt, _border) {
 var trueId = 'popup'+id;

 _unsetId(trueId);

   var _H = 400;
   var _W = 400;

   _div = new _NewEL('DIV','popup'+id);

    div = getEl(trueId);
    div.style.width = _W+'px';
    div.style.height = _H+'px';
    div.style.position = 'absolute' ;
    div.style.left = parseInt(mousex) - parseInt(_W) +'px';
    div.style.top = parseInt(mousey) -  parseInt(_H) +'px';
    div.style.whiteSpace = 'nowrap';
    div.style.fontWeight = 'normal';
    div.style.padding = '2px 2px 2px 2px';
    div.style.zIndex = 10000;
    div.style.textAlign = 'left';
    div.style.border = '1px solid #7777d3';  
    div.style.color = '#000000';
    div.style.backgroundColor = '#cccccc';
    div.innerHTML = '<img id=\"layer'+id+'\" src=\"'+_name+'\" border=\"'+_border+'\" alt\"'+_alt+'\"  />';
    document.body.insertBefore(div, document.body.lastChild);
    _div.action(trueId, 'visible');

//onclick=\"this.style.visibility=\'hidden\' \"
// this.W = getEl(id).width;
// this.H = getEl(id).height;


 if(!getEl('popup'+id)) {
   } 
  else {
   el = getEl('popup'+id);
   el.innerHTML = '';
   el.innerHTML = '';
   el.style.left = mousex - 80 +'px';
   el.style.top = mousey + 25 +'px';
   el.style.visibility = 'visible'; 
   el.style.display = 'block'; 
  } 


}
*/

AC_FL_RunContent = 0; 
DetectFlashVer = 0;

//function BScheck(c,q) {
function BScheck(q) {

// if (c == 'Цветовое решение') {
//    alert('Укажите цвет');
//    return false;
// }
 if (q== 'количество') {
    alert('Укажите количество');
    return false;
 }
// if (c== 'Color') {
//    alert('Choose color');
//    return false;
// }
 if (q== 'quantity') {
    alert('Choose quantity');
    return false;
 }

// return  c+'_'+q; 
 return  q; 
}

function addToBasket(id,cost) {
 getEl('ok'+id).innerHTML = '';
// p=BScheck(eval("in_c"+id),eval("in_q"+id));
 p=BScheck(eval("in_q"+id));
 if(p) {
  getEl('body0').style.cursor = 'wait';
  url = '/site/inc/page.order.withbasket.php?a=add&doc='+id+'&p='+p+'&cost='+cost;
  h_get(url, checkResponse);
 }
}

function delFromBasket(id,q) {
 var is_confirmed = confirm(q);
  if (is_confirmed) {
//    p =  eval("in_c"+id)+'_'+eval("in_q"+id); 
    url = '/site/inc/page.order.withbasket.php?a=del&doc='+id;
    h_get(url, checkResponse);
  }
}


function XmlGetVal(ID) {
   tmp =  response.getElementsByTagName(ID)[0];
   return  tmp.getAttributeNode("val").value;
}

function checkResponse() {
 state = req.readyState;  
 if(state == 4) {
   response_ = req.responseText;
   response = req.responseXML;
//   alert(response_); 
   STATUS = XmlGetVal('status');
   ID = XmlGetVal('id');
   P = XmlGetVal('price');
   Ct = XmlGetVal('flcount');
   Fltxt = XmlGetVal('fltxt');
   delivery = XmlGetVal('delivery');
   totalcost = XmlGetVal('totalcost');
   
   if (STATUS == 'add') {
     getEl('flcount').innerHTML = Ct;
     getEl('fltxt').innerHTML = Fltxt;
     getEl('ok'+ID).innerHTML = '<img src="/site/img/ok.gif" alt="" border="0" >';
   }
   else if (STATUS == 'del') {
     getEl(ID).style.display = 'none';
     getEl('fltxt').innerHTML = Fltxt;
     getEl('flcount').innerHTML = Ct;
     getEl('delivery').innerHTML = delivery;
     getEl('digit').innerHTML = parseInt(getEl('digit').innerHTML) - parseInt(P) + parseInt(delivery);

      if(Ct == 0)
        window.location.href = window.location.href;
   }
 }
 getEl('body0').style.cursor = 'default';
}

function clearForm(form) {
 getEl(form).reset();
}

function sendOrder(form) {
 getEl(form).submit();
}


function hrcu(obj,id) {
	obj.style.display = 'none';
	obj.style.visibility = 'hidden';
	getEl('rcu'+id).style.display = 'block';
	getEl('rcu'+id).style.visibility = 'visible';

	return false;
}

/*
function Animate(divId) {
	var oThis = this;
	var aImg  = document.getElementById(divId).getElementsByTagName('img');
	var m1 = 100, m2 = 0, nextImage = 0, t = "";
	var oImg1 = '', oImg2 = '';

	this.next = function() {
		if (t != "") return;
		m1 = 100;
		m2 = 0;
		oImg1 = aImg[nextImage];	
		nextImage++;
		if (nextImage == aImg.length) { nextImage = 0; }  
		oImg2 = aImg[nextImage];	
		oThis.changeSlide();
	}

	this.changeSlide = function(){
		m1--; m2++;
		oImg1.style.opacity = m1/100;
		oImg1.style.filter="alpha(opacity="+m1+")";
		oImg2.style.opacity = m2/100;
		oImg2.style.filter="alpha(opacity="+m2+")";
		t = setTimeout(oThis.changeSlide,5);
		if (m2 == 100) {
			clearTimeout(t); t = ""; 
			setTimeout(oThis.next,3000);
		}
	}

	setTimeout(oThis.next,1000);
}

//window.onload = function() { new Animate('img1'); new Animate('img2');  }
*/