/** javascript functions for pitgreen.cms
	* functions.js
	*
	* @module	javascript
	* @modulegroup	cms
	* @package	pitgreen.com
	* @author	Philipp Schuele / Oliver Johannson
	* @version      0.4.2-1
	* @copyright	rutan gmbh 2007
	* @todo
*/

var windowObject=false, watchTimer=false;
var evtobj;

function OJ_watchWindow (windowObject){
	if (windowObject.closeWindow==true) {
		linkArgs="?mode=crop&imgType="+windowObject.imgType+"&boxWidth="+windowObject.boxWidth+"&boxHeight="+windowObject.boxHeight+"&boxX="+(windowObject.boxX-windowObject.margin)+"&boxY="+(windowObject.boxY-windowObject.margin);
		windowObject.close();
		document.location.href="index.php"+linkArgs;
	} else {
		watchTimer = window.setTimeout("OJ_watchWindow(windowObject)", 100);
	}
}

function OJ_openWindow (imgType, filename, boxWidth, boxHeight, boxX, boxY, aspectRatio, srcWidth, srcHeight) {
	windowObject = window.open("cropwindow.php?imgType="+imgType+"&filename="+filename+"&boxWidth="+boxWidth+"&boxHeight="+boxHeight+"&boxX="+boxX+"&boxY="+boxY+"&aspectRatio="+aspectRatio+"&srcWidth="+srcWidth+"&srcHeight="+srcHeight,
						"CropImage", "width="+(srcWidth+60)+",height="+(srcHeight+40)+",menubar=no,scrollbars=yes,resizable=yes,status=yes");
	windowObject.focus();
	OJ_watchWindow (windowObject);
}

function PS_popup( url, width, height, options, name ) {
	if ( ! width ) width = 234;
	if ( ! height ) height = 432;
	if ( ! options ) options = "scrollbars=yes,menubar=no,toolbar=no,location=no,status=no,resizable=no";
	if ( ! name ) name = "popupWindow";

	var newWin = window.open( url, name, "width=" + width + ",height=" + height + "," + options );
}

function setTableHeight () {
	document.getElementById('CMSmain').style.height = document.documentElement.clientHeight-150;
	window.setTimeout('setTableHeight ();',100);
}


/**
 * Saves current Object, what event e execute
 * @param event
 * @return
 */
function saveevt(e) {
	//alert(navigator.appName);
	if(navigator.appName=="Netscape"){
		evtobj=e.target.parentNode.parentNode;
	}else {
		evtobj=e.srcElement.parentNode.parentNode;
	}
	//alert(evtobj.className);
	
}

