var itp_static_url='http://static.seopult.ru';
var main_static_url='http://static.seopult.ru';
var itp_min_seobudget = 25;
var itp_min_trafbudget = 3;
var itp_max_seobudget = 500000;
var default_process="<img src='"+itp_static_url+"/themes/default/_img/loader.gif' height='16' width='16'>";
var default_process_tiny="<img src='"+itp_static_url+"/themes/default/_img/loader-tiny.gif' height='16' width='16'>";
String.prototype.trim = function() {return this.replace(/^[\s\r\n\t]+|[\s\r\n\t]+$/g,'');};
String.prototype.remove_dbl_spaces = function() {return this.replace(/\s{2,}/g,' ');};
String.prototype.addslashes = function() {return this.replace(/([\"\']{1})/g, "\\$1").replace(/\0/g, "\\0");}
function function_exists (func_name) {if (typeof func_name === 'string') {func_name = this.window[func_name];}return typeof func_name === 'function';}
function exec_when_function(function_name,callback){if(function_exists(function_name)){eval(callback);}else{setTimeout("exec_when_function('"+function_name+"','"+callback.addslashes()+"')",100);}}
function load_js_src(js_src, async){var scriptElem = document.createElement('script');scriptElem.setAttribute('src',js_src);scriptElem.setAttribute('type','text/javascript');if (!!async){scriptElem.setAttribute('async', 'true');}document.getElementsByTagName('head')[0].appendChild(scriptElem);}
function set_opacity(op_obj, op_val){if (typeof op_obj!="object") op_obj=document.getElementById(op_obj);op_obj.style.opacity=op_val;op_obj.style.MozOpacity=op_val;op_obj.style.KhtmlOpacity=op_val;op_obj.style.filter='alpha(opacity="'+(100*Number(op_val))+'")';}
function get_client_width(){return document.compatMode=='CSS1Compat'&&!window.opera?document.documentElement.clientWidth:document.body.clientWidth;}
function get_client_height(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;}
function get_document_width(){return (document.body.scrollWidth>document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;}
function get_document_height(){return (document.body.scrollHeight>document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;}
function get_body_scroll_top(){return self.pageYOffset||(document.documentElement&&document.documentElement.scrollTop)||(document.body&&document.body.scrollTop);}
function get_body_scroll_left(){return self.pageXOffset||(document.documentElement&&document.documentElement.scrollLeft)||(document.body&&document.body.scrollLeft);}
function rolik1(){return rolik(1);}
function rolik2(){return rolik(2);}
function rolik(rnum){showdiv('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="675" height="462" id="myFlashContent"><param name="movie" value="/themes/default/_img/virus/rolik'+rnum+'.swf"><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/themes/default/_img/virus/rolik'+rnum+'.swf" width="675" height="462"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]--></object>');}
function flashplay(source){showdiv('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+get_client_width()+'" height="'+(get_client_height()-60)+'"><param name="movie" value="'+source+'"><!--[if !IE]>--><object type="application/x-shockwave-flash" data="'+source+'" width="'+get_client_width()+'" height="'+(get_client_height()-40)+'"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]--></object>', '/loadimg.html?flash='+source);}
var videoplay_js_loaded=false;
function videoplay(source, dl_source) {if (!videoplay_js_loaded) {load_js_src(itp_static_url+'/themes/default/js/video/swfobject.js', false);load_js_src(itp_static_url+'/themes/default/js/video/flvplayer.js', false);video_js_loaded=true;}showdiv('<div id="video_select" style="background-color: #f9f9f9; padding-bottom: 7px;"><span id="video_lq" onclick="flvplayer(0, \''+source+'\', true)">Низкое качество</span> &nbsp; <span id="video_mq" onclick="flvplayer(1, \''+source+'\', true)">Среднее качество</span> &nbsp; <span id="video_hq" onclick="flvplayer(2, \''+source+'\', true)">Высокое качество</span></div><div id="flvplayer"></div>', dl_source);exec_when_function("flvplayer", "flvplayer(1, '"+source+"', true)");}
function upplay(upval) {showdiv('<object type="application/x-shockwave-flash" data="http://seopult.tv/files/flash/uppod.swf" width="900" height="508"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="movie" value="http://seopult.tv/files/flash/uppod.swf" /><param name="FlashVars" value="'+upval+'" /></object>');}
function upplay2(upval) {showdiv('<object width="660" height="495" id="player"><param name="movie" value="http://itvcom.ru/files/flash/uppod.swf"></param><param name="allowFullScreen" value="true"/><param name="allowscriptaccess" value="always"/><param name="wmode" value="transparent" /><param name="FlashVars" value="'+upval+'" /><embed src="http://itvcom.ru/files/flash/uppod.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="660" height="495" flashvars="'+upval+'"/></object>');}
function showdiv(inner_html, src_link, min_height) {var multup_obj=document.getElementById('multup');var small_win=!!min_height && get_client_height()<min_height;multup_obj.style.position=/MSIE [5-6]+.*Win/.test(navigator.userAgent)||small_win?'absolute':'fixed';multup_obj.style.top=String(10+(/MSIE [5-6]+.*Win/.test(navigator.userAgent)||small_win?get_body_scroll_top():0))+'px';multup_obj.innerHTML='<table cellspacing=0 cellpadding=0 border=0 align="center"><tr><td align="right" style="background-color: #f9f9f9;">'+(!!src_link?'<a href="'+src_link+'">скачать</a> &nbsp; ':'')+'<a href="javascript:closediv();">закрыть</a></td></tr><tr><td>'+inner_html+'</td></tr></table>';multup_obj.style.display='';set_opacity('sp_main_tbl', 0.3);}
function closediv(){var multup_obj=document.getElementById('multup');multup_obj.innerHTML='';multup_obj.style.display='none';set_opacity('sp_main_tbl', 1);}
function getInText(node){return node.innerText||node.textContent;}
function execute(id, url,while_loading,redirect_url,redirect_timeout, callback_on_success, callback_on_error) {
  if (id=='' || id=='default_execute_div') {
    id = 'default_execute_div';
    var goal = document.getElementById(id);
    if (!goal) {
      goal = document.createElement('div');
      goal.id = id;
      goal.style.display='none';
      document.getElementsByTagName('body')[0].appendChild(goal);
    }
  } else {
    var goal=document.getElementById(id);
    if (!goal){
      return false;
    }
  }
  
  if (!while_loading){
    goal.innerHTML = default_process;
  } else if (while_loading != '__empty__') {
    goal.innerHTML = while_loading;
  }
  var request   = false;
  var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP' );

  if ( window.XMLHttpRequest ) {
    request = new XMLHttpRequest;
  } else if ( window.ActiveXObject ) {
    for ( var i = 0; i < msxmlhttp.length; i ++ ) {
      try {
        request = new ActiveXObject( msxmlhttp[i] );
      } catch ( e ) {
        request = false;
      }
    }
  }
  if ( !request ) {
    return false;
  }
  request.onreadystatechange = function() { 
    if ( request.readyState == 4 ) {
      if ( request.status == 200 ) {
        var reg=/<script[^>]*?>(.*?)<\/script>/ig;
        var reg_repl=/<[\/]{0,1}script[^>]*?>/ig;
        var resp=request.responseText;
        if (scr=resp.match(reg)){
          resp=resp.replace(reg,"");
          goal.innerHTML=resp;
          for (i=0; i<scr.length;i++){
            to_exec=scr[i].replace(reg_repl,"");
            eval(to_exec);
          }
        } else {
          goal.innerHTML=resp;
        }
        if (redirect_url){
          if (redirect_timeout){
            setTimeout("execute('"+id+"','"+redirect_url+"','"+while_loading+"')",redirect_timeout*1000);
          } else {
            execute(id,redirect_url,while_loading);
          }
        }
        if (callback_on_success) {
          if (typeof callback_on_success == 'function') {
            callback_on_success();
          } else {
            eval(callback_on_success+'()');
          }
        }
      } else {
        if (callback_on_error) {
          if (typeof callback_on_error == 'function') {
            callback_on_error(request.status);
          } else {
            eval(callback_on_error+'('+request.status+')');
          }
        }
        
      }
    }
  }
  if (url) {
	  if (typeof (url) == 'object' && url['path'] != null) {
		  var q_data = url['data'] != null ? url['data'] : '';
		  var u_path = url['path'];
	  } else if (typeof (url) == 'string') {
		  var q_pos = url.indexOf('?');
		  var q_data = (q_pos!=-1?url.substr(q_pos+1):'');
		  var u_path = (q_pos!=-1?url.substr(0,q_pos):url);  
	  } else {
		  return false;
	  }
	  request.open( 'POST', u_path, true );
	  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  request.send(q_data);
  }
};
function execute_with_hiding(id,url,while_loading){
  var resObj=document.getElementById(id);
  if (resObj){
    if (resObj.style.display=='none'){
      resObj.style.display='';
      execute(id,url,while_loading);
    }else{
      resObj.style.display='none';
    }
  }
};
function execute_onempty_with_hiding(id,url){
  var resObj=document.getElementById(id);
  if (resObj){
    if (resObj.style.display=='none'){
      resObj.style.display='';
      if (resObj.innerHTML=='') {
        execute(id,url);
      }
    }else{
      resObj.style.display='none';
    }
  }
}
function check_checkboxes (formObj){
  elms=formObj.elements;
  if (!elms){
    return false;
  }
  for (i=0;i<elms.length;i++){
    if (elms[i].type=='checkbox' && elms[i].name!='' && elms[i].checked){
      return true;
    }
  }
  return false;
};
function check_checkboxes_in (container, common) {
  var elms=container.getElementsByTagName('input');
  if (!elms){
    return false;
  }
  for (i=0; i<elms.length; i++) {
    if (elms[i].type=='checkbox' && (!common || elms[i].name.indexOf(common)!=-1) && !elms[i].disabled && elms[i].checked) {
      return true;
    }
  }
  return false;
};
function enlargeObj(id,size){
  var oDist=document.getElementById(id);
  if (oDist){
    var currentSize=new Number(oDist.style.height.substr(0,oDist.style.height.length-2));
    var newSize=currentSize+size;
    oDist.style.height=newSize+'px';
    return true;
  }
  return false;
};
function reduceObj(id,size){
  var oDist=document.getElementById(id);
  if (oDist){
    var currentSize=new Number(oDist.style.height.substr(0,oDist.style.height.length-2));
    if (currentSize<size)
    return false;
    var newSize=currentSize-size;
    oDist.style.height=newSize+'px';
    return true;
  }
  return false;
};
function clearObj(id) {
  var oDist=document.getElementById(id);
  if (oDist){
    if (oDist.value) {
      oDist.value='';
    }
    if (oDist.innerHTML) {
      oDist.innerHTML='';
    }
  }
  return false;
};
function showhideObj(id){
  var oDist=document.getElementById(id);
  if (oDist){
    if (oDist.style.display=='none')
    oDist.style.display='';
    else
    oDist.style.display='none';
  }
};
function checkall_common(form,state,common){
  var elms=form.elements;
  for (i=0;i<elms.length;i++){
    if (elms[i].type=='checkbox' && (!common || elms[i].name.indexOf(common)!=-1) && !elms[i].disabled){
      elms[i].checked=state;
    }
  }
};
function fillall_common(form,value,common){
  var elms=form.elements;
  for (i=0;i<elms.length;i++){
    if (elms[i].type=='text' && (common=='' || elms[i].name.indexOf(common)!=-1)){
      elms[i].value=value;
    }
  }
};
function deleteById(id_to_delete){
  var obj_to_delete=document.getElementById(id_to_delete);
  if (obj_to_delete){
    obj_to_delete.parentNode.removeChild(obj_to_delete);
  }
};
function deleteNode(obj_to_delete) {
  if (obj_to_delete){
    obj_to_delete.parentNode.removeChild(obj_to_delete);
  } 
};
function valid_email(mail){
  var preg_email=/^[a-z0-9._+-]+@(?:[^.-]?[a-z0-9-]+[^-]?\.)+(?:[A-Z]{2,6})$/i;
  return mail.match(preg_email)?true:false;
};
var preg_valid_url=/^http[s]?:\/\/((?:[a-zA-Z0-9]+(?:[\-\_a-zA-Z0-9]*[a-zA-Z0-9]+){0,1}\.){1,}[-0-9a-zA-Z]{2,})([\/]{1}.*){0,1}$/i;

function valid_url(url) {
  if (!url.match(/^http[s]?:\/\//)) {
    return false;
  }
  hostpath_array = url.split("/");
  host_array = hostpath_array[2].split(".");
  for (var i=0; i< host_array.length; i++) {
    var lat = host_array[i].match(/[a-zA-Z]/); 
    var cyr = host_array[i].match(/[а-яА-ЯёЁ]/);
    if (cyr && lat) {
      return false;
    }
  }
  
  hostpath_array[2] = punycode.ToASCII(hostpath_array[2]);
  
  url = hostpath_array.join("/");
  return url.match(preg_valid_url) ? true : false;
};
var restricted_symbols=/[^a-zA-Zа-яА-ЯёЁ0-9\.\?_\s:;,!#\/\(\)\'-]+/;
var max_allowed_length=60;
function valid_keyword(keyword) {
  var key_error='';
  if (keyword.length>max_allowed_length) {
    key_error='Максимально возможное количество символов в ключевом слове составляет '+max_allowed_length;
  } else if (keyword.match(restricted_symbols)) {
    key_error="Ключевое слово может состоять из букв и цифр, разделенных пробелом, а также включать символы .?-_:;,!#/()\'";
  }
  return key_error;
};
function showhideHelp(){
  var help=document.getElementById('more_help');
  var helper=document.getElementById('more_helper');
  if (help.style.display==''){
    help.style.display='none';
    helper.innerHTML='подробнее';
  }else{
    help.style.display='';
    helper.innerHTML='скрыть';
  }
};
function submitter(formObjToSubmit){
  if (!formObjToSubmit){
    return '';
  }
  var submit_elms=formObjToSubmit.elements;
  var ret='';
  for (i=0;i<submit_elms.length;i++){
	  if (submit_elms[i].name=='' || submit_elms[i].type=='button' || ((submit_elms[i].type=='checkbox' || submit_elms[i].type=='radio') && !submit_elms[i].checked)){
      continue;
    }
    ret+='&'+URLEncode(submit_elms[i].name)+'='+URLEncode(submit_elms[i].value);
  }
  if (ret==''){
    return '';
  }
  return ret.substr(1);
};
function inputs_readonly(h_obj, readonly) {
  readonly=!!readonly;
  var h_inputs=h_obj.getElementsByTagName('input');
  for (i_input=0; i_input<h_inputs.length; i_input++) {
    h_inputs[i_input].readOnly=readonly;
  }
};
function is_numeric(val){
  var preg=/^[\+-]{0,1}[0-9]+(?:\.[0-9]*){0,1}$/;
  return val.match(preg)?true:false;
};
function is_int(val){
  var preg=/^[0-9]+$/;
  return val.match(preg)?true:false;
};
function in_array (needle, haystack, argStrict) {
  var key = '', strict = !!argStrict;
  for (key in haystack) {
    if ((!strict && haystack[key] == needle) || (strict && haystack[key] === needle)) {
      return true;
    }
  }
  return false;
}
function redirect_url(url) {
  return "http://yushkevich.su/redirect.php?url="+URLEncode(url);
};
function blink_bg(id, color, times) {
  var blObj=document.getElementById(id);
  if (!color) {
    color='#FFEFD8';
  }
  if (!times) {
    times=2;
  }
  if (blObj) {
    var init=blObj.style.backgroundColor;
    var timeout=50;
    for (i=0; i<times; i++) {
      setTimeout("set_bg_color('"+id+"','"+color+"')", timeout);
      setTimeout("set_bg_color('"+id+"','"+init+"')", timeout+300);
      timeout+=500;
    }
  }
};
function set_bg_color(id, color) {
  var colObj=document.getElementById(id);
  if (colObj) {
    var css_text = colObj.style.cssText.replace(/background-color:\s[^;]*(;|$)/gi, "");
    if (color.length>0) {
      css_text+= ';background-color: '+color+' !important;';
    }
    colObj.style.cssText = css_text;
  }
};
function set_select_value(slc_obj, slc_vl) {
  if ((typeof(slc_obj)!='object') || (typeof(slc_obj.options)!='object' && typeof(slc_obj.options)!='function')) {
    return false;
  }
  for (var islc=0; islc<slc_obj.options.length; islc++) {
    if (slc_obj.options[islc].value==slc_vl) {
      slc_obj.options[islc].selected=true;
      slc_obj.value = slc_vl;
      return true;
    }
  }
  return false;
}
function random (min, max) {
  max=Math.round(max); min=Math.round(min);
  if (min>=max) {
    return 0;
  }
  return min+Math.floor(Math.random()*(max-min));
};
function curdate() {
  dt=new Date();
  return dt.getFullYear()+'-'+(dt.getMonth()<9?'0':'')+(dt.getMonth()+1)+'-'+(dt.getDate()<10?'0':'')+dt.getDate();
}
// Инициализируем таблицу перевода
var trans = [];
for (var i = 0x410; i <= 0x44F; i++){
  trans[i] = i - 0x350; // А-Яа-я
}
trans[0x401] = 0xA8;    // Ё
trans[0x451] = 0xB8;    // ё

function URLEncode(str){
  var ret = [];
  // Составляем массив кодов символов, попутно переводим кириллицу
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    if (typeof trans[n] != 'undefined')
    n = trans[n];
    if (n <= 0xFF)
    ret.push(n);
  }
  return escape(String.fromCharCode.apply(null, ret)).replace(/\+/g,"%2B");

};
function rand_num(){
  return Math.ceil(Math.random()*10000000000).toString();
};
function get_form_by_num(num, form1, form2, form5) {
	var rest100 = num % 100;
	var rest10 = num % 10;
	if ((rest100 >= 10 && rest100 <= 20) || rest10 == 0 || rest10 >= 5) {
		return form5;
	} else if (rest10 == 1) {
		return form1;
	} else {
		return form2;
	}
};
function process_shift_checkboxes(etarget, tbl, cell) {
	var rows = tbl.rows;
	var last_like_checked=0, curpos = 0, cur_checked=etarget.checked, cur_name=etarget.name, inp, to_ch_inp, cur_cell;
	for (r=1; r<rows.length; r++) {
		cur_cell = cell < 0 ? rows[r].cells.length - 1 : cell;
		inp = rows[r].cells[cur_cell].firstChild;
		if (!inp || inp.nodeName != 'INPUT') {
			continue;
		}
		if (!inp || !inp.name) {
			alert(rows[r]);
			//alert(inp);
			return false;
		}
		if (inp.name == cur_name) {
			if (last_like_checked > 0) {
				for (cr=last_like_checked; cr<r; cr++) {
					cur_cell = cell < 0 ? rows[cr].cells.length - 1 : cell;
					to_ch_inp = rows[cr].cells[cur_cell].firstChild;
					if (to_ch_inp && to_ch_inp.nodeName == 'INPUT') {
						to_ch_inp.checked = cur_checked;
					}
				}
				break;
			}
			curpos = r;
		} else {
			if (curpos == 0) {
				if (inp.checked == cur_checked) {
					last_like_checked = r;
				}
			} else {
				if (inp.checked == cur_checked) {
					for (cr=curpos+1; cr<=r; cr++) {
						cur_cell = cell < 0 ? rows[cr].cells.length - 1 : cell;
						to_ch_inp = rows[cr].cells[cur_cell].firstChild;
						if (to_ch_inp && to_ch_inp.nodeName == 'INPUT') {
							to_ch_inp.checked = cur_checked;
						}
					}
					break;
				}
			}
		}
	}
};


