
// Title: Common

// Version: 1.0 

// Date: 

// Note: Common script files used for validation

// if two digit year input dates after this year considered 20 century.

//Display the calendar in a modal dialog.
//If a selected date is supplied, send that to the calendar page as a querystring value
function ShowModalCalendar(ctlDateLabelId, 
                           ctlDateHiddenTextBoxId, 
                           selectedDate)
{
    var dateEl = 
            document.getElementById(ctlDateLabelId);
    var src = 
            window.event.srcElement;
    var dialogLeft = 
            window.screenLeft + src.offsetLeft;
    var dialogTop = 
            window.screenTop + src.offsetTop;
    //var retValue = 
            window.showModalDialog('CalendarPopup.aspx?date=' + selectedDate, null, 'dialogTop:' 
                    + dialogTop + ';dialogLeft:' + dialogLeft 
                    + ';dialogHeight:185px;dialogWidth:205px;scroll:no;status:no;unadorned:yes;help:no;');
    var retValue = window.showModalDialog('CalendarPopup.aspx?date=' + selectedDate, null, 'dialogTop:' 
                    + dialogTop + ';dialogLeft:' + dialogLeft 
                    + ';dialogHeight:185px;dialogWidth:205px;scroll:yes;status:yes;unadorned:yes;help:yes;');
    //alert(retValue);
    if (retValue != null)
    {
        dateEl.innerHTML = retValue;
        document.getElementById(ctlDateHiddenTextBoxId).value = 
                retValue;
    }
}

//PURPOSE: Allow only date of birth entries to be typed into a control
//USAGE: onkeypress="return AllowOnlyDate();"
function AllowOnlyDate()
{
    __validationResult=true;
    __allowReturn = false;
    
    var ASCII = event.keyCode;
    if (ASCII == 9)                     {return true;} // 9=TAB
    if ((ASCII >= 48) && (ASCII <= 57)) {return true;} // (0-9)=(48-57)
    if (ASCII == 47)                    {return true;} // 47=/
    
    __validationResult=false;
    return false;
}

//PURPOSE: Allow only a positive number to be typed into a control
//          by excluding all non-numeric or numberic-related characters
//USAGE: onkeypress="return AllowOnlyPositiveNumbers();"
function AllowOnlyPositiveNumbers()
{
    __validationResult=true;
    __allowReturn = false;
    
    var ASCII = event.keyCode;
    if (ASCII == 9)                     {return true;} // 9=TAB
    if (ASCII == 46)                    {return true;} // 46=decimal point
    if ((ASCII >= 48) && (ASCII <= 57)) {return true;} // (0-9)=(48-57)
    
    __validationResult=false;
    return false;
}

//PURPOSE: Allow only alphanumeric characters and the specified special characters to be typed into a control
//USAGE: onkeypress="return AllowOnlyAlphanumericAndPunctuationForSearchString();"
function AllowOnlyAlphanumericAndPunctuationForSearchString()
{
    __validationResult=true;
    __allowReturn = false;
    
    var ASCII = event.keyCode;
    if (ASCII == 32)                     {return true;} // 32=WHITESPACE
    if ((ASCII >= 48) && (ASCII <= 57)) {return true;}  // (0-9)=(48-57)
    if ((ASCII >= 65) && (ASCII <= 90)) {return true;}  // A-Z=(65-90)
    if ((ASCII >= 97) && (ASCII <= 122)){return true;}  // a-z=(97-122)
    if (ASCII == 40)                      {return true;}  //40=(
    if (ASCII == 41)                      {return true;}  //41=)
    if (ASCII == 44)                      {return true;}  //44=,
    if (ASCII == 46)                      {return true;}  //46=.
    if (ASCII == 34)                      {return true;}  //34="
    if (ASCII == 38)                      {return true;}  //38=&
    
    __validationResult=false;
    return false;
}

//PURPOSE: Unchecck the checkbox upon entering text in the Texbox control
//USAGE: onkeydown="return unCheckDefaultSearch(checkboxID);"
function unCheckDefaultSearch(id)
{
    var chck = document.getElementById(id);
    if (chck != null)
    {
        chck.checked=false;
    }
}


