var xmlHttp;
topedge = 0;  // location of news box from top of page
leftedge = 0;  // location of news box from left edge
boxheight = 120;  // height of news box
boxwidth = 195;  // width of news box
scrollheight = 200; // total height of all data to be scrolled
currentTop = 0;
//var blank="..img/blank.gif";
var timeOut;


/*-------------------------------------------------------------------------*/
// Базовый метод посылает запрос для асинхронного вызова
/*-------------------------------------------------------------------------*/
function OnAsyncGetMenu(Link) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Браузер не поддерживает запросы HTTP");
        return;
    }

    xmlHttp.onreadystatechange = OnAsyncGetMenuResult;
    xmlHttp.open("GET", Link + "?r=" +Math.random() , true);
    xmlHttp.send(null);
}


/*-------------------------------------------------------------------------*/
// Базовый метод посылает запрос для асинхронного вызова
/*-------------------------------------------------------------------------*/
function OnAsyncGetRequest() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Браузер не поддерживает запросы HTTP");
        return;
    }

	url = onGetParamsByForm(form2);
    xmlHttp.onreadystatechange = OnAsyncGetRequestResult;
    xmlHttp.open("POST", "formmail.php", true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(url);
}


/*-------------------------------------------------------------------------*/
// Функция отслеживания обратного вызова для контрола ajaxcombobox 
/*-------------------------------------------------------------------------*/
function OnAsyncGetRequestResult() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

		  var rez = xmlHttp.responseText;
		  if(rez.length != 0)
		  {
			    alert(rez);
		  		document.getElementById("csPopupReport").innerHTML = TemplateResultPopup(rez);
		  }
		  else
		 {
		  		document.getElementById("csPopupReport").innerHTML = TemplateResultPopup("<div style=\"font: normal 14px arial,helvetica; background-color:white;\">Запрос отправлен<br> Наш менеджжер в ближайшее время свяжется с Вами.<br>Спасибо за обращение в нашу компанию.</div>");
	
		 }
			
//        }
    }
}


/*-------------------------------------------------------------------------*/
// Функция отслеживания обратного вызова для контрола ajaxcombobox 
/*-------------------------------------------------------------------------*/
function OnAsyncGetMenuResult() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

        var obj = document.getElementById("csNews");
        if (obj != null) {
            obj.innerHTML = xmlHttp.responseText;
        }
    }
}

/*-------------------------------------------------------------------------*/
// Вспомогательный метод определения класса для асинхронного вызова процедур
/*-------------------------------------------------------------------------*/
function GetXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        try {
            objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                new XMLHttpRequest();
            }
        }
    }
    return objXMLHttp;
}




/* Начальная функция определяющая порядок загрузки методов*/
function addLoadEvent(func) {   
   var oldonload = window.onload;   
  if (typeof window.onload != 'function') {   
    window.onload = func;   
  } else {   
     window.onload = function() {   
       if (oldonload) {   
        oldonload();   
      }   
      func();   
     }   
   }   
 }  


function scrollnews(cliptop) 
{
var element = document.getElementById("news");

if(element ==null) return;

if(element.style.visibility == 'hidden')
{
news.style.visibility='visible';
var element = document.getElementById("news");
var bounds = getElementSize(element);

 topedge = bounds.top;
 leftedge = bounds.left;
 news.style.position = "absolute";
}

if (document.layers) {
newsDiv = document.news;
newsDiv.clip.top = cliptop;
newsDiv.clip.bottom = cliptop + boxheight;
newsDiv.clip.left = 0;
newsDiv.clip.right = boxwidth + leftedge;
newsDiv.left = leftedge;
newsDiv.top = topedge - cliptop;
					}
else {
newsDiv = news.style;
newsDiv.clip = "rect(" + cliptop + "px " + (boxwidth + leftedge) + "px " + (cliptop + boxheight) + "px 0px)";
newsDiv.pixelLeft = leftedge;
newsDiv.pixelTop = topedge - cliptop;
	}

cliptop = (cliptop + 1) % (scrollheight + boxheight);
currentTop = cliptop;
timeOut = setTimeout("scrollnews(" + cliptop + ")", 50);
}



