function fcheck(form) {

for(i=1;i<arguments.length;i++) {

with(form) {

if(!arguments[i].value) {alert('Пожалуйста, заполните обязательные поля'); return false}

}

}

return true

}

function runScripts(scripts) {
    if (!scripts) return false;
    for (var i = 0; i < scripts.length; i++) {
        var thisScript = scripts[i];   
        var text;
        if (thisScript.src) {
            var newScript = document.createElement("script");
            newScript.type = thisScript.type;       
            newScript.language = thisScript.language;
            newScript.src = thisScript.src;             
            document.body.appendChild(newScript);   
        } else if (text = (thisScript.text || thisScript.innerHTML)) {
            var text = (""+text).replace(/^\s*<!\-\-/, '').replace(/\-\->\s*$/, '');
            eval(text);
        }
    }
}

function EvalAJAXScripts(obj)
{
 //for(var i=0; i<document.getElementById(obj).getElementsByTagName('script').length; i++){
  // eval(document.getElementById(obj).getElementsByTagName('script')[i].text);}
  alert($("#" + obj).html());
  //eval();
}

function emailcheck(string) {

 if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1 || string=='') return true

 else {

  alert('Введите корректный адрес e-mail!')

  return false

 }

}

function getObj(id)
{
	var obj = document.getElementById(id);
	if (obj) return obj;
}
	
function show_info(obj)
{
	getObj(obj).style.display = 'block';
}

function hide_info(obj)
{
	getObj(obj).style.display = 'none';
}

function str_replace(search, replace, subject) {
 
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }
 
    return sa ? s : s[0];
}

function round ( val, precision ) {
    return parseFloat(parseFloat(val).toFixed(precision));
}

function floatval(mixed_var) {
    return (parseFloat(mixed_var) || 0);
}

function explode( delimiter, string, limit ) {
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

Array.prototype.max = function(){
	return Math.max.apply({},this)
}

function getselected(obj)
{
	return obj.options[obj.selectedIndex].value;
}

function ClientWidth() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function ClientHeight() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}    

function ScrollLeft() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollLeft:document.body.scrollLeft;
}

function ScrollTop() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollTop:document.body.scrollTop;
}

function position_block(id)
{
	bw = ClientWidth();	bh = ClientHeight();
	div_w = getObj(id).offsetWidth;	div_h = getObj(id).offsetHeight;
	getObj(id).style.left = (bw - div_w)/2+'px';
	getObj(id).style.top = (bh - div_h)/3+'px';
}

function show_block(id)
{
	show_info('overlayer');
	show_info(id);
	position_block(id);
}

function hide_block(id)
{
	hide_info(id);
	hide_info('overlayer');
}

function answer(id)
{
	getObj('parent_id').value = id;
}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea) {
	// Can a text range be created?
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange) {
		var caretPos = textarea.caretPos, temp_length = caretPos.text.length;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;

		if (temp_length == 0) {
			caretPos.moveStart("character", -text2.length);
			caretPos.moveEnd("character", -text2.length);
			caretPos.select();
		}
		else
			textarea.focus(caretPos);
	}
	// Mozilla text range wrap.
	else if (typeof(textarea.selectionStart) != "undefined") {
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text1 + selection + text2 + end;

		if (textarea.setSelectionRange) {
			if (selection.length == 0)
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	// Just put them on the end, then.
	else {
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}