//PURPOSE: Allow only alphanumeric characters and the specified special characters to be typed into a control
//USAGE: onkeypress="return AllowOnlyAlphanumericAndPunctuationForLocation();"
function AllowOnlyAlphanumericAndPunctuationForLocation()
{
    __validationResult=true;
    __allowReturn = false;
    
    var ASCII = event.keyCode;
    if (ASCII == 32)                     {return true;} // 32=WHITESPACE
    if ((ASCII >= 48) && (ASCII <= 57)) {return true;}  // (0-9)=(48-57)
    if ((ASCII >= 65) && (ASCII <= 90)) {return true;}  // A-Z=(65-90)
    if ((ASCII >= 97) && (ASCII <= 122)){return true;}  // a-z=(97-122)
    if (ASCII == 40)                      {return true;}  //40=(
    if (ASCII == 41)                      {return true;}  //41=)
    if (ASCII == 44)                      {return true;}  //44=,
    if (ASCII == 46)                      {return true;}  //46=.
    
    __validationResult=false;
    return false;
}

//PURPOSE: show the option dialog box
//USAGE: onclick="return ShowOptions();"
function ShowOptions(strDivTag)
{
    var divTag = null;

    if(strDivTag == 'options')
    {
        divTag = 
            document.getElementById("divOptions");
    }
    else
    {
        divTag = 
            document.getElementById("divAdvancedSearch");
    }
    
    if(divTag != null)
    {
        divTag.style.display = "block";
    }
}

//PURPOSE: hide the option dialog box
//USAGE: onclick="return HideOptions();"
function HideOptions(strDivTag)
{
    var divTag = null;

    if(strDivTag == 'options')
    {
        divTag = 
            document.getElementById("divOptions");
    }
    else
    {
        divTag = 
            document.getElementById("divAdvancedSearch");
    }

    if( (divTag != null) && 
        (divTag.style.display == "block") )
    {
        divTag.style.display = "none";
    }
}

//PURPOSE: show the outlook window
//USAGE: onclick="mailto();"
function mailto()
{
  var subject = "Microsoft Learning Class Locator Page";
  parent.location.href='mailto:?subject=' + subject 
    + '&body=' + escape(location.href);
}


//PURPOSE: Client side handling of dropdown change
function dropChange(dropArrangeBy,dropAudience)
{
    var dAud = document.getElementById('DivAudience');
    var dropAud = document.getElementById(dropAudience);
    var dArr = document.getElementById(dropArrangeBy);
    var selectedvalue = dArr.options[dArr.selectedIndex].value;
    if (selectedvalue == "TrainingCentersAlphabetical")
    {
        if (dAud != null)
        {
           dAud.style.display = "none";
        }
    }
    else if (selectedvalue == "TrainingCentersProximity")
    {
        if (dAud != null)
        {
           dAud.style.display = "none";
        }
    }
    else  if (selectedvalue == "CourseNumber")
    {
        if (dAud != null)
        {
            dAud.style.display = "block";
            dropAud.selectedIndex = 0;
        }        
    }
    else  if (selectedvalue == "CourseName")
    {
        if (dAud != null)
        {
            dAud.style.display = "block";        
            dropAud.selectedIndex = 0;
        }
    }
}

function OnmouseClickPaginationButton(id) {
    // Fetch the existing class name for the box image
    element = document.getElementById(id);
    var existingClassName = element.className;
    var elemAttribs = element.attributes;
    // Change the class name for the box only when the existing
    // class name is not PaginationBoxNumberSelected
    if (existingClassName != 'PaginationBoxNumberSelected') 
    {        
        var mouseOverClass = 'PaginationBoxNumberPressed';
        elemAttribs.removeNamedItem('class');
        elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
    }
}

function OnmouseoverPaginationButton(id) {
    // Fetch the existing class name for the box image
    element = document.getElementById(id);
    var existingClassName = element.className;
    var elemAttribs = element.attributes;
    // Change the class name for the box only when the existing
    // class name is not PaginationBoxNumberSelected
    if (existingClassName != 'PaginationBoxNumberSelected') 
    {        
        var mouseOverClass = 'PaginationBoxNumberRollover';
        elemAttribs.removeNamedItem('class');
        elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
    }
}

function OnmouseOutPaginationButton(id) {
    // Fetch the existing class name for the box image
    element = document.getElementById(id);
    var existingClassName = element.className;
    var elemAttribs = element.attributes;
    // Change the class name for the box only when the existing
    // class name is not PaginationBoxNumberSelected
    if (existingClassName != 'PaginationBoxNumberSelected') 
    {        
        var mouseOverClass = 'PaginationBoxNumberNormal';
        elemAttribs.removeNamedItem('class');
        elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
    }
}

