// Author: Andrew Green / Copyright DR Solutions International Ltd.

function URLEncode(surl){surl=encodeURI(surl);surl=surl.replace(/,/g,"%2C");/*surl=surl.replace(/?/g,"%3F");*/surl=surl.replace(/:/g,"%3A");surl=surl.replace(/&/g,"%26");surl=surl.replace(/=/g,"%3D");surl=surl.replace(/$/g,"%24");surl=surl.replace(/#/g,"%23");return surl;}
function URLEncode(surl){surl=decodeURI(surl);surl=surl.replace(/%2C/g,",");/*surl=surl.replace(/%3F/g,"?");*/surl=surl.replace(/%3A/g,":");surl=surl.replace(/%26/g,"&");surl=surl.replace(/%3D/g,"=");surl=surl.replace(/%24/g,"$");surl=surl.replace(/%23/g,"#");return surl;}

function fncexternallink(){
  if (document.getElementsByTagName){
    var i,a; a=document.getElementsByTagName('a');
    for(var i=0; i<a.length; i++){if(a[i].getAttribute('href') && a[i].getAttribute('rel')=='externallink'){a[i].target='_blank';}}
  }
}

function fncsubmit(oform){document.getElementById(oform).submit();}

function fncformfieldfileUpload(oform){
  oform = document.getElementById(oform);
  var surl = "";
  for (var i=0;i<oform.length;i++){
    if(oform.elements[i].type=='text'){
      if(i>1){surl=surl+"&"}
      surl=surl+oform.elements[i].name+"%3D"+oform.elements[i].value;
    }
  }
  oform.action = oform.action+"&addurl="+surl;
}

function fncconfirm(stext,surltrue,surlfalse){var oconfirm=confirm(stext);if(oconfirm==true){window.location=surltrue;}else{window.location=surlfalse;}}

function fncstylechange(oitem,stype,svalue){
  switch(stype){
    case "background": if(svalue.indexOf("#")>-1){oitem.style.backgroundColor=svalue;}else{oitem.style.backgroundImage="url(img/"+svalue+")";};break;
    case "border": if(svalue.indexOf("#")>-1){oitem.style.borderColor=svalue;};break;
    case "image": oitem.src=svalue;break;
    case "text-colour": if(svalue.indexOf("#")>-1){oitem.style.color=svalue;};break;
    case "text-decoration": oitem.style.textDecoration=svalue;break;
    default: return false;
  }
}

function fncwmpwrite(strid,strurl){
  document.write("<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' type='application/x-oleobject' id='" + strid + "'>\n");
  document.write("<param name='filename' value='" + strurl + "'>\n");
  document.write("<param name='autostart' value='true'>\n");
  document.write("<param name='showcontrols' value='true'>\n");
  document.write("<param name='showstatusbar' value='false'>\n");
  document.write("<param name='showdisplay' value='false'>\n");
  document.write("<param name='volume' value='0'>\n");
  document.write("<embed type='application/x-mplayer2' src='" + strurl + "' showcontrols='true' showstatusbar='false' showdisplay='true' autostart='true' volume='0' id='" + strid + "'></embed>\n");
  document.write("</object>\n");
}

function fnccleartextbox(ofield,stext){
//  ofield = document.getElementById(ofield);
  if(ofield.value==stext){
    ofield.value = "";
  }
}

function fnctextlimiter(ofield,ocounter,ilimit){
  ofield = document.getElementById(ofield);
  ocounter = document.getElementById(ocounter);
  if(ofield.value.length > ilimit){
    ofield.value = ofield.value.substring(0,ilimit);
  }else{
    ocounter.value = ilimit - ofield.value.length;
  }
}

function fncWindowPosition(windowWidth,windowHeight){ 
  if (parseInt(navigator.appVersion) >= 4) window.moveTo((screen.width/2)-(windowWidth/2+10),(screen.height/2)-(windowHeight/2+20));
}

function fncWindowPopup(strUrl,intWidth,intHeight){
  var newwindow = window.open(strUrl,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+intWidth+",height="+intHeight+",left=0,top=0","False");
}

