function setDisabled(id, status) {
    document.getElementById(id).disabled=status;
}

function setColor(id, color)
{
    document.getElementById(id).style.color=color; 
}

function setBorder(id, color)
{
    document.getElementById(id).style.border="1px solid " + color; 
}

function setValue(id, data) {
    document.getElementById(id).value=data;
}

function resolutionSelectOnChange() {
    var resolution = document.getElementById('resolution');

    if(resolution.selectedIndex == 0) {
        setDisabled('width', 0);
        setDisabled('height', 0);
    }
    else {
        setDisabled('width', 1);
        setDisabled('height', 1);
        if(resolution.value == 1) {
            setValue('width', '1280');
            setValue('height', '720');
        }
        else if(resolution.value == 2) {
            setValue('width', '1920');
            setValue('height', '1080');
        }
        else if(resolution.value == 3) {
            setValue('width', '1920');
            setValue('height', '1200');
        }
        else if(resolution.value == 4) {
            setValue('width', '1024');
            setValue('height', '768');
        }
        else if(resolution.value == 5) {
            setValue('width', '1280');
            setValue('height', '768');
        }
        else if(resolution.value == 6) {
            setValue('width', '1366');
            setValue('height', '768');
        }
        else if(resolution.value == 7) {
            setValue('width', '1600');
            setValue('height', '1200');
        }
        else if(resolution.value == 8) {
            setValue('width', '2560');
            setValue('height', '1460');
        }
        else if(resolution.value == 9) {
            setValue('width', '2560');
            setValue('height', '1600');
        }
    }
}

function checkDistanceForm() {
    var hasError = false;

    var resolution = document.getElementById('resolution');
    var width = document.getElementById('width');
    var height = document.getElementById('height');
    var size = document.getElementById('size');

    if(resolution.selectedIndex == 0 && (
       width.value.trim() == "" ||
       IsNumeric(width.value.trim()) == false ||
       width.value.trim() < 1 ||
       height.value.trim() == "" ||
       IsNumeric(width.value.trim()) == false ||
       height.value.trim() < 1)) {
        hasError = true;
        if(width.value.trim() == "" || IsNumeric(width.value.trim()) == false || width.value.trim() < 1)
            setBorder('width', '#C00000');
        else
            setBorder('width', '#000000');
        if(height.value.trim() == "" || IsNumeric(width.value.trim()) == false || height.value.trim() < 1)
            setBorder('height', '#C00000');
        else
            setBorder('height', '#000000');
    }
    else {
        setBorder('width', '#000000');
        setBorder('height', '#000000');
    }

    if(size.value.trim() == "" || IsNumeric(size.value.trim()) == false || size.value.trim() < 1) {
        hasError = true;
        setBorder('size', '#C00000');
    }
    else
        setBorder('size', '#000000');

    if(hasError) {
        //alert('One or more errors found in submission. Correct them to continue.');
        return false;
    }
    else
        return true;
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