/*-------------------------------------------------------------------------*/
// Вспомогательная функция определяет размеры и положение элемента
/*-------------------------------------------------------------------------*/
function getElementSize(element) {
    var left = element.offsetLeft;
    var top = element.offsetTop;
    for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
        left += parent.offsetLeft - parent.scrollLeft;
        top += parent.offsetTop - parent.scrollTop
    }
    return { left: left, top: top, width: element.offsetWidth, height: element.offsetHeight };
}

var slideShowSpeed = 3000;
var crossFadeDuration = 3;
/*
var Pic = new Array();

Pic[0] = 'images/wms_1.jpg';
Pic[1] = 'images/wms_2.jpg';
Pic[2] = 'images/wms_3.jpg';
Pic[3] = 'images/wms_4.jpg';
Pic[4] = 'images/wms_5.jpg';

var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();

for (i = 0; i < p; i++)
{
	preLoad[i] = new Image();
	preLoad[i].src = Pic[i];
}
*/
function runSlideShow()
{
	if (document.all){
		document.images.SlideShow.style.filter='blendTrans(duration=2)';
		document.images.SlideShow.style.filter='blendTrans(duration=crossFadeDuration)';
		document.images.SlideShow.filters.blendTrans.Apply();
		}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all){
		document.images.SlideShow.filters.blendTrans.Play();
		}
	j = j + 1;
	if (j > (p-1)) j=0;
	t = setTimeout('runSlideShow()', slideShowSpeed);
}

function runPartnerShow()
{
	if (document.all){
		document.images.partnerShow.style.filter='blendTrans(duration=2)';
		document.images.partnerShow.style.filter='blendTrans(duration=crossFadeDuration)';
		document.images.partnerShow.filters.blendTrans.Apply();
		}
	document.images.partnerShow.src = partnerLoad[j2].src;
	if (document.all){
		document.images.partnerShow.filters.blendTrans.Play();
		}
	j2 = j2 + 1;
	if (j2 > (p2-1)) j2=0;
	t2 = setTimeout('runPartnerShow()', slideShowSpeed);
}


// --------------------------------------------------------------------------------
// Tree control events
// --------------------------------------------------------------------------------
function tree_showBranch(branch)
{
  var objBranch = document.getElementById(branch).style;

  if(objBranch.display=="block")
    objBranch.display="none";
  else
    objBranch.display="block";
}


function tree_swapFolder(img)
{
  objImg = document.getElementById(img);

  if(objImg.src.indexOf('plus') > -1)
    objImg.src = "images\\minus.gif";
  else
    objImg.src = "images\\plus.gif";
}


function tree_swapFolder1(img)
{
  objImg = document.getElementById(img);

  if(objImg.src.indexOf('folder_opened.gif') > -1)
    objImg.src = "images\\folder.gif";
  else if(objImg.src.indexOf('folder.gif') > -1)
      objImg.src = "images\\folder_opened.gif";
}


function tree_swapFolder2(img)
{
  objImg = document.getElementById(img);

  if(objImg.src.indexOf('arrow_up.gif') > -1)
    objImg.src = "../images/arrow_down.gif";
  else if(objImg.src.indexOf('arrow_down.gif') > -1)
      objImg.src = "../images/arrow_up.gif";
}
// --------------------------------------------------------------------------------


