
var changeLangURL = null;

function changeLang(elem, msg) {
 if (elem && msg) {  
  if (!changeLangURL)
    changeLangURL=elem.href;  
  if (msg.length>0 && !window.confirm(msg)) {
    elem.href='javascript:void(0);';
    return false;
  } else {
    elem.href=changeLangURL;
  }
 }
}

function drag(a) {
  a.href = 'javascript:void(0);';
}

function checkSearchForm(form, msg) {
 var any=false;
 if (form.elements['substring'].value.length > 0) {
  any=true;
 }
 for (i = 0; i < form.elements.length; i ++) {
  if ((form.elements[i].tagName=="SELECT") && (form.elements[i].selectedIndex > 0)) {
   any=true;
   break;
  }
 }
 if (!any)
  alert(msg);
 return any;
}

function checkAskForm(form, msg1, msg2) {
 if (form.elements['title'].value.length == 0) {
  alert(msg1);
  return false;
 }
 if (form.elements['content'].value.length == 0) {
  alert(msg2);
  return false;
 }
 return true;
}

var loginFormFilled = false;

function clearLoginFormFilling(form) {
 if (!loginFormFilled) {
  form.elements['j_username'].value='';
  form.elements['j_password'].value='';
  loginFormFilled = true;
 }
}


function newWin(url, w, h) {
 var name=''+Math.random();
 name = name.substring(name.indexOf(".")+1);
 var left = window.screen.width / 8; 
 var top = window.screen.height / 8;
 win = window.open(url,"helpWinU"+name,"left="+left+",top="+top+",width="+(w?w:'400')+",height="+(h?h:'300')+",resizable=yes,scrollbars=yes,dependent=no");
 win.focus();
}

function newWinCentred(url) {
 var name = ""+Math.random();
 name = name.substring(name.indexOf(".")+1);
 win = window.open(url,"helpWinU"+name);
 win.focus();
}

function popupCentred(url, w, h) {
 var x=0;
 var y=0;
 if ((w / screen.width)< 0.9) {
  x=((screen.width-w)/4);
  y=((screen.height-h)/5);
 }
 var win = window.open(url,null,"left="+x+",top="+y+",width="+w+",height="+h+",resizable=yes,scrollbars=no,dependent=no");
 win.focus();
}

function newBlankWin(url) {
 var w = screen.availWidth-10;
 var h = screen.availHeight-30;
 setTimeout(window.open(url,null,"width="+w+",height="+h+",resizable=yes,scrollbars=yes,left=0,top=0"),1);
 //win.focus();
}


function exportWin(winName,kind,id,lang,width,height,left,top,type,refr) {
 var scroll=((kind=='rating')?'scrollbars=yes,resizable=yes,':'resizable=no,');
 var ewin = window.open(appPath+'cabinet/servlet/exportData?kind='+kind+'&id='+id+'&lang='+lang+'&width='+width+'&height='+height+((type)?('&types='+type):'')+((refr)?('&refresh='+refr):''),kind+id+winName+((type)?type:''),scroll+'location=no,menubar=no,toolbar=no,width='+width+',height='+height+',status=bo,top='+top+',left='+left);
 ewin.focus();
}

function exportPortfolio(winName,url,id,lang,width,height,left,top) {
 var ver=navigator.appVersion, client='IE';
 dom=document.getElementById?1:0
 ie5=(ver.indexOf("MSIE 5")>-1&&dom)?1:0;
 ie6=(ver.indexOf("MSIE 6")>-1&&dom)?1:0;
 if(!(ie5 || ie6)) client='other';

 var ewin = window.open(url+'?kind=portfolio&id='+id+'&lang='+lang+'&width='+width+'&height='+height+'&client='+client,
  'portfolio'+id+winName, 'scrollbars=yes,resizable=yes,location=no, menubar=no, toolbar=no,width='+width+',height='+height+',status=bo,top=0,left=0');

 ewin.moveTo(left,top);
 ewin.focus();
}

function resizeWindow() {
 var table = document.getElementById("ContentTable");
 var dX = table.scrollWidth - document.body.clientWidth;
 var dY = table.scrollHeight - document.body.clientHeight;
 window.resizeBy(dX, dY);
 var sw = window.screen.width;
 var sh = window.screen.height;
 var X = sw/8;
 var Y = sh/8;
 var moveToX = X;
 var moveToY = Y;
 var maxWidth = (sw - moveToY);
 var maxHeight = (sh - moveToY);
 if (document.body.clientWidth > (maxWidth-50)) {
   window.resizeBy((maxWidth - document.body.clientWidth),0);
   moveToX = 0;
 }
 if (document.body.clientHeight > (maxHeight-50)) {
   window.resizeBy(0,(maxHeight - document.body.clientHeight));
   moveToY = 0;
 }
 if (X!=moveToX || Y!=moveToY) {
   window.moveTo(moveToX,moveToY);
 }
}

  