var isIE;
isIE = document.all ? true : false;

realHtmlArea = false;
/* --- html area (form edit) new window scripts --- */
function htmlAreaEdit(fillTextArea) {
	var w = screen.width-200;
	var h = screen.height - 200;
	x = ( screen.width - w) / 2;
	y = ( screen.height - h) / 2;
	
	realHtmlArea = document.all[fillTextArea];
	
	//tinymce
	myEditor = window.open('/js/mceeditor.html',"htmlarea","resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
	myEditor.ptr = fillTextArea;
	//FCK Editor
	//myEditor = window.open('/js/fckeditor/htmlarea.html',"htmlarea","resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
}


var nextDesignMode;

function cyInit() {

	
	if (document.all['designModeSwitcher']) nextDesignMode = document.all['designModeSwitcher'].nextMode; else nextDesignMode=1;
	setDragNDrop();
	document.onclick = docOnClick;
	document.onmousedown = docOnMouseDown;
	
	// Find out what objects are dependent on scrolling page (aligned right and aligned bottom)
	for(var i=0; i<=myDocumentElements.length-1; i++) {

		if (  myDocumentElements.item(i).getAttribute('draggable') == 'yes' ) {
			if ( (myDocumentElements.item(i).getAttribute('ddvalign') == 3)
			  || (myDocumentElements.item(i).getAttribute('ddhalign') == 3)) 
				{ bottomAlignedWindows.push( myDocumentElements.item(i) ); }
			}
			
		if (  myDocumentElements.item(i).getAttribute('fixScroll') == 'yes' ) {
			bottomAlignedWindows.push(myDocumentElements.item(i));
			}
		}


	//setTimeout("menuRepos()", 100);
		
	}

function docOnMouseDown() {
	if ((event.button==2) && (lastOver==false))  {// this means that we are not over any application window
			pageMenuShow();	
			}
	
	
}

bottomAlignedWindows = Array();
var mmouseX = 0;
var mmouseY = 0;
function getMouseXY() {
	if(isIE){
		mmouseX = event.clientX;
		mmouseY = event.clientY;
	}
}
document.onmousemove = getMouseXY;

function menuRepos() {
	var upflashp = document.getElementById("upflashpad");
	var mmenu = document.getElementById("mymenu");
	var newHeight = Math.round (parseInt(mmenu.style.height) + (document.body.scrollTop - parseInt(mmenu.style.height))/5);
	if (mmenu.style.height != newHeight) {
		mmenu.style.height = newHeight;
		//upflashp.style.height = newHeight + Math.round(document.body.clientHeight/2) - 50;
		var nhh= newHeight + mmouseY - 23;
		if (nhh <=0) nhh = 1;
		upflashp.style.height = nhh;
		setTimeout("menuRepos()", 20);	
		} else {
		setTimeout("menuRepos()", 200);
		}
}



function docOnScrollPage() {
	

	if (nextDesignMode!=1) return; //don't move boxes in design mode
	
	for (var i=0; i<=bottomAlignedWindows.length-1; i++) {
		myWdw = bottomAlignedWindows[i];
		if (!myWdw.realtop) myWdw.realtop = parseInt(myWdw.style.top);
		myWdw.style.top = myWdw.realtop + document.body.scrollTop;
		}
}

function pageMenuShow() {
	myPageMenu = document.all['pageMenu'];
	if (!myPageMenu) return;
	
	myPageMenu.style.visibility = 'visible';
	myPageMenu.style.top = event.y + document.body.scrollTop;
	myPageMenu.style.left = event.x + document.body.scrollLeft;
	
}

function pageMenuHide() {
	myPageMenu = document.all['pageMenu'];
	if (!myPageMenu) return;
	myPageMenu.style.visibility = 'hidden';
}

// Hides every menu that we don't want to click on
function docOnClick() {
	wdwHideMenu(lastMenu);	//if (intListActive) intListHide(intListActive,intListTR);
	pageMenuHide();
}




function doKeyDown (ev) {
	
    var myKeyCode      = ev.keyCode;
    var mySrcElement   = ev.srcElement;
    var isShiftPressed = ev.shiftKey;
    var isCtrlPressed  = ev.ctrlKey;
    var isAltPressed   = ev.altKey;
		
		
    // Enter(13), Shift(16), Ctrl(17), Alt(18), CapsLock(20) keys?
    if (myKeyCode >= 13 && myKeyCode <= 20)
        return true;
		
		doKeysChek(ev)
		
/*
    alert("Key code=" + myKeyCode 
        + "; Shift=" + isShiftPressed
        + "; Ctrl=" + isCtrlPressed
        + "; Alt=" + isAltPressed
        );
  */    
    
    if ( (myKeyCode == 76) && (isCtrlPressed) && (isAltPressed)) {
     	LockSwitchWdw();
	}
	
    nudgeMoveWdw(myKeyCode,isShiftPressed);
	
	
    if ( (myKeyCode == 68) && (isCtrlPressed) && (isAltPressed) ) {
    	// switch design mode
    	
    	if (!document.images['designModeSwitcher']) { nextMode = 1; } else {
    			nextMode = document.all['designModeSwitcher'].nextMode;
    			}
    	
    	setTimeout("switchDesignMode("+nextMode+")",200);
	}
	
   return true;
} // doKeyDown


function LockSwitchWdw() {
	if (!lastOver) return;
	
	args = parseQueryString();
	cyId = args['cy'];
	if (!cyId) cyId = 1; //becouse home page has no cy=??
	
	windowId = lastOver.winId;
	
	myTransmission = document.getElementById('hiddenImg');
	myTransmission.src = '?mod=admin&c=cc_admin_windows&m=lockWindow&p_cId='+cyId+'&p_wId='+windowId;
	//window.location = myTransmission.src;
}


/* Nudge move of window boxes */
function nudgeMoveWdw(myKeyCode,isShiftPressed) {
	if (!lastOver) return;
	if (nextDesignMode == 1) return; // means that we are not in design mode
	
	if (!isShiftPressed) step = 1; // 1px
	else step = 10;
	
	switch(myKeyCode) {
		case 37 : // left arrow
			lastOver.style.left = parseInt(lastOver.style.left) - step;
		break;
		case 40 : // down arrow
			lastOver.style.top = parseInt(lastOver.style.top) + step;
		break;
		case 39 : // right arrow
			lastOver.style.left = parseInt(lastOver.style.left) + step;
		break;
		case 38 : // up arrow
			lastOver.style.top = parseInt(lastOver.style.top) - step;
		break;
		case 83 : // S (Save)
			wdwSavePosition();
		break;		
	}
	
	showWdwInfo();
}

hideWdwInfoTimeout = false;
lastWdwNudge = false;

function showWdwInfo() {
	myWdwInfo = document.all['wdwInfo'];
	
	lastWdwNudge = lastOver;

	myvalign = false;
	myhalign = false;
	
	ddv = parseInt(lastOver.ddvalign);
	ddh = parseInt(lastOver.ddhalign);
	
	// Vertical
	switch (ddv) {
		case 1: myvalign = 'top';
			myY = parseInt(lastOver.style.top);
			break;	
		case 2: myvalign = 'middle';
			myY = parseInt(lastOver.style.top) - Math.round(document.body.clientHeight/2);
			break;	
		case 3: myvalign = 'bottom';
			myY = parseInt(lastOver.style.top) - document.body.clientHeight;
			break;
	}
	// Horizontal
	switch (ddh) {
		case 1: myhalign = 'left';
			myX = parseInt(lastOver.style.left);
			break;	
		case 2: myhalign = 'center';
			myX = parseInt(lastOver.style.left) - Math.round(document.body.clientWidth/2);	
			break;	
		case 3: myhalign = 'right';
			myX = parseInt(lastOver.style.left) - document.body.clientHeight;
			break;
	}
	
	gen  = '<form name="tmp" onSubmit="return wdwNudgeSave(this);">';
	gen += 'x: <input name="xpos" type="text" myval="'+parseInt(lastOver.style.left)+'"  value="'+myX+'" onChange="wdwNudgeSetX(this.value)"/> from '+myhalign;
	gen += '<br/>y: <input name="ypos" type="text" myval="'+parseInt(lastOver.style.top)+'" value="' + myY + '" onChange="wdwNudgeSetY(this.value)"/> from '+myvalign;
	gen += '<br/>width: <input name="wwidth" type="text" value="'+parseInt(lastOver.style.width)+'" onChange="wdwNudgeSetWidth(this.value)"/>';
	gen += '<br/>height: <input name="wheight" type="text" value="'+parseInt(lastOver.style.height)+'" onChange="wdwNudgeSetHeight(this.value)"/>';
	
	gen += '<br/><input type="submit" value="Save" style="width:80px;"  />';
	gen += '</form>';
	myWdwInfo.innerHTML = gen;
	myWdwInfo.style.visibility = 'visible';
	
	if (hideWdwInfoTimeout) clearTimeout(hideWdwInfoTimeout);
	hideWdwInfoTimeout = setTimeout('hideWdwInfo()',4000);
}


function wdwNudgeSave(self) {
	wdwNudgeSetX(self.xpos.value);
	wdwNudgeSetY(self.ypos.value);
	wdwNudgeSetWidth(self.wwidth.value);
	wdwNudgeSetHeight(self.wheight.value);
	wdwSavePosition();
	return false;
		
}

function wdwNudgeSetWidth(newVal) {
	if (!lastWdwNudge) return;
	lastWdwNudge.style.width = newVal;
	
}

function wdwNudgeSetHeight(newVal) {
	if (!lastWdwNudge) return;
	lastWdwNudge.style.height = newVal;
}

function wdwNudgeSetX(newX) {
	if (!lastWdwNudge) return;
	var myNewPos = 0;
	newX = parseInt(newX);
	var halign = parseInt(lastWdwNudge.ddhalign);
	switch (halign) {
		case 1: // left
			myNewPos = newX;
		break;
		case 2: // center
			myNewPos = Math.round(document.body.clientWidth/2) + newX;
		break;
		case 3: // right
			myNewPos = document.body.clientWidth + newX;
		break;				
		}
	
	lastWdwNudge.style.left = myNewPos;
}

function wdwNudgeSetY(newY) {
	if (!lastWdwNudge) return;
	var myNewPos = 0;
	newY = parseInt(newY);
	var valign = parseInt(lastWdwNudge.ddvalign);
	switch (valign) {
		case 1: // top
			myNewPos = newY;
		break;
		case 2: // middle
			myNewPos = Math.round(document.body.clientHeight/2) + newY;
		break;
		case 3: // bottom
			myNewPos = document.body.clientHeight + newY;
		break;				
		}
	
	lastWdwNudge.style.top = myNewPos;
}

function hideWdwInfo() {
	myWdwInfo = document.all['wdwInfo'];
	myWdwInfo.style.visibility = 'hidden';
}


function onWdwInfoOver(self) {
	if (hideWdwInfoTimeout) clearTimeout(hideWdwInfoTimeout);
	
}

function onWdwInfoOut(self) {
	if (hideWdwInfoTimeout) clearTimeout(hideWdwInfoTimeout);
	hideWdwInfoTimeout = setTimeout('hideWdwInfo()',4000);
}

/**
  * Inserts multiple fields.
  *
  */
function insertValueQuery() {
    var myQuery = document.forms['designForm'].template;
    var myListBox = document.forms['designForm'].insertField;

    if(myListBox.options.length > 0) {
        var chaineAj = "";
        var NbSelect = 0;
        for(var i=0; i<myListBox.options.length; i++) {
            if (myListBox.options[i].selected){
                NbSelect++;
                if (NbSelect > 1)
                    chaineAj += ", ";
                chaineAj += myListBox.options[i].value;
            }
        }

        //IE support
        if (document.selection) {
            myQuery.focus();
            sel = document.selection.createRange();
            sel.text=chaineAj;
            document.sqlform.insert.focus();
        }
        //MOZILLA/NETSCAPE support
        else if (myQuery.selectionStart || myQuery.selectionStart == "0") {
            var startPos = myQuery.selectionStart;
            var endPos = myQuery.selectionEnd;
            var chaineSql = myQuery.value;

            myQuery.value=chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
        } else {
            myQuery.value += chaineAj;
        }
    }
}



intListActive = false;
intListTR = false

function absoluteLeft(e) { if (e.parentNode && e.tagName != 'BODY') {if (e.tagName != 'TR') return e.offsetLeft+absoluteLeft(e.parentNode); else return absoluteLeft(e.parentNode);} return e.offsetLeft; }
function absoluteTop(e) { if (e.parentNode && e.tagName != 'BODY') {if (e.tagName != 'TR') return e.offsetTop+absoluteTop(e.parentNode); else return absoluteTop(e.parentNode);} return e.offsetTop; }

function intListClick(self,menuIdx) {
	
	if (intListActive) intListHide(intListActive,intListTR);
		
	myMenu = document.all[menuIdx];
	
	self.className = 'interfaceListElementActive';
	myMenu.className = 'intListOpened';
	document.body.appendChild(myMenu);
	var offX = -70;
	var offY = -75
	//alert(sumParentsOffsetY(self));
	//alert(event.y  - sumParentsOffsetY(self) + document.body.scrollTop);
	
	myMenu.style.top = event.y ;//+ offY - sumParentsOffsetY(self) + document.body.scrollTop;
	
	myMenu.style.left = event.x ;//+ offX- sumParentsOffsetX(self) + document.body.scrollLeft;
	//sumParentsOffsetX(self)
	//alert(event.y +" - " + (sumParentsOffsetY(self.parentElement) + 55) + " ---- " + (event.x - sumParentsOffsetX(self)));
	//myMenu.style.zIndex = 102300;
	//alert(myMenu.style.top);
	
	intListActive = myMenu;
	intListTR = self;
	
}

function sumParentsOffsetY(element) {
	var val;
	val = 0;
	if (element.parentElement) val = sumParentsOffsetY(element.parentElement);
	//alert(element.className+"---"+element.style.top);
	//if (element.style.position == 'absolute') val += element.offsetTop;
	if (element.style.top) val += parseInt(element.style.top);
	return val;
}

function sumParentsOffsetX(element) {
	var val;
	val = 0;
	if (element.parentElement) val = sumParentsOffsetX(element.parentElement);
	if (element.style.left) val += element.offsetLeft;
	return val;
}

function intListHide(self,myTR) {
	
	self.className= 'intListHidden';
	myTR.className= 'interfaceListElement';
}

function wdwMenuClick(self, menuId) {
	myMenu = document.all[menuId];

	if (myMenu.style.display=='none')  {
		// show menu
		myPosX = self.offsetLeft;
		myPosY = self.offsetTop;

		//myMenu.filters[0].apply();
		//myMenu.filters[1].Opacity = 90;
		
		myMenu.style.display  = 'block';
		
		myMenu.style.left = myPosX-129;
		myMenu.style.top = myPosY+14;
		
		//myMenu.filters[0].play();
		}
		else {
		// hide menu
		myMenu.style.display  = 'none';
		}
}

function selectChange(fname, fval) {
	//gets field name and field value of select.. notifys cycore that the select option has changed
	
	var newurlarr = new Array();
	pq = parseQueryString();
	pq['tmp_'+fname] = fval; // notify for new selection
	for(f in pq) {
		 newurlarr.push(f+'='+pq[f]);
	}
	newurl = '?'+newurlarr.join('&');
	goto(newurl);
	}

function switchDesignMode(dmod) {
	var newurlarr = new Array();
	pq = parseQueryString();
	pq['dmod'] = dmod;
	for(f in pq) {
		 newurlarr.push(f+'='+pq[f]);
	}
	newurl = '?'+newurlarr.join('&');
	goto(newurl);
	}

lastOver = false;
lastMenu = false;

// ------------------------------ SHOW MENU --------------------------------
function wdwShowMenu(self, posX, posY) { // param1: window obj
	
	if (lastMenu != false) wdwHideMenu(lastMenu);
	// We will show the menu button
	var menuContainer = document.all[ self.id+'_menu' ];
	if (!menuContainer)  return;
	
	menuContainer.style.visibility = "visible";
	
	menuContainer.style.left = posX;
	menuContainer.style.top = posY;
	menuContainer.style.zIndex = '8000';
	
	lastMenu = menuContainer;
	}
	
// ------------------------------ HIDE MENU --------------------------------
function wdwHideMenu(menuC) {
	if (!menuC) return;
	menuC.style.visibility = 'hidden';
	
	}

// ------------------------------ WINDOW->ON MOUSE DOWN --------------------------------	
function wdwMouseDown(self) {
	if ( event.button == 2) {
		// right clicked over application
		//alert( getRealRecPosX(self) );
		var myY = event.y + document.body.scrollTop;
		var myX = event.x + document.body.scrollLeft;
		
		wdwShowMenu(self, myX, myY);
		//wdwShowMenu(self, event.x + document.body.scrollLeft - getRealRecPosX(self.parentNode), event.y + document.body.scrollTop - getRealRecPosY(self.parentNode));
		return false;
		} 
	return false;
}

function getRealRecPosX(self) {
	if (self.tagName != 'DIV') return 0;
	var myPos = 0;
	if (self.style.left) myPos = parseInt(self.style.left);
	var myParentPos = 0;
	if (self.parentNode) myParentPos = getRealRecPosX(self.parentNode);
	return myParentPos + myPos;
}

function getRealRecPosY(self) {
	if (self.tagName != 'DIV') return 0;
	var myPos = 0;
	if (self.style.top) myPos = parseInt(self.style.top);
	var myParentPos = 0;
	if (self.parentNode) myParentPos = getRealRecPosY(self.parentNode);
	return myParentPos + myPos;
}

function wdwOut(self) {
	inspectionWdwOut(self);
	//if (lastOver) wdwHideMenu(lastOver);
	lastOver = false;
	}

function inspectionWdwOver(self) {

	return;
	
	
	me = document.getElementById('inspectorWin');
	
	//alert(self.style.left+" - "+self.style.top + " - "+self.style.width+" - "+self.style.height);
	
	//me.style.position = 'absolute';
	me.style.left = parseInt(self.style.left)-10;
	me.style.top = parseInt(self.style.top)-10;
	me.style.width = parseInt(self.style.width)+20;
	me.style.height = parseInt(self.style.height)+20;
	
	//me.style.backgroundColor = "#ee0000";
	me.style.borderColor = "#000000";
	me.filters[0].Opacity = 80;


	me.style.zIndex = parseInt(self.style.zIndex)-1;
	me.style.visibility = 'visible';

	me.style.border = "2px solid #339933";
	//me.filters[1].apply();
	
	//me.style.border = "0px solid";
	//me.style.visibility = 'hidden';
	//me.filters[1].play();
	
	
	//me.innerHTML = 'Hello jordan'+me.style.zIndex;
	
	
}

function inspectionWdwOut(self) {
	//me = document.getElementById('inspectorWin');
}

function wdwOver(self) {
	
	inspectionWdwOver(self);
	//window.status = 'dd.elements.' + dd.obj.name + '.x  = ' + dd.obj.x + '     dd.elements.' + dd.obj.name + '.y = ' + dd.obj.y;
	//myobj = document.all[dd.obj.name];
	myobj = self;
	
/*
	if (myobj == lastOver) return;
	if (lastOver) { 
		//if (lastPicked.filters[1]) lastPicked.filters[1].apply();
		if (lastOver.filters[0]) lastOver.filters[0].Opacity=60;	
		//if (lastPicked.filters[1]) lastPicked.filters[1].MakeShadow= false;
		//if (lastPicked.filters[1]) lastPicked.filters[1].play();
		}
//	myobj.filters[0]
	
	//if (myobj.filters[1]) myobj.filters[1].apply();
	
//	myMenu.filters[1].Opacity = 80;

	//if (myobj.filters[1]) myobj.filters[1].PixelRadius=0;	
	if (myobj.filters[0]) myobj.filters[0].Opacity=65;
//	myMenu.style.display  = 'block';
		
//	myMenu.style.left = myPosX-99;
//	myMenu.style.top = myPosY+14;
		
	//if (myobj.filters[1]) myobj.filters[1].play();
	
*/	
	lastOver = myobj;
	//if (nextDesignMode != 1) showWdwInfo();
}


function appOverTR(self) {
	self.className = 'wdw-table-row-over';
}

function appOutTR(self) {
	self.className = 'wdw-table-row';
}


function setDragNDrop() {


	var draggableObjs = new Array();
	
	myDocumentElements=document.getElementsByTagName("div");

	for(var i=0; i<=myDocumentElements.length-1; i++) {

		if ( myDocumentElements.item(i).getAttribute('id') 
			&& ( myDocumentElements.item(i).getAttribute('draggable') == 'yes') ) {
			if (nextDesignMode == 1) {
				// NOT IN DESIGN MODE
				
				
				
				
				
				
				} else {
				// IN DESIGN MODE
				draggableObjs.push( "'"+myDocumentElements.item(i).getAttribute('id')+"'+RESIZABLE" );
				}
			}
		}
	
	if (draggableObjs.length != 0) for(var j=0; j<=draggableObjs.length-1; j++) {
		eval("ADD_DHTML("+draggableObjs[j]+");");
		}
		
}



function parseQueryString (str) {
  str = str ? str : location.search;
  var query = str.charAt(0) == '?' ? str.substring(1) : str;
  var args = new Object();
  if (query) {
    var fields = query.split('&');
    for (var f = 0; f < fields.length; f++) {
      var field = fields[f].split('=');
      args[unescape(field[0].replace(/\+/g, ' '))] = 
unescape(field[1].replace(/\+/g, ' '));
    }
  }
  return args;
}




function goto(place) {
	if (place) window.location.href = place;	
	}

function confirmGoto(place) {
	if (!confirm('Are you shure you want to do this ?')) return false;
	
	if (place) window.location = place;	
	}




function popup(url,windowname,w,h,x,y) {
	if (!w) w= screen.width ;
	if (!h) h= screen.height -140;
	if (!x) {
		x = ( screen.width - w) / 2;
		y = ( screen.height - h) / 2;
		}
	return window.open(url,windowname,"resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
	}
	
	
function popupAdmin(url,windowname,w,h,x,y) {
	if (!w) w= screen.width ;
	if (!h) h= screen.Height - 140 ;
	if (!x) {
		x = ( screen.width - w) / 2;
		y = ( screen.height - h) / 2;
		}
	
	
	return window.open(url,windowname,"fullscreen=yes,resizable=yes,dialog=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
	}
	
////////////////////////////////////////////////////////////
// FUNCTIONS FOR EXTENDED SCRIPTING
// Use these for your own extensions,
// or to call functions defined elsewhere



/* my_PickFunc IS AUTOMATICALLY CALLED WHEN AN ITEM STARTS TO BE DRAGGED.
The following objects/properties are accessible from here:

- dd.e: current mouse event
- dd.e.property: access to a property of the current mouse event.
  Mostly requested properties:
  - dd.e.x: document-related x co-ordinate
  - dd.e.y: document-related y co-ord
  - dd.e.src: target of mouse event (not identical with the drag drop object itself).
  - dd.e.button: currently pressed mouse button. Left button: dd.e.button <= 1

- dd.obj: reference to currently dragged item.
- dd.obj.property: access to any property of that item.
- dd.obj.method(): for example dd.obj.resizeTo() or dd.obj.swapImage() .
  Mostly requested properties:
	- dd.obj.name: image name or layer ID passed to SET_DHTML();
	- dd.obj.x and dd.obj.y: co-ordinates;
	- dd.obj.w and dd.obj.h: size;
	- dd.obj.is_dragged: 1 while item is dragged, else 0;
	- dd.obj.is_resized: 1 while item is resized, i.e. if <ctrl> or <shift> is pressed, else 0

For more properties and details, visit the API documentation
at http://www.walterzorn.com/dragdrop/api_e.htm (english) or
http://www.walterzorn.de/dragdrop/api.htm (german)    */

function my_PickFunc()
{

}




/* my_DragFunc IS CALLED WHILE AN ITEM IS DRAGGED
See the description of my_PickFunc above for what's accessible from here. */
function my_DragFunc()
{
	//window.status = 'dd.elements.' + dd.obj.name + '.x  = ' + dd.obj.x + '     dd.elements.' + dd.obj.name + '.y = ' + dd.obj.y;
}




/* my_ResizeFunc IS CALLED WHILE AN ITEM IS RESIZED
See the description of my_PickFunc above for what's accessible from here. */
function my_ResizeFunc()
{
	//window.status = 'dd.elements.' + dd.obj.name + '.w  = ' + dd.obj.w + '     dd.elements.' + dd.obj.name + '.h = ' + dd.obj.h;
}




/* THIS ONE IS CALLED ONCE AN ITEM IS DROPPED
See the description of my_PickFunc for what's accessible from here.
Here may be investigated, for example, what's the name (dd.obj.name)
of the dropped item, and where (dd.obj.x, dd.obj.y) it has been dropped... */
/* function my_DropFunc()
{
}
*/

// invoked by dd script
function my_DropFunc() {
	
	wdwSavePosition();
	

}

function wdwSavePosition() {
	
	if (!lastOver) {
		if (!lastWdwNudge) return;
		dropedElement = lastWdwNudge;
		} else {
		dropedElement = lastOver;	
		}
		
	
	args = parseQueryString();
	cyId = args['cy'];
	if (!cyId) cyId = 1; //becouse home page has no cy=??
	
	//dropedElement = document.all[dd.obj.id];

	
	windowId = dropedElement.winId;
	
	//errorOffsetX = Math.round(dropedElement.clientLeft);
	//errorOffsetY = Math.round(dropedElement.clientTop);
	errorOffsetX = 0;
	errorOffsetY = 0;
	
	mySaveX = (parseInt(dropedElement.style.left)+errorOffsetX);
	mySaveY = (parseInt(dropedElement.style.top)+errorOffsetY);
	myWidth = parseInt(dropedElement.style.width);
	myHeight = parseInt(dropedElement.style.height);
	
	// changes image src to pass params to cycore	
	document.all['hiddenImg'].src = '?mod=admin&c=cc_admin_windows&m=setWinPos&p_cId='+cyId+'&p_wId='+windowId+'&p_x='+mySaveX+'&p_y='+mySaveY+'&p_w='+myWidth+'&p_h='+myHeight+'&p_z='+dropedElement.style.zIndex+'&p_cw='+document.body.clientWidth+'&p_ch='+document.body.clientHeight+'&p_valign='+dropedElement.ddvalign+'&p_halign='+dropedElement.ddhalign;
}

















function dump(arr,level) {
	
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}

return dumped_text;
} 
//addEvent(document.getElementById(adminForm), 'submit', submitRating, false);










//////////////////////js calendar ////////////////////////
function ShowCalendar(CONTROL,START_YEAR,END_YEAR,FORMAT,FORMTOSUBMITAFTER){
	if(FORMTOSUBMITAFTER!=false){
		//alert(FORMTOSUBMITAFTER);
		formToSubmit = FORMTOSUBMITAFTER;
	}else{
		formToSubmit = false;
	}
//alert(CONTROL);
//ControlToSet = eval(CONTROL);
FormToSubmit = FORMTOSUBMITAFTER;
ControlToSet = (CONTROL);
StartYear = START_YEAR;
EndYear = END_YEAR;
FormatAs = FORMAT;
CalWidth = 200;
LEFT =10;
TOP =10;
var strFeatures = "width=" + CalWidth + ",height=170" + ",left=" + LEFT + ",top=" + TOP;
//return false;
path = "js/HTMLCalendar.htm";
//alert(path);
var CalWindow = window.open(path,"Calendar", strFeatures)
CalWindow.focus();
} //End Function

function ClearCalendar(CONTROL,formToSubmit){
	ControlToSet = (CONTROL);
	myobj = document.getElementById(ControlToSet);

	myobj.value = ""; 
	myobj = null;

	ControlToSet = null;
	StartYear = null;
	EndYear = null;
	FormatAs = null;
	if(formToSubmit!=false){
		//document.forms[formToSubmit].submit();
	}
	
} //End Function

function SetDate(DATE){
//alert(ControlToSet);
if(ControlToSet){
//alert();

ControlToSet.value = DATE; 
}
//alert(ControlToSet);
myobj = document.getElementById(ControlToSet);

myobj.value = DATE; 
myobj = null;

ControlToSet = null;
StartYear = null;
EndYear = null;
FormatAs = null;
	if(formToSubmit!=false){
		//document.forms[formToSubmit].submit();
	}
}
////////////////////////////////////////////////////////////


function openContentEditor(appClass,appModule,appAction,appInstanceId,appLang){
	var w= screen.width/3 ;
	var h= screen.Height/2;
	var x = ( screen.width - w) - 50;
	var y = 150;
	popup('/?mod=admin&c=cc_admin_content_edit&m=read'+'&p_c='+appClass+'&p_m='+appModule+'&p_a='+appAction+'&p_iid='+appInstanceId+'&lang='+appLang,'contEditor',w,h,x,y);
}

function openTxt(ptr){
	myEditor = window.open('js/txteditor.html',"htmlarea","resizable=1,toolbar=0,scrollbars=1,menubar=0,status=1,directories=0,maximize=1");
	myEditor.ptr = ptr;
}

//

function viewLoader(){
	var ptr = document.getElementById('loader');
	if(!ptr){
		var loader = document.createElement('div');
		loader.id = 'loader';
		loader.style.position = 'absolute';
		
		loader.style.top = screen.height/2-200;
		loader.style.left = screen.width/2;
		loader.style.display = "block";
		//loader.innerHTML = "<center><div style='background:#FCF0AA;border:3px solid black;cursor:pointer;padding:5 5 5 5'><img src='images/loader.gif' /><br/>searching</div></center>";
		loader.innerHTML = "<table border=0 width=50 style='background-image:url(images/pack_01/bckgrd.gif);height:50px;width:50px' height=50 cellpadding=0 cellspacing=0><tr><td width=6><img src='images/pack_01/bckgrd_left.gif' border=0 /></td><td style='vertical-align:middle;padding:0 10 0 10' align='middle'><img src='images/loader.gif' /></td><td width=6><img src='images/pack_01/bckgrd_right.gif' border=0 /></td></tr></table>";
		//loader.innerHTML = "<table border=0 width=50 style='background-image:url(images/pack_01/loader_bck.jpg);height:50px;width:50px' height=50 cellpadding=0 cellspacing=0><tr><td style='vertical-align:middle;padding:0 10 0 10' align='middle'><img src='images/loader.gif' /></td></tr></table>";
		document.body.appendChild(loader);
		loaderIsOn = true;
	}else{
		document.getElementById('loader').style.display = "block";
	}
}

function submitCYBER(request,formid,viewAni){
	if(!top.document.getElementById(formid)){
		window.status = formid+" is not found !";
		return;
	}
	var myform = top.document.getElementById(formid);
	if(top.cyber){
		if(viewAni){
			viewLoader();
		}
		//removing all objects marked as trash
		for(var i =0;i<cyberRemoveBeforeReload.length;i++){
			var key 	= cyberRemoveBeforeReload[i];
			var garb 	= document.getElementById(key);
			if(!garb)continue;
			garb.parentNode.removeChild(garb);			
		}			

		// _dom : 0=other, 1=Mozilla, 2=NN4, 3=IE4/5
		_dom=(document.all?3:(document.getElementById?1:(document.layers?2:0)));
		_ie5=(navigator.appVersion.indexOf('MSIE 5')>=0);
		switch(_dom){
			case 3://ie
				var myform2 = top.cyber.document.createElement('form');
				myform2.id = "submit";
				top.cyber.document.body.appendChild(myform2);
				var f = top.cyber.document.getElementById("submit");
				f.innerHTML = myform.innerHTML;
				f.action = request;
				f.method = "POST";
				f.submit();
			break;
			case 1:
				var myform2 = top.cyber.document.importNode(myform,true);
				myform2.id = "submit";
				top.cyber.document.body.appendChild(myform2);
				var f = top.cyber.document.getElementById("submit");
				//f = myform;
				f.action = request;
				f.method = "POST";
				f.submit();
			break;
		}
		
	}		
}

var cyberIsLoading=false;
var cyberRemoveBeforeReload = new Array();
function callCYBER(request,viewAni){
	/*if(cyberIsLoading){
		alert('Another request is in progress at the moment!\n Please wait.');
		return false;
	}*/
	if(top.cyber){
		if(viewAni){
			viewLoader();
		}
		top.cyber.location.href = request;
		cyberIsLoading = true;
	}
	return true;
}

//todo da se napravi biblioteka JS za cc_form i tazi funkzia da se premesti tam
function cloneField(fieldName){
	alert(fieldName);
}


function autoFill(ptr,str,state){
	switch(state){
		case 1:
			if (ptr.value==str) ptr.value='';
		break;
		case 0:
			if (ptr.value=='') ptr.value=str;
		break;
	}
}

function fixHeight(ptr,w){
	//window.status = 'w';
	//alert(h);
	var obj = document.getElementById(ptr);
	if(!obj)
		return false;
		
	if(typeof(w)=='undefined')
		return false;
		
		
	obj.style.height = w+'px';
}


function start_slide(){
	var obj = document.getElementById("gallery1");
	if(typeof(obj)=='undefined')
		return false;
		
	obj.onclick();
	
}