// Author: Andrew Green / Copyright DR Solutions International Ltd.

// 2008-07+

function fncStyleDisplayByType(oStyle,oButton){
  oStyle = document.getElementById(oStyle);
  sType = oButton.title;
  switch(sType){
    case "hide":
      oStyle.style.display="none";
      oButton.value="Show";
      oButton.title="show";
      break;
    case "show":
      oStyle.style.display="block";
      oButton.value="Hide";
      oButton.title="hide";
      break;
    default: return false;
  }
}

function fncObjectChange(oChange,sType,sValue){
  if(!(oChange===undefined || sType===undefined || sValue===undefined)){
    if(!(oChange instanceof Object)){oChange=document.getElementById(oChange);}
    switch(sType){
      case "disabled": if(sValue===true || sValue===false){oChange.disabled=sValue};break;
      default: return false;
    }
  }
}

function fncStyleChange(oStyle,sType,sValue){
  if(!(oStyle===undefined || sType===undefined || sValue===undefined)){
    if(!(oStyle instanceof Object)){oStyle=document.getElementById(oStyle);}
    switch(sType){
      case "background": if(sValue.indexOf("#")>-1){oStyle.style.backgroundColor=sValue;}else{oStyle.style.backgroundImage="url(img/"+sValue+")";};break;
      case "border": if(sValue.indexOf("#")>-1){oStyle.style.borderColor=sValue;};break;
      case "image": oStyle.src=sValue;break;
      case "text-colour": if(sValue.indexOf("#")>-1){oStyle.style.color=sValue;};break;
      case "text-decoration": oStyle.style.textDecoration=sValue;break;
      case "class": oStyle.className="disabled";break;
      default: return false;
    }
  }
}

function fncFormSubmit(oForm,sAction,sMethod){
  if(oForm!=undefined){
    if(!(oForm instanceof Object)){oForm=document.getElementById(oForm);}
    if(!(sAction==undefined)){oForm.action=sAction;}
    if(!(sMethod==undefined)){oForm.method=sMethod;}
    oForm.submit();
  }
}

function fncPromptConfirm(sMsg,sUrlTrue,sUrlFalse){
  var oConfirm = confirm(sMsg);
  switch(oConfirm){
    case true: window.location=sUrlTrue;break;
    case false: if(!(sUrlFalse==undefined)){window.location=sUrlFalse;}else{return void(0);}break;
    default: return false;
  }
}


//function fncObjectChange(){
//}


// OLD

/*
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 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");
}

