/**
 * catalog.compel.ru
 * JavaScript Client Side Application
 */

function pe_ShowFilterConfig(filter_txt) {
  $.prompt(filter_txt, {buttons:{}, prefix:'pejqi', persistent:false, submit:pe_SubmitFilter });
  //$.prompt(filter_txt, {buttons:{},  persistent:false, submit:pe_SubmitFilter });
}

function pe_SubmitFilter (stat) {
  if (stat == 1) {
    var url = "?"+$("#pe_filters").formSerialize();
    window.open(url, "_self");
  } else if (stat == 2) {
    alert('TODO: сделать :-)');
  }
}

function jspsShowFilterCfg(fi) {
  var tmpo = document.getElementById("main");
  var oldbg = document.getElementById('main').getAttribute('color');
  document.getElementById("ps_option").innerHTML = fi+': min <input type="text" value="" /> typ <input type="text" value="" /> max <input type="text" value="" />';
}



function peSendAjaxReq(phpscript, phpreq, divid) {
  var xmlHttpReq = false;
  var self = this;
  // Mozilla/Safari
  if (window.XMLHttpRequest) {
    self.xmlHttpReq = new XMLHttpRequest();
  }
  // IE
  else if (window.ActiveXObject) {
    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  self.xmlHttpReq.open('POST', '/'+phpscript, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4) {
      document.getElementById(divid).innerHTML = self.xmlHttpReq.responseText;
      //sm(divid,500,500);
    }
  }
  self.xmlHttpReq.send(phpreq);
}


function peGetParam(name) {
  var start=location.search.indexOf("?"+name+"=");
  if (start<0) start=location.search.indexOf("&"+name+"=");
  if (start<0) return '';
  start += name.length+2;
  var end=location.search.indexOf("&",start)-1;
  if (end<0) end=location.search.length;
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
}