function OnmouseClickLinkArrow(id, identifier) 
{
    if(identifier == 'B')
        var mouseOverClass = 'PaginationArrowBackPressed';
    else
        var mouseOverClass = 'PaginationArrowNextPressed';
        
    var elemAttribs = document.getElementById(id).attributes;
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseoverLinkArrow(id, identifier) {
    if (identifier == 'B')
        var mouseOverClass = 'PaginationArrowBackRollover';
    else
        var mouseOverClass = 'PaginationArrowNextRollover';
    
    var elemAttribs = document.getElementById(id).attributes;
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseOutLinkArrow(id, identifier) {
    if (identifier == 'B')
        var mouseOverClass = 'PaginationArrowBackNormal';
    else
        var mouseOverClass = 'PaginationArrowNextNormal';
    
    var elemAttribs = document.getElementById(id).attributes;
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseclickGoButton(id, errorMessage, chkboxOne, chkboxTwo) {
    var elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'ButtonGoMouseClick';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));

    return CheckTypeOfInstruction(chkboxOne, chkboxTwo, errorMessage);
}

function OnmouseoverGoButton(id) {
    var elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'ButtonGoMouseOver';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
    return true;
}

function OnmouseoutGoButton(id) {
    var elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'ButtonGoNormal';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function MakeAttribute(attName, attValue) {
    var objAttribute = document.createAttribute(attName);
    objAttribute.value = attValue;
    return objAttribute;
}

function CheckTypeOfInstruction(chkboxOne, chkboxTwo, errMessage) 
{    
    if (document.getElementById(chkboxOne).checked == false && document.getElementById(chkboxTwo).checked == false) {
        alert(errMessage);
        return false;
    }
    else
        return true;
}

function OpenSADiv() {
    var saTooltipStyle = SAToolTip.style;
    x = event.clientX + document.documentElement.scrollLeft - 265;
    y = event.clientY + document.documentElement.scrollTop;
    saTooltipStyle.display = "block";
    saTooltipStyle.position = "absolute";
    saTooltipStyle.left = x;
    saTooltipStyle.top = y;
}

function CloseSADiv(objAnchor) {
    document.getElementById('SAToolTip').style.display = 'none';
    document.getElementById(objAnchor).style.color = '#CACACA';
}

function WhatsThisChangeColorAdvanced(objAnchor){
    document.getElementById(objAnchor).style.color = '#000000';
}


function OpenSAAdvancedDiv() {
    var saAdvTooltipStyle = SAAdvancedToolTip.style;
    x = event.clientX + document.documentElement.scrollLeft - 20;
    y = event.clientY + document.documentElement.scrollTop + 4;
    saAdvTooltipStyle.display = "block";
    saAdvTooltipStyle.position = "absolute";
    saAdvTooltipStyle.left = x;
    saAdvTooltipStyle.top = y;
}

function CloseSADivAdvanced(objAnchor) {
    document.getElementById('SAAdvancedToolTip').style.display = 'none';
    document.getElementById(objAnchor).style.color = '#0066CC';
}

function OpenInstructionAdvancedDiv() {
    var instructAdvTooltipStyle = InstructionAdvancedTooltip.style;
    x = event.clientX + document.documentElement.scrollLeft - 20;
    y = event.clientY + document.documentElement.scrollTop + 4;
    instructAdvTooltipStyle.display = "block";
    instructAdvTooltipStyle.position = "absolute";
    instructAdvTooltipStyle.left = x;
    instructAdvTooltipStyle.top = y;
}

function CloseInstructionAdvancedDiv(objAnchor) {
    document.getElementById('InstructionAdvancedTooltip').style.display = 'none';
    document.getElementById(objAnchor).style.color = '#0066CC';
}

function OpenGoldPartnersDiv() {
    var goldPartnersTooltipStyle = GoldPartnersToolTip.style;    
    x = event.clientX + document.documentElement.scrollLeft;
    y = event.clientY + document.documentElement.scrollTop + 4;
    goldPartnersTooltipStyle.display = "block";
    goldPartnersTooltipStyle.position = "absolute";
    goldPartnersTooltipStyle.left = x;
    goldPartnersTooltipStyle.top = y;
}

function CloseGoldPartnersDiv(objAnchor) {
    document.getElementById('GoldPartnersToolTip').style.display = 'none';
}

function OpenSoftAssuranceDiv() {
    var softAssuranceToolTipStyle = SoftAssuranceToolTip.style;
    x = event.clientX + document.documentElement.scrollLeft;
    y = event.clientY + document.documentElement.scrollTop + 4;
    softAssuranceToolTipStyle.display = "block";
    softAssuranceToolTipStyle.position = "absolute";
    softAssuranceToolTipStyle.left = x;
    softAssuranceToolTipStyle.top = y;
}

function CloseSoftAssuranceDiv(objAnchor) {
    document.getElementById('SoftAssuranceToolTip').style.display = 'none';
}

function OpenNewDiv() {
    var newToolTipStyle = NewToolTip.style;    
    x = event.clientX + document.documentElement.scrollLeft;
    y = event.clientY + document.documentElement.scrollTop + 4;
    newToolTipStyle.display = "block";
    newToolTipStyle.position = "absolute";
    newToolTipStyle.left = x;
    newToolTipStyle.top = y;
}

function CloseNewDiv(objAnchor) {
    document.getElementById('NewToolTip').style.display = 'none';
}

function OpenInstructionDiv() {
    var instructTooltipStyle = document.getElementById('InstructionTooltip').style;
    instructTooltipStyle.position = 'absolute';
    instructTooltipStyle.top = (document.documentElement.scrollTop + event.clientY + 4) + "px";
    instructTooltipStyle.left = document.documentElement.scrollLeft + event.clientX - 20;
    instructTooltipStyle.display = 'block';    
}

function CloseInstructionDiv(objAnchor) {
    document.getElementById('InstructionTooltip').style.display = 'none';
    document.getElementById(objAnchor).style.color = '#CACACA';
}
function WhatsThisChangeColor(objAnchor) {
    document.getElementById(objAnchor).style.color = 'white';
}

function RemoveDefaultText(objTextBox) 
{
    hiddenSearchClick = objTextBox
    var hdnSrchForTextClicked = document.getElementById('hiddenSearchForTextClicked');
        
    //alert(hdnSrchForTextClicked.value);
    if (hdnSrchForTextClicked.value != '1') 
    {        
        var objTxtBoxAttribs = document.getElementById(objTextBox);
        objTxtBoxAttribs.value = '';
        hdnSrchForTextClicked.value = '1';
        objTxtBoxAttribs = document.getElementById(objTextBox).attributes;
        var mouseClickClass = 'BlackColorContents';
        objTxtBoxAttribs.removeNamedItem('class');
        objTxtBoxAttribs.setNamedItem(MakeAttribute('class', mouseClickClass));
    }
    return true;
}
   
function TitleHyperlink(id)
{
    document.getElementById(id).style.color='#0066CC';
}

function TitleHyper(id)
{
    document.getElementById(id).style.color='#000000';
}

var hiddenSearchClick;
var radioButtonType = '';

function RadioButtonValue(identifier)
{
    radioButtonType = identifier;
    //alert(radioButtonType);
    if(identifier == "C"){
        document.getElementsByName('MainSearch$hiddenRadioButtonValue').value = 'C';
        radioButtonType ='C';
        }
    else{
        document.getElementsByName('MainSearch$hiddenRadioButtonValue').value = 'T';        
        radioButtonType='T';
    }
}

function MatchSet(match, result) 
{   
    if (document.getElementById(match).checked == true) 
    {     
        document.getElementById(result).disabled = true; 
        //document.getElementById(result).checked = false;       
    }
    else 
    {         
        document.getElementById(result).disabled = false;        
        //document.getElementById(result).checked = false;       
    }
}

function ResultSet(result, match) 
{
    if (document.getElementById(result).checked == true) 
    {   
        document.getElementById(match).disabled = true;
        //document.getElementById(match).checked = false;
    }
    else 
    {    
        document.getElementById(match).disabled = false;
        //document.getElementById(match).checked = false;
        
    }
}

function OnmouseoverRegisterClass(id) 
{    
    elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'RegisterForClassRollover';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseoutRegisterClass(id) 
{    
    elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'RegisterForClassNormal';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnclickRegisterClass(id) 
{
    elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'RegisterForClassPressed';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));    
}

function OpenLegend() 
{
    x = event.clientX + document.documentElement.scrollLeft;
    y = event.clientY + document.documentElement.scrollTop + 5;
    Popup.style.display = "block";
    Popup.style.position = "absolute";
    Popup.style.left = x;
    Popup.style.top = y;
    
}



function CloseLegend()
{
    Popup.style.display = "none";
}

function OnmouseoverViewAllClass(id) 
{
    elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'AllClassDateTimeRollOver';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseoutViewAllClass(id) 
{
    elemAttribs = document.getElementById(id).attributes;
    var mouseOverClass = 'AllClassDateTimeNormal';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));
}

function OnmouseClickViewAllClass(id) 
{
    elemAttribs = document.getElementById(id).attributes;    
    var mouseOverClass = 'AllClassDateTimePressed';
    elemAttribs.removeNamedItem('class');
    elemAttribs.setNamedItem(MakeAttribute('class', mouseOverClass));    
}

function CheckSoftwareAssurance(id)
{
    var id = document.getElementById(id);
    if(id.checked == true)
    {
        id.checked = false;
    }
    else if (id.checked == false)
    {
        id.checked = true;
    }
}

function CheckExactResults(exact, all)
{
    var exactId = document.getElementById(exact);
    var allId = document.getElementById(all);

    if(exactId.checked == true)
    {
        //alert(1);
        exactId.checked = false;
        allId.disabled = false;
    }  
    else if(exactId.checked == false && exactId.disabled == false)
    {
        //alert(2);
        exactId.checked = true;
        allId.disabled = true;
    }
}

function CheckAllResults(exact, all)
{
    var exactId = document.getElementById(exact);
    var allId = document.getElementById(all);
    
    if(allId.checked == true)
    {
        //alert(3);
        allId.checked = false;
        exactId.disabled = false;
    }
    else if(allId.checked == false && allId.disabled == false)
    {
        //alert(4);
        allId.checked = true;
        exactId.disabled = true;
    }
}

function OnMouseoverSendThisPage(id)
{
    var idpage = document.getElementById(id);
    idpage.style.textDecoration = "underline";
}

function OnMouseoutSendThisPage(id)
{
    var idpage = document.getElementById(id);
    idpage.style.textDecoration = "none";
}

function WebTrendsCall(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14) {

    wtReportEvent();
    WT.dl = '1';
    if (s5 != null) {
        dcsMultiTrack(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14);
                 //alert(s1); alert(s2); alert(s3); alert(s4);
                 //alert(s5); alert(s6); alert(s7); alert(s8); alert(s9); alert(s10);
                 //alert(s11); alert(s12); alert(s13); alert(s14);
    }
    else {
         //alert(s1); alert(s2); alert(s3); alert(s4);
        dcsMultiTrack(s1, s2, s3, s4);
    }

}

/*******************************************************************************************
**************Code Added today for clearing parameters**************************************
*******************************************************************************************/
// code added for clearing 
function wtReportEvent() {
    // DCS.dcsuri = ''
WT.ti = WT.oss = WT.oss_r = DCSext.cpls_satv = DCSext.cpls_location = DCSext.cpls_searchtype = DCSext.cpls_coursetrain = DCSext.cpls_fromdate = DCSext.cpls_todate = DCSext.cpls_deliveryformat = DCSext.cpls_language = DCSext.cpls_proximity = DCSext.cpls_msprodtechnology1 = DCSext.cpls_msprodtechnology2 = DCSext.cpls_msprodtechnology3 = DCSext.cpls_goldcert = DCSext.cpls_searchcoursenum = DCSext.cpls_searchopt = DCSext.cpls_sortby = DCSext.cpls_proximitychange = DCSext.cpls_partner_id = DCSext.cpls_linktype = DCSext.cpls_courseid = DCSext.cpls_startdate = DCSext.cpls_lang = DCSext.cpls_audience = '';
    //DCSext = new Object(); //not sure what this does exactly.
    //dcsMultiTrack(arguments); //we might want to remove this part from the function. Then, we could call wtReportEvent() when a link is clicked (just to clear params) then immediately fire the multiTrack as we do now.
}

/*******************************************************************************************
**************Code Added today for clearing parameters**************************************
*******************************************************************************************/