﻿/* Controls the amount of characters keyed into a TextBox If the user types
   more than the allowed amount the function returns the orginal text
*/
function textCounter(field, countfield, maxlimit)
{if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
else
    {
    countfield.value = maxlimit - field.value.length;
    }
}

function fileSelected(fileName) {
    // Updates teh Session Variable with the file selected
    WebService.UpdateSession_FileSelected(fileName);
    return false;
}

function displayCMSform(formName) {
    // Display the div in "formName"
    document.getElementById(formName).style.display = 'block';
}
function hideCMSform(formName) {
    // Hide the div in "formName"
    document.getElementById(formName).style.display = 'none';
}

function displayCMSpanel(panelID) {
    //Hide all the CMS divs on this page and then display the one requested
    document.getElementById('cmsMeta').style.display = 'none';
    document.getElementById('cmsHTML').style.display = 'none';
    document.getElementById('cmsModule').style.display = 'none';

    document.getElementById(panelID).style.display = 'block';
}


//
// Case Study Routines
//
function CSdisplayLargeImage(img, title, desc) {
    // var imgFixed = 'url(' + img + ')';
    var imgFixed = img;
    imgFixed = imgFixed.replace('~/', '../'); // Get correct relatice refference to item
    imgFixed = imgFixed.replace(' ', '%20'); // Code spaces in the path correctly
    // Update Img control
    document.getElementById('casestudy_largeimageIMG').src = imgFixed;
    if (title != null) document.getElementById('casestudy_largeimageTITLE').innerHTML = title;
    if (desc != null) document.getElementById('casestudy_largeimageDESC').innerHTML = desc;
    // Update DIV
    // document.getElementById('casestudy_largeimageID').style.backgroundImage = imgFixed;

    // Hide the ASP Image Control that displays the Default Image and Display the IMG Tag
    document.getElementById('ctl00_ContentPlaceHolder1_CaseStudyDisplay1_casestudy_largeimageTITLE_ASP').style.display = 'none';
    document.getElementById('ctl00_ContentPlaceHolder1_CaseStudyDisplay1_casestudy_largeimageIMG_ASP').style.display = 'none';
    document.getElementById('ctl00_ContentPlaceHolder1_CaseStudyDisplay1_casestudy_largeimageDESC_ASP').style.display = 'none';
    document.getElementById('casestudy_largeimageTITLE').style.display = 'block';
    document.getElementById('casestudy_largeimageIMG').style.display = 'block';
    document.getElementById('casestudy_largeimageDESC').style.display = 'block';
}




// Validate for Blank field
function checkEmpty(source, args) {
    // if value is empty return INVALID
    if (args.Value == '')
        args.IsValid = false;
    else
        args.IsValid = true;
}

// Date Checking
function checkdate(source, args) {
    var inputDate = args.Value;
    // var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/;  //Basic check for format validity
    var validformat = /(\d{2})(\d{2})(\d{4})/  //Basic check for format validity
    if (inputDate != '' && inputDate.match(validformat)) {
       // alert("Invalid Date Format. Please correct and submit again.")
        args.IsValid = false;
    }
    else { //Detailed check for valid date ranges
        var monthfield = inputDate.split("/")[0]
        var dayfield = inputDate.split("/")[1]
        var yearfield = inputDate.split("/")[2]
        var dayobj = new Date(yearfield, monthfield - 1, dayfield)
        if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {
        //    alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
            args.IsValid = false;
        }
        else
            args.IsValid = true;
    }
}

var truncate = function(text, max_chars) {
    return (text.length > max_chars) ? text.substring(0, max_chars) + '...' : text;
}



