function getImageWidth(iDefaultWidth) {
  return iWidth = (obImage.src) ? obImage.width : iDefaultWidth;
}
function getImageHeight(iDefaultHeight) {
  return iWidth = (obImage.src) ? obImage.height : iDefaultHeight;
}

function isValidName(ob,validExtensions) {
  var param = ob.value.toLowerCase();
  if (!param) {
    alert("Please enter a the name and path of file you wish to upload...");
    ob.focus();
    return false;
  } else {
    var ext = param.substr(param.lastIndexOf('.'),5);
    if (!cs_InStr(validExtensions,ext)) {
      alert('This is an invalid file type.  Please choose another file...');
      ob.focus();
      return false;
    }  
  }
  return true;
}

function submitThisForm(param) {
  var iReturnFileName = document.content.iReturnFileName.value;
  var nvSQL = document.content.nvSQL.value;
  var nvSQLParams = document.content.nvSQLParams.value;
  var nvValidFileExtensions = document.content.nvValidFileExtensions.value;
  if (isValidName(document.content.binaryFile,param)) {
    var fileName = isSecure() + 'tp_FileUploadForm.asp?j='+iReturnFileName+'&q='+nvValidFileExtensions+'&m='+nvSQL+'&n='+nvSQLParams;
    document.content.action = fileName;
    document.content.submit();
  }
}

function cs_isValidText(param) {
  if (!param) return false;
  var j = parseInt(param.length);
  var invalidChars = "^~`|\=><?/@#$%&*()+!:,;'" + '"';
  for (var i=0; i<j; i++) {
    if (invalidChars.indexOf(param.charAt(i)) != -1) return false;
  }
  return true;
}

function getMessage(param) {
  if (param == null) return;
  var thisStr;
  switch(param) {
    case '.jpg': thisStr = 'JPEG Image...'; return thisStr;
    case '.gif': thisStr = 'GIF Image...'; return thisStr;
    case '.bmp': thisStr = 'Bitmap Image...'; return thisStr;
    case '.doc': thisStr = 'Invalid file type...'; return thisStr;
    case '.exe': thisStr = 'Invalid file type...'; return thisStr;
    case '.sys': thisStr = 'Invalid file type...'; return thisStr;
    case '.bat': thisStr = 'Invalid file type...'; return thisStr;
    case '.dll': thisStr = 'Invalid file type...'; return thisStr;
    case '.vbs': thisStr = 'Invalid file type...'; return thisStr;
    case '.swf': thisStr = 'Shockwave Flash file type...'; return thisStr;
    case '.js': thisStr = 'Javascript file type...'; return thisStr;
    case '.asp': thisStr = 'Active Server Page file type...'; return thisStr;
    case '.html': thisStr = 'Hypertext Markup file type...'; return thisStr;
    case '.htm': thisStr = 'Hypertext Markup file type...'; return thisStr;
    case '.xhtml': thisStr = 'Extensible Hypertext Markup file type...'; return thisStr;
    case '.pdf': thisStr = 'Adobe Print Definition file type...'; return thisStr;
    case '.inc': thisStr = 'Include file type...'; return thisStr;
    case '.txt': thisStr = 'Text file type...'; return thisStr;
    case '.bak': thisStr = 'Backup file type...'; return thisStr;
    default: return 'Invalid file type...';
  }
}

var thisImage = new Image();

function getThisImage(param,fileExt) {
  if (param == null) return;
  var thisSrc;
  var fx = param.substring(param.lastIndexOf('.'),param.length);
  var imageExt = '.jpg;.gif;.bmp';
  var msie=document.all;
  var nn6=document.getElementById;
  if ((imageExt.indexOf(fx) != -1)) {
    var i,defaultWidth,defaultHeight,bResetHeight,bResetWidth;
    var thisObj=document.content.binaryFile;
    var thisWidth=0,thisHeight=0;
    defaultWidth = 150;
    defaultHeight = 150;
    thisImage.src = param;
    thisHeight = thisImage.height;
    thisWidth = thisImage.width;
    if ((thisHeight > defaultHeight) || (thisWidth > defaultWidth)) {
      bResetWidth = (thisWidth > thisHeight) ? true : false;
      i = (bResetWidth) ? Math.round((defaultWidth / thisWidth)*100) : Math.round((defaultHeight / thisHeight)*100);
      thisWidth = Math.round((i*thisWidth)/100);
      thisHeight = Math.round((i*thisHeight)/100);
    }  
    thisSrc = '<img src="'+param+'" width="'+ thisWidth +'" height="'+ thisHeight +'">';
  } else {
    if (fileExt.indexOf(fx) == -1) {
      thisSrc = '<img src="/images/cs_Warning.gif" width="39" height="39">';
    } else {
      thisSrc = '<img src="/images/cs_CategoryMaintenance.gif" width="35" height="43">';
    }
  }
  if (msie||nn6) {
    var layerObj1=document.getElementById? document.getElementById("layer3"): document.all.layer3
    var layerObj2=document.getElementById? document.getElementById("layer4"): document.all.layer4
    layerObj2.innerHTML=getMessage(fx);
    layerObj1.innerHTML='Loading image...';
    layerObj1.innerHTML=thisSrc;
  } else {
    if (document.layers) {
      document.layer1.document.layer2.document.write(thisSrc);
      document.layer1.document.layer2.document.close();
    } else {
      alert('If you wish to preview images please upgrade your browser...');
    }
  }  
}
