function writeSWF(FO){
var cnt = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\""+FO.width+"\" height=\""+FO.height+"\" id=\""+FO.id+"\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\""+FO.src+"\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=\""+FO.src+"\" wmode=\"transparent\" quality=\"high\" width=\""+FO.width+"\" height=\""+FO.height+"\" name=\""+FO.id+"\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"/></object>";
document.write(cnt);
}


function openPopUp(id, name, width, height){
var t= window.open('popup.php?id='+id+'&name='+name,'PopUp','width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=100,screenY=100');
}



	function calculateMeasure(measure_id){
	var summ = eval('document.all.summ_'+measure_id);
	var formula_inp = eval('document.all.formula_'+measure_id);
	var this_dim = dimension[measure_id];

	if(this_dim.length > 0){
	for(i in this_dim){
	eval('var '+this_dim[i]+' = 1*document.all.'+this_dim[i]+'_'+measure_id+'.value');
//	eval('alert(this_dim[i] +"= "+'+this_dim[i]+')');
	}
	}

	var formula = formula_inp.value.replace(/{/g, '');
	formula = formula.replace(/}/g, '');
	summ.value = eval(formula);
//	summ.value = formula;
	}


	





function callbackSelectImage(editor, result, tbi, sender)
{
  document.getElementById(editor.name).value = result;
  window.focus();
  document.getElementById(editor.name).focus();
}

	
	
function selectImage(input){
  
SpawEngine.spaw_dir = "/libs/spaw2/";

var spawArgs;
var spawArguments;
var spawEditor = new SpawEditor(input);

SpawEngine.registerEditor(spawEditor);
spawEditor.setTheme(SpawThemespaw2);
spawEditor.setLang("ru");
spawEditor.setOutputCharset("");
spawEditor.stylesheet = "";
var content_page = new SpawEditorPage(input,input,"ltr");
spawEditor.addPage(content_page);
spawEditor.getTab(input).template = "";
spawEditor.getTab(input).active_template = "";
spawEditor.active_page =content_page;

SpawEngine.openDialog('spawfm', 'spawfm', spawEditor, document.getElementById(input).value, 'type=flash', 'callbackSelectImage', null, null);
}



  function selectId(id, name, formName, fieldName) {

//alert('id='+id);
//alert('name='+name);
//alert('formName='+formName);
//alert('fieldName='+fieldName);

    if (id != "" && name != "" && formName != "" && fieldName != "" ){

      var obj= new Object(window.opener.document.forms[formName].elements[fieldName]);

        if(obj.type == 'text'){
	if(obj.value != ''){
	obj.value = element.value+', '+name;
	}else{
	obj.value = name;
	}
	}else if(obj.type == 'select-multiple' || obj.type == 'select-one'){


var anOption = window.opener.document.createElement("OPTION"); 

obj.options.add(anOption);
anOption.innerText = name;
anOption.value = id;
anOption.selected = true;
alert('�������� ������ '+name+' � ��������������� ('+id+')');
obj.size = obj.options.length+1;

var anInput = window.opener.document.createElement("input"); 
window.opener.document.forms[formName].appendChild(anInput);
anInput.name = fieldName.substring(0,(fieldName.length-2))+'_val['+id+']';
anInput.value = name;
anInput.type = 'hidden';
//alert(anInput.name);
	}	
	

//      window.close();
    }
  }


function LoadHTML(a, css){
//this[a+'_frame'].document.designMode = 'On';
this[a+'_frame'].document.createStyleSheet(css);
this[a+'_frame'].document.body.innerHTML = document.all[a+'_data'].value;
return 1;
}

function EmailValidation(email){
	var re=new RegExp("^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}\$");
	if(!re.test(email)) return false;
}


function CheckForm(form){
if(form.text.value==""){
form.text.focus();
alert("Field 'Message' can't be empty");
return false;
}

if(form.text.value.length > 1500){
form.text.focus();
alert("Count of type of field 'Message' can't be more than 1500 type");
return false;
}

//if(form.contact_name.value==""){
//form.contact_name.focus();
//alert("Field 'Contact' can't be empty");
//return false;
//}

if(form.group_id.value==0){
form.group_id.focus();
alert("Field 'Group' can't be empty");
return false;
}



if(form.email.value==""){
form.email.focus();
alert("Field 'E-mail' can't be empty");
return false;
}

if(EmailValidation(form.email.value)==false){
form.email.focus();
alert("Field 'E-mail'must be like to example name@domain.com");
return false;
}


}

function CountOfSymbol(target, to, limite){
to.value = limite-target.value.length;
}

function ChangeSelect(sel, module, method, val, url){
window.location='?module='+module+'&method='+method+'&'+val+'='+sel.value+url;
}

function ChangeImage(file, img){
if(file.value!=""){
window.document.all[img].src=file.value;
}
}


var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function show_calendar2(formName, fieldName)
{
    var form = document.forms[formName];
    var element = form.elements[fieldName];
    var vWinCal = window.open('/class/Xokos/Wysiwyg/dialogs/calendar.php?form_name=' + formName + '&field_name=' + fieldName + '&value=' + escape(element.value) + '&decorator=none', 'Calendar','width=230,height=170,status=no,resizable=yes,top=220,left=200');
    vWinCal.opener = self;
    vWinCal.focus();
}


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 

		
		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center">Loading template preview...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		newHTML = newHTML + '<h2 class="title_h2">' + ' '+title + '</h2>'
		
    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '</div>'; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}		

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}


var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}
