function getXmlHttp(){
  var http;
  try {
    http = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      http = false;
    }
  }
  if (!http && typeof XMLHttpRequest!='undefined') {
    http = new XMLHttpRequest();
  }
  return http;
}



//добавление в избранное (в статьях, например)
function add2Fav (x){
if (document.all  && !window.opera) {
	if (typeof window.external == "object") {
		window.external.AddFavorite (document.location, document.title); return true;
	}else return false;
}else{
	x.href=document.location;
	x.title=document.title;
	x.rel = "sidebar";
	return true;
}
}



//в окне обратного звонка
function check_form_inp(target){
	var stil=target.getAttribute('class');
	if(stil=='input_noactive'){ target.setAttribute('class', 'input_active'); }else{ target.setAttribute('class', 'input_noactive');}
}



function count_price(){ 
	var count_price_thick=document.forms["count_price_form"].count_price_thick.value;
	var count_price_area=document.forms["count_price_form"].count_price_area.value;
	
	document.getElementById('count_price_allprice').innerHTML=count_price_thick*count_price_area*12;
	document.getElementById('count_price_partprice').innerHTML=count_price_thick*count_price_area/1000;
}




function VisualLoad(target){
	if(document.getElementById(target)){
	document.getElementById(target).innerHTML="<img src=\"images/loader.gif\" />";
	}
}











function Send_CB_form(){
	var error_form=1;
var http = getXmlHttp();
document.getElementById('callback_form_area_status').className="panel_bt_load SmallTxt";
//document.getElementById('callback_form_area_status').innerHTML="";
	var name=document.forms["callback_form"].man_name.value;
	var phone=document.forms["callback_form"].man_phone.value;
	
	if(phone=="" || phone.length<7){
	document.getElementById('CB_phone').style.color="red";
	error_form=2;	}
	
	if(name=="" || name.length<2){
	document.getElementById('CB_name').style.color="red";
	error_form=2; }

	
	
if(error_form==1){
	//вернуть кнопку на место
	
	
var url = "http://www.tehnopena.ru/parts/send_mail_cb.php";
var params = "callback=true";
params+="&name="+name;
params+="&phone="+phone;
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {	
	document.getElementById('callback_form_area').innerHTML=http.responseText;
}
}
http.send(params); 
}else{
	document.getElementById('callback_form_area_status').className="panel_bt_ok";
}
return false; }





function faq_write(id){
document.getElementById(id).value="";
document.getElementById(id).className="faq_input";
}
	



function Send_FAQ_form(){
	var error_form=1;
var http = getXmlHttp();
document.getElementById('faq_form_area_status').className="panel_bt_load";
//document.getElementById('callback_form_area_status').innerHTML="";
	var name=document.forms["faq_ask_form"].faq_name.value;
	var contact=document.forms["faq_ask_form"].faq_contact.value;
	var question=document.forms["faq_ask_form"].faq_question.value.replace('#[\n\r]+#', "\\n");;
	//var question=document.getElementById('faq_question').innerHTML.split("\u000A").join("<br />\u000A");
	
	var regular = /[A-z0-9]/g;
	
	if(name=="Ваше имя?" || name.length<2 || regular.exec(name)!=null){
	document.getElementById('FAQ_name').style.color="red";
	error_form=2; }

	if(contact=="email, телефон" || contact.length<3){
	document.getElementById('FAQ_contact').style.color="red";
	error_form=2; }
	
	if(question=="email, телефон" || question.length<3){
	document.getElementById('FAQ_question').style.color="red";
	error_form=2; }

	

if(error_form==1){

var url = "http://www.tehnopena.ru/parts/send_mail_faq.php";
var params = "faq=true";
params+="&name="+name;
params+="&contact="+contact;
params+="&question="+question;

http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {	
	document.getElementById('faq_form_area').innerHTML=http.responseText;
}
}
http.send(params);
}else{
	document.getElementById('faq_form_area_status').className="panel_bt_ok";
}
return false; }





//////// отправка комментария ///////////
function SendCommentForm(){
	var error_form=1;
var http = getXmlHttp();
	document.getElementById('submitComment').className="panel_bt_load";

	var name=document.forms["addCommentForm"].CommentName.value;
	var email=document.forms["addCommentForm"].CommentMail.value;
	var forPage=document.forms["addCommentForm"].forPage.value;
	var message=document.forms["addCommentForm"].CommentMessage.value.replace('#[\n\r]+#', "\\n");
	
	var regular = /[A-z0-9]/g;
	
	if(name.length<2 || regular.exec(name)!=null){
	document.getElementById('CommentNameSt').style.color="red";
	error_form=2; }else{document.getElementById('CommentNameSt').style.color="#333";}

	email = email.replace(/^\s+|\s+$/g, '');
	if(!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email)){
		document.getElementById('CommentMailSt').style.color="red";
	error_form=2;
	}else{document.getElementById('CommentMailSt').style.color="#333";}
 
	if(message=="" || message.length<3){
	document.getElementById('CommentMessageSt').style.color="red";
	error_form=2; }else{document.getElementById('CommentMessageSt').style.color="#333";}

	

if(error_form==1){
	
var url = "../../parts/comments.php";
var params = "newComment=true";
params+="&forPage="+forPage;
params+="&name="+name;
params+="&email="+email;
params+="&message="+message;

http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {	
	//document.getElementById('faq_form_area').innerHTML=http.responseText;
	document.getElementById('submitComment').className="";
	$('#addCommentContainer').slideToggle(500);//alert(http.responseText);
	$("#CommentCore").append(http.responseText);
	//$(http.responseText).hide().insertBefore('#addCommentContainer').slideDown();
	
}
}
http.send(params);
}else{
	document.getElementById('submitComment').className="";
}
return false; }

//////// отправка комментария ///////////









function show_yandex_map_ext(ob, coords_1, coords_2, branch_name, branch_text, zoom)
{
  zoom = zoom || 15;
    YMaps.jQuery(function(){
        var map = new YMaps.Map(YMaps.jQuery("#"+ob)[0]);
        map.setCenter(new YMaps.GeoPoint(coords_1,coords_2), zoom, YMaps.MapType.MAP);
        map.addControl(new YMaps.Zoom());
        map.addControl(new YMaps.ToolBar());
        map.addControl(new YMaps.TypeControl());
        YMaps.Styles.add(
          "constructor#pmdblPlacemark",
          {
            iconStyle : {
              size : new YMaps.Point(36,41),
              offset: new YMaps.Point(-13,-40)
          }
        });
        var legend = new YMaps.Placemark(new YMaps.GeoPoint(coords_1, coords_2), {style: 'default#orangePoint'});
        var legend_content = '<div style=" width:200px; font-size: 12px; margin-bottom: 5px;"><b style="width:200px; font-size: 14px; color: #000000;">'+branch_name+'</b></div>'+branch_text;
        legend.setBalloonContent(legend_content);
        map.addOverlay(legend);
        legend.setIconContent('<b style=" width:200px; color: #000000;">'+branch_name+'</b>');
    });
}