function TemplatePopupForm(message)
{
	var result = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#dfe8f6\">"
        + "<tr>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_left_background.gif);\"></td>"
        + "<td height=\"2px\" style=\"background-image:url(../images/cs_form_top_center_background.gif); background-repeat:repeat-x\"></td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td class=\"csReportHeader\">"
        + "<table cellspacing='0' cellpadding='1' width=100%>"
        + "<tr>"
        + "<td height=\"10\" class=\"cs_leftMenuHead\">"
        + "<div id=\"csPopupReportHeader\" style=\"width:100%; height:100%; cursor:move;\">Отправка запроса</div></td>"
        + "<td align=\"right\"><img src=\"../images/close.gif\" border=\"0\" onclick=\"csHidePopupReport('csBackground');\" style=\"cursor:hand;\">"
        + "</td>"
        + "</tr>"
        + "</table>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td></tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td>"
        + "<div id=\"csPopupReportContent\" style=\"padding-right:10px;\">"
    	+ "<form method=\"POST\" action=\"formmail.php\" name=\"form2\">"
		+ "<input type=\"hidden\" name=\"recipient\" value=\"info@consid.ru\">"
		+ "<input type=\"hidden\" name=\"subject\" value=\"Запрос с сайта consid.ru\">"
		+ "<input type=hidden name=\"cc_email\" value=\"0\">"
		+ "<input type=\"hidden\" name=\"required\" value=\"email,name\">"
		+ "<input type=\"hidden\" name=\"env_report\" value=\"REMOTE_ADDR,HTTP_USER_AGENT\">"
		+ "<input type=\"hidden\" name=\"title\" value=\"Feedback Form Results\">"
		+ "<input type=\"hidden\" name=\"redirect\" value=\"http://www.consid.ru/contacts_good.html\">"
		+ "<input type=\"hidden\" name=\"missing_fields_redirect\" value=\"http://www.consid.ru/contacts_error.html\">"
        + "<div style=\"padding-left:10px; padding-top:14px\">"
        + "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
        +   "<tr>"
        +    "<td height=\"14\" colspan=\"2\" align=\"left\" valign=\"top\" class=\"style1\">Контактное лицо:</td>"
        +   "</tr>"
        +   "<tr>"
        +   "<td height=\"24\" colspan=\"2\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"name\" style=\"height:17px; width:216px; font-family:tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#CDCDCD;\"></td>"
        +   "</tr>"
        +   "<tr>"
        +   "<td height=\"14\" colspan=\"2\" align=\"left\" valign=\"top\" class=\"style1\">Ваш E-mail:</td>"
        +   "</tr>"
        +   "<tr>"
        +   "<td height=\"24\" colspan=\"2\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"email\" style=\"height:17px; width:216px; font-family:tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#CDCDCD \"></td>"
        +   "</tr>"
        +   "<tr>"
        +   "<td height=\"14\" colspan=\"2\" align=\"left\" valign=\"top\" class=\"style1\">Телефон:</td>"
        +   "</tr>"
        +   "<tr>"
        +   "<td height=\"24\" colspan=\"2\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"phone\" style=\"height:17px; width:216px; font-family:tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#CDCDCD \"></td>"
        +   "</tr>"
		        +   "<tr>"
        +   "<td height=\"14\" colspan=\"2\" align=\"left\" valign=\"top\" class=\"style1\">Компания:</td>"
        +   "</tr>"
        +   "<tr>"
        +  "<td height=\"24\" colspan=\"2\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"company\" style=\"height:17px; width:216px; font-family:tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#CDCDCD \"></td>"
        +   "</tr>"
        +   "<tr>"
        +    "<td height=\"14\" colspan=\"2\" align=\"left\" valign=\"top\" class=\"style1\">Текст сообщения:</td>"
        +   "</tr>"
        +    "<tr>"
        +   "<td colspan=\"2\" align=\"left\" valign=\"top\"><textarea name=\"message\" style=\"height:61px; width:216px; font-family:tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#CDCDCD; overflow:auto \"></textarea></td>"
        +    "</tr>"
        +   "<tr>"
        +   "<td width=\"90\" height=\"37\" align=\"left\" valign=\"top\"><div style=\"padding-left:10px; padding-top:4px\">"
        +   "<table width=\"77\" height=\"22\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
        +   "<tr>"
        +     "<td align=\"left\" valign=\"top\" background=\"../images/but_1.gif\"><div style=\"padding-left:7px; padding-top:3px; padding-bottom:5px\"><a href=\"#\" class=\"style11\" style=\"text-decoration:none\" onClick=\"form2.reset();\">Стереть</a></div></td>"
        +    "</tr>"
        +    "</table>"
        +    "</div></td>"
        +   "<td width=\"100\" align=\"left\" valign=\"top\"><div style=\"padding-left:0px; padding-top:4px\">"
        +    "<table width=\"77\" height=\"22\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
        +   "<tr>"
        +   "<td align=\"left\" valign=\"top\" background=\"../images/but_2.gif\"><div style=\"padding-left:7px; padding-top:3px\"><a href=\"#\" class=\"style11\" style=\"text-decoration:none;\"  onClick=\"OnAsyncGetRequest();\">Запрос</a></div></td>"
        +   "</tr>"
        +   "</table>"
        +   "</div></td>"
        +   "</tr>"
        +   "</table>"
        +   "</div>"
		+  "</form>"
		+"</div>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_left_background.gif);\"></td><td height=\"2px\" style=\"background-image:url(../images/cs_form_bottom_center_background.gif); background-repeat:repeat-x;\"></td><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_right_background.gif);\"></td></tr>"
        + "</table>";
	
	return result;
}