function imageEditorBuild (imgType, filename, boxWidth, boxHeight, boxX, boxY, aspectRatio, srcWidth, srcHeight) {
	
         document.getElementById("imageEditor").style.display = "inline";
         var imageEditorDiv = document.getElementById("imageEditor");
         var distanceDiv = document.createElement("div");
      	var underDis1Div = document.createElement("div");
         var underDis2Div = document.createElement("div");
         var containerDiv = document.createElement("div");
         var underDis1Class = document.createAttribute("class");
      	var underDis2Class = document.createAttribute("class");
         underDis1Class.nodeValue = "functions";
      	underDis2Class.nodeValue = "functions bottom";
         var ul1  = document.createElement("ul");
         var ul2  = document.createElement("ul");
         var ul3  = document.createElement("ul");
         var ul4  = document.createElement("ul");

         var ulRight2Id = document.createAttribute("id");
         var ulRight4Id = document.createAttribute("id");
         ulRight2Id.nodeValue = "ulright";
         ulRight4Id.nodeValue = "ulright";
         ul2.setAttributeNode(ulRight2Id);
         ul4.setAttributeNode(ulRight4Id);

         var li1  = document.createElement("li");
         var li2  = document.createElement("li");
         var li41  = document.createElement("li");
         var li42  = document.createElement("li");


         var tagA1 = document.createElement("a");
         var tagA2 = document.createElement("a");
         var tagA41 = document.createElement("a");
         var tagA42 = document.createElement("a");

         //tagA1.setAttribute("href","#");
         tagA2.setAttribute("href","#");
         tagA41.setAttribute("href","#");
         tagA42.setAttribute("href","#");

         //txtLi1 = document.createTextNode("Lock Ratio");
         txtLi2 = document.createTextNode("X");
         txtLi41 = document.createTextNode("Cancel");
         txtLi42 = document.createTextNode("Crop");

         //li1.appendChild(tagA1);
         li2.appendChild(tagA2);
         li41.appendChild(tagA41);
         li42.appendChild(tagA42);
         //tagA1.appendChild(txtLi1);
         tagA2.appendChild(txtLi2);
         tagA41.appendChild(txtLi41);
         tagA42.appendChild(txtLi42);

         tagA41.onclick = function(){imageEditorDestroy();};
         tagA42.onclick = function(){aufruf();};
         tagA2.onclick = function(){imageEditorDestroy();};

         var distanceId = document.createAttribute("id");
         var containerId = document.createAttribute("id");
         distanceId.nodeValue = "distance";
         containerId.nodeValue = "container";
         containerDiv.setAttributeNode(containerId);
         distanceDiv.setAttributeNode(distanceId);

         containerDiv.style.backgroundImage="url("+filename+")";

         ul1.appendChild(li1);
         ul2.appendChild(li2);
         ul4.appendChild(li41);
         ul4.appendChild(li42);

         underDis1Div.appendChild(ul1);
         underDis1Div.appendChild(ul2);
         underDis2Div.appendChild(ul3);
         underDis2Div.appendChild(ul4);

         distanceDiv.appendChild(underDis1Div);
         distanceDiv.appendChild(underDis2Div);
         distanceDiv.style.marginBottom= (-(srcHeight/2))+"px";

         underDis1Div.setAttributeNode(underDis1Class);
         underDis2Div.setAttributeNode(underDis2Class);

         imageEditorDiv.appendChild(distanceDiv);
         imageEditorDiv.appendChild(containerDiv);

         containerDiv.style.height=srcHeight+"px";
         containerDiv.style.width=srcWidth+"px";

         imageEditorDiv.style.width='100%';
         imageEditorDiv.style.height='100%';

         createBB(aspectRatio,imgType);
         createTDBBox(boxY,boxX,boxHeight+boxY,boxWidth+boxX);

}
function imageEditorDestroy () {
         var node = document.getElementById("distance");
         var node1 = document.getElementById("container");
         if (node&&node1){
		node.parentNode.removeChild(node);
                 node1.parentNode.removeChild(node1);
                 counterBbox--;
                 boxIdTmp = ("boxtable"+counterBbox);
         }
         document.getElementById("imageEditor").style.display = "none";
}



function decrypt (string){
	key="alvensleben";
	array_alphabet=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","@","-",".",":","_","%");
	var result="";

	for(i=0;i<string.length;i++){
		var j=0;
		while(j<array_alphabet.length&&string.charAt(i)!=array_alphabet[j])j++;
			position_char=j;
			j=0;
			//alert(string.charAt(i));
		while(j<array_alphabet.length&&key.charAt(i%key.length)!=array_alphabet[j])j++;
			position_key=j;
			position=(position_char-position_key)%array_alphabet.length;
			if(position<0)position+=array_alphabet.length;

			//alert(key.charAt(i%key.length));

			result+=array_alphabet[position];
			//alert(array_alphabet[position]);

	}
	document.location.href=decodeURIComponent(result);
}

function jsPrompt(promptTXT){
	if(document.getElementById('jsPrompt')){
		lines=promptTXT.split("\n");
		for (i=0;i<lines.length;i++){
			var newBR = document.createElement("br");
			var newTXT = document.createTextNode(lines[i]);
			document.getElementById('jsPrompt').appendChild(newTXT);
			document.getElementById('jsPrompt').appendChild(newBR);
		}
	} else jsPromptPre+="\n"+promptTXT;
}






    
              	  



