function redir(loc, timeout) {
	setTimeout("document.location='"+loc+"'", timeout);
}

function show(val) {
	if (val) {
		if (val.style.display == '') {
			val.style.display = 'none';
		} else {
			val.style.display = '';
		}
	}
}

function setBkColor(obj, color) {
	obj.style.backgroundColor = color;
}

function showWindow(src) {
	cms_win_frame.src=src;
	show(cms_win);
}

function _out(name) {
	obj = document.getElementById(name);
	objb = document.getElementById(name+'B');
	obj.style.border = "1px solid #3081BA";
	objb.style.display = "none";
}

function _over(name) {
	obj = document.getElementById(name);
	objb = document.getElementById(name+'B');
	obj.style.border = "1px solid red";
	objb.style.display = "";
	//obj.style.display = "none";
}

function openCalendar() {

}

//-----------------------//
//  CMS BLOCKS
//-----------------------//

function _active(obj) {
	//    obj.style.cssText = "border: 1px solid #FFFFFF; ";
}

function _deactive(obj) {
	//    obj.style.cssText = "border: 1px solid #999999; ";
}


//-----------------------//
//  AJAX
//-----------------------//

function ajaxQuery(val, funcName) {
	JsHttpRequest.query(
	'/sys/ajax/getvalue.php',
	{
		'req': val
	},
	// Function is called when an answer arrives.
	function(result, errors) {
		eval(funcName+'(result);');
	},
	true// disable caching
	);
}

//-----------------------//
//  AJAX CONTROLS
//-----------------------//
function grid_update_row(id, data) {
	for (name in data)  {
		val = document.getElementById('col_'+id+'_'+name);
		val.innerHTML = data[name];
	}
}

function add_to_order(id, name, link) {
	req = new Array();
	req["cmd"] = "add_to_order";
	req["id"] = id;
	req["name"] = name;
	req["link"] = link;
	ajaxQuery(req, 'order_callback');
}

function order_count(id, count) {
	req = new Array();
	req["cmd"] = "order_count";
	req["id"] = id;
	req["count"] = count;
	ajaxQuery(req, 'null_callback');
}

function delete_from_order(id) {
	req = new Array();
	req["cmd"] = "delete_from_order";
	req["id"] = id;
	ajaxQuery(req, 'order_callback');
}

function order_list() {
	req = new Array();
	req["cmd"] = "order_list";
	ajaxQuery(req, 'order_callback');
}

function null_callback() {}

function checkText() {
	var pasteDiv = document.createElement( 'DIV' ) ;
	pasteDiv.style.visibility = 'hidden';
	pasteDiv.style.overflow = 'hidden';
	pasteDiv.style.position = 'absolute';
	pasteDiv.style.width = 1;
	pasteDiv.style.height = 1;
	document.body.appendChild(pasteDiv);
	pasteDiv.innerHTML = '' ;
	var pasteTextRange = document.body.createTextRange() ;
	pasteTextRange.moveToElementText(pasteDiv) ;
	pasteTextRange.execCommand('Paste') ;
	var word = /<\w[^>]* class="?MsoNormal"?/gi ;

	if (word.test(pasteDiv.innerHTML)) {
		pasteDiv.innerHTML = clearHTML(pasteDiv.innerHTML);;
		pasteTextRange.moveToElementText(pasteDiv) ;
		pasteTextRange.execCommand('Copy') ;
	}
}

function clearHTML( html ) {

	var bIgnoreFont = 1 ;
	var bRemoveStyles = 1 ;

	html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
	html = html.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;

	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;

	// Remove FONT face attributes.
	if ( bIgnoreFont ) {
		html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
		html = html.replace( /\s*face=[^ >]*/gi, "" ) ;

		html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	}

	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove styles.
	if ( bRemoveStyles )
	html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;

	// Remove empty styles.
	html =  html.replace( /\s*style="\s*"/gi, '' ) ;

	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;

	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;


	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;

	html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;

	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;

	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	html = html.replace( /<H1([^>]*)>/gi, '' ) ;
	html = html.replace( /<H2([^>]*)>/gi, '' ) ;
	html = html.replace( /<H3([^>]*)>/gi, '' ) ;
	html = html.replace( /<H4([^>]*)>/gi, '' ) ;
	html = html.replace( /<H5([^>]*)>/gi, '' ) ;
	html = html.replace( /<H6([^>]*)>/gi, '' ) ;

	html = html.replace( /<\/H\d>/gi, '' ) ;

	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;


	// Remove empty tags (three times, just to be sure).
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;



	// Transform <P> to <DIV>
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<p$2<\/p>" ) ;
	return html ;
}

function delConfirm(str, str2) {
	if (!str2) str2 = 'Удалить содережимое модуля?';
	if (confirm(str2) == true) {
		document.location = str;
	}
}

function setCookie(name, value) {
	var today = new Date();
	expire = new Date(today.getTime() + 1000*60*60*24*356);
	document.cookie = name + "=" + escape(value)
	+ ((expire == null) ? "" : ("; expires="+ expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

//if (!getCookie("uvID")) {setCookie("uvID", Math.random());}