function TemplateInformation()
{
	var result = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#dfe8f6\">"
        + "<tr>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_left_background.gif);\"></td>"
        + "<td height=\"2px\" style=\"background-image:url(../images/cs_form_top_center_background.gif); background-repeat:repeat-x\"></td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td class=\"csReportHeader\">"
        + "<table cellspacing='0' cellpadding='1' width=100%>"
        + "<tr>"
        + "<td height=\"10\" class=\"cs_leftMenuHead\">"
        + "<div id=\"csPopupReportHeader\" style=\"width:100%; height:100%; cursor:move;\">Консультации</div></td>"
        + "</tr>"
        + "</table>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td></tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td>"
        + "<div id=\"csPopupReportContent\" style=\"font: normal 14px arial,helvetica; background-color:white;\">"
		+ "Телефон: <br>+7(495) <strong>729-83-70</><br><br>"
		+ "<script type=\"text/javascript\" src=\"http://download.skype.com/share/skypebuttons/js/skypeCheck.js\"></script>"
		+ "<a href=\"skype:consid77?call\"><img src=\"http://download.skype.com/share/skypebuttons/buttons/call_blue_white_124x52.png\" style=\"border: none;\" width=\"124\" height=\"52\" alt=\"Общение в Skype\" /></a><br>"
		+ "<img src=\"../images/icq.gif\" border=\"0\"/> 339-980-063 Дмитрий<br>"		
		+ "<img src=\"../images/icq.gif\" border=\"0\"/> 610-584-262 Илья<br><br>"				
		+ "<input type=\"button\" value=\"Отправить запрос\" onclick=\"csShowPopupReport('csBackground');\"/>"				
		+"</div>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_left_background.gif);\"></td><td height=\"2px\" style=\"background-image:url(../images/cs_form_bottom_center_background.gif); background-repeat:repeat-x;\"></td><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_right_background.gif);\"></td></tr>"
        + "</table>";
	
	return result;
}


function TemplateResultPopup(message)
{
	var result = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#dfe8f6\">"
        + "<tr>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_left_background.gif);\"></td>"
        + "<td height=\"2px\" style=\"background-image:url(../images/cs_form_top_center_background.gif); background-repeat:repeat-x\"></td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_top_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td class=\"csReportHeader\">"
        + "<table cellspacing='0' cellpadding='1' width=100%>"
        + "<tr>"
        + "<td height=\"10\" class=\"cs_leftMenuHead\">"
        + "<div id=\"csPopupReportHeader\" style=\"width:100%; height:100%; cursor:move;\">Результаты отправки запроса</div></td>"
        + "<td align=\"right\"><img src=\"../images/close.gif\" border=\"0\" onclick=\"csHidePopupReport('csBackground');\" style=\"cursor:hand;\">"
        + "</td>"
        + "</tr>"
        + "</table>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td></tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_left_background.gif); background-repeat:repeat-y;\"></td>"
        + "<td>"
        + "<div id=\"csPopupReportContent\" style=\"padding:10px;\">"
        + message+"</div>"
        + "</td>"
        + "<td width=\"2px\" style=\"background-image:url(../images/cs_form_right_background.gif);\"></td>"
        + "</tr>"
        + "<tr><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_left_background.gif);\"></td><td height=\"2px\" style=\"background-image:url(../images/cs_form_bottom_center_background.gif); background-repeat:repeat-x;\"></td><td width=\"2px\" style=\"background-image:url(../images/cs_form_bottom_right_background.gif);\"></td></tr>"
        + "</table>";
	
	return result;
}




/*----------------------------------------------------------------*/
// Возвращает все параметры формы в виде строки
/*----------------------------------------------------------------*/
function onGetParamsByForm(FormId) {

    var textString = '';
    // Определяем все параметры формы
    // Надо добавить другие параметры - список и т.п.

    for (i = 0; i < FormId.elements.length; i++) {
        oControl = FormId.elements[i];

		if(oControl != null && oControl.name != "")
		{
			var re = /&/g;
			var re1 = /\+/g;

			//var objValue = encodeURIComponent(oControl.value.replace(re, "%26").replace(re1, "%2B"));
			//var objValue = encodeURIComponent(oControl.value);
			var objValue = oControl.value;

			if (oControl.name != 'chk'
			&& (oControl.type == 'checkbox')) {
				if (oControl.value != 'false' && oControl.checked)
					textString += '&' + oControl.name + '=' + objValue;
				else
					textString += '&' + oControl.name + '=0';
			}
			else if (oControl.type == "text" | oControl.type == "textarea" | oControl.type == "password") {
			oControl.value = objValue;
			textString += '&' + oControl.name + '=' + objValue;
			}
			else if (oControl.type == "radio" && oControl.checked) {
			textString += '&' + oControl.name + '=' + objValue;
			}
			else if (oControl.type == "hidden" && oControl.name != 'chk' && oControl.name != "previousformpopup") {
			textString += '&' + oControl.name + '=' + objValue;
			}
			else if (oControl.selectedIndex != null) {
			textString += '&' + oControl.name + '=' + objValue;
			}
		}
    }
    return textString.substring(1);
}


/*----------------------------------------------------------------*/
// Обработка всплывающих слоев Всплывающий слой Открывается
/*----------------------------------------------------------------*/
function csShowPopupReport(branch)
{
  var objBranch = document.getElementById(branch).style;

  if(objBranch.display=="none")
  {
    objBranch.display="block";
	objBranch.zIndex=100;
  }
  objBranch = document.getElementById("csPopupReport").style;
  objBranch.display = "block";
  objBranch.zIndex = 200;
  SetCenterElement("csPopupReport");
}
/*----------------------------------------------------------------*/
// Всплывающий слой Закрывается
/*----------------------------------------------------------------*/
function csHidePopupReport(branch)
{
  var objBranch = document.getElementById(branch).style;
  objBranch.display = "none";
  objBranch.zIndex=0;
  
  objBranch = document.getElementById("csPopupReport").style;
  objBranch.display = "none";
  objBranch.zIndex=0;
}


/* ------------------------------------------------------------------------*/
// Центрирует всплывающий элемент по центру экрана
/* ------------------------------------------------------------------------*/
function SetCenterElement(element) {

    var elem = document.getElementById(element);

    if (window.innerWidth) {
        width = window.innerWidth;
        height = window.innerHeight;
    }
    else if (document.body && document.body.clientWidth) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }

    var widthIM = width / 2 - (elem.offsetWidth == 0 ? elem.scrollWidth : elem.offsetWidth) / 2;
    var heightIM = height / 2 - (elem.offsetHeight == 0 ? elem.scrollHeight : elem.offsetHeight) / 2;
    elem.style.left = (widthIM > 0 ? widthIM : 0);
    elem.style.top = (heightIM > 0 ? heightIM : 0);

}

