﻿// <!CDATA[
        // (c) Copyright Microsoft Corporation.
        // This source is subject to the Microsoft Permissive License.
        // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
        // All other rights reserved.
    
        // Script objects that should be loaded before we run
        var typeDependencies = ['AjaxControlToolkit.DropShadowBehavior'];
    
        // Test Harness
        var testHarness;

        // Controls and behaviors
        var panel;
        var behavior;

        // Variables
        var panelBounds;

        // Helper functions

        function CheckShadowBounds(rounded) {
            return function() {
                var shadowWidth = behavior.get_Width();
                var shadowDiv = behavior._shadowDiv;
                if (0 < shadowWidth && shadowDiv) {
                    var shadowBounds = CommonToolkitScripts.getBounds(shadowDiv);
                    testHarness.assertEqual(shadowBounds.x, panelBounds.x + shadowWidth, 'Unexpected shadow x = ' + (panelBounds.x + shadowWidth) + ' (expected ' + shadowBounds.x + ')');
                    testHarness.assertEqual(shadowBounds.y, panelBounds.y + shadowWidth, 'Unexpected shadow y = ' + (panelBounds.y + shadowWidth) + ' (expected ' + shadowBounds.y + ')');
                    testHarness.assertEqual(shadowBounds.width, panelBounds.width, 'Unexpected shadow width = ' + panelBounds.width + ' (expected ' + shadowBounds.width + ')');
                    if (rounded) {
                        testHarness.assertTrue(panelBounds.height < shadowBounds.height, 'Unexpected shadow height (' + panelBounds.height + " > " + shadowBounds.height + ")" );
                    } else {
                        testHarness.assertEqual(shadowBounds.height, panelBounds.height, 'Unexpected shadow height (' + panelBounds.height + " != " + shadowBounds.height + ")");
                    }
                    testHarness.assertTrue(shadowDiv.style.zIndex < panel.style.zIndex, 'Unexpected zIndex');
                }
            };
        }

        function CheckOpacity(val) {
            return function() {
                testHarness.assertEqual(val, behavior.get_Opacity(), 'Unexpected opacity');
            }
        }
        
        function CheckInitialPosition() {
            panelBounds = CommonToolkitScripts.getBounds(panel);
            testHarness.assertTrue((0 < panelBounds.x) && (0 < panelBounds.y), 'Unexpected panel location = ' + panelBounds.x + ',' + panelBounds.y + ' (expected greater than 0,0)');
        }

        // Register the tests
        function registerTests(harness) {
            testHarness = harness;

            panel = testHarness.getElement('ctl00_ContentPlaceHolder1_Panel1');
            behavior = testHarness.getObject('DropShadowProperties1');

            var test = testHarness.addTest('Initial position');
            test.addStep(CheckInitialPosition);

            test = testHarness.addTest('Initial state');
            test.addStep(CheckInitialPosition);
            test.addStep(CheckShadowBounds(false));
            test.addStep(CheckOpacity(1.0));

            test = testHarness.addTest('Changing Width');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Width(behavior.get_Width() + 5); });
            test.addStep(CheckShadowBounds(false));
            test.addStep(function() { behavior.set_Width(0); });
            test.addStep(CheckShadowBounds(false));
            test.addStep(function() { behavior.set_Width(8); });
            test.addStep(CheckShadowBounds(false));

            test = testHarness.addTest('Changing Opacity');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Opacity(0.4); });
            test.addStep(CheckOpacity(0.4));
            test.addStep(CheckShadowBounds(false));

            test = testHarness.addTest('Rounded');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Rounded(true); });
            test.addStep(CheckShadowBounds(true));

            test = testHarness.addTest('Changing Rounded Width');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Rounded(true); });
            test.addStep(function() { behavior.set_Width(behavior.get_Width() + 5); });
            test.addStep(CheckShadowBounds(true));
            test.addStep(function() { behavior.set_Width(0); });
            test.addStep(CheckShadowBounds(true));
            test.addStep(function() { behavior.set_Width(8); });
            test.addStep(CheckShadowBounds(true));

            test = testHarness.addTest('Changing Rounded Radius');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Rounded(true); });
            test.addStep(function() { behavior.set_Radius(behavior.get_Radius() + 5); });
            test.addStep(CheckShadowBounds(true));
            test.addStep(function() { behavior.set_Radius(0); });
            test.addStep(CheckShadowBounds(false));  // false because radius of 0 is effectively unrounded
            test.addStep(function() { behavior.set_Radius(8); });
            test.addStep(CheckShadowBounds(true));

            test = testHarness.addTest('Unrounded');
            test.addStep(CheckInitialPosition);
            test.addStep(function() { behavior.set_Rounded(true); });
            test.addStep(function() { behavior.set_Rounded(false); });
            test.addStep(CheckShadowBounds(false));

            test = testHarness.addTest('Panel movement');
            test.addStep(CheckInitialPosition);
            test.addStep(function() {
                    panel.style.left = '150px';
                    panelBounds = CommonToolkitScripts.getBounds(panel);
                    behavior.set_TrackPosition(true);
                    behavior.set_TrackPositionDelay(25);
                },
                function() {  try { CheckShadowBounds(false); return true; } catch (ex) { return false; }  },
                200, 5000);
            
            test = testHarness.addTest('Panel shrink');
            test.addStep(CheckInitialPosition);
            test.addStep(function() {
                    panel.style.left = '150px';
                    panelBounds = CommonToolkitScripts.getBounds(panel);
                    behavior.set_TrackPosition(true);
                    behavior.set_TrackPositionDelay(25);
                },
                function() {  try { CheckShadowBounds(false); return true; } catch (ex) { return false; }  },
                200, 5000);
            test.addStep(function() {
                    testHarness.getElement('MoreText').style.display = 'none';
                    panelBounds = CommonToolkitScripts.getBounds(panel);
                },
                function() {  try { CheckShadowBounds(false); return true; } catch (ex) { return false; }  },
                200, 5000);
        }
        
        // (c) Copyright Microsoft Corporation.
        // This source is subject to the Microsoft Permissive License.
        // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
        // All other rights reserved.

        // Script objects that should be loaded before we run
        var typeDependencies = ['AjaxControlToolkit.TextBoxWatermarkBehavior'];

        // Test Harness
        var testHarness = null;

        // Controls in the page
        var tb1 = null;
        var tb2 = null;
        var tbb1 = null;
        var btn = null;
        var lbl = null;

        // Variables
        var watermarkText = 'watermark';
        var watermarkCssClass = 'watermarked';

        // Ensure the textbox is in its empty state
        function checkEmptyState() {
            testHarness.assertEqual(watermarkCssClass, tb1.className, "TextBox1's class name should be '" + watermarkCssClass + "' instead of '" + tb1.className + "'");
            testHarness.assertEqual(watermarkText, tb1.value, "TextBox1's value should be '" + watermarkText + "' instead of '" + tb1.value + "'");
            testHarness.assertEqual('', tbb1.get_Text(), "TextBox1's behavior text should be '' instead of '" + tbb1.get_Text() + "'");
        }

        // Ensure the textbox is in its full state
        function checkFullState() {
            testHarness.assertEqual('unwatermarked', tb1.className, "TextBox1's class name should be 'unwatermarked' instead of '" + tb1.className + "'");
            testHarness.assertEqual('full', tb1.value, "TextBox1's value should be 'full' instead of '" + tb1.value + "'");
            testHarness.assertEqual('full', tbb1.get_Text(), "TextBox1's behavior text should be 'full' instead of '" + tbb1.get_Text() + "'");
        }

        // Ensure the label has the right text
        function checkLabelContents(text) {
            testHarness.assertEqual(text, lbl.innerHTML, "Label should be '"+text+"' instead of '"+lbl.innerHTML+"'.");
        }

        // Test the initial state of the control
        function testInitialState() {
            checkEmptyState();
            checkLabelContents(":Label:");
        }

        // Test focusing the control
        function testFocus() {
            testHarness.fireEvent(tb1, 'onfocus');
            testHarness.assertEqual('unwatermarked', tb1.className, "TextBox1's class name should be 'unwatermarked' instead of '" + tb1.className + "'");
            testHarness.assertEqual('', tb1.value, "TextBox1's value should be empty instead of '" + tb1.value + "'");
        }

        // Test removing focus from the control
        function testEmptyBlur() {
            testHarness.fireEvent(tb1, 'onblur');
            checkEmptyState();
        }

        // Test removing focus from a filled control
        function testFullBlur() {
            testHarness.fireEvent(tb1, 'onfocus');
            tb1.value = 'full';
            testHarness.fireEvent(tb1, 'onblur');
            checkFullState();
        }

        // Test removing focus from an empty control
        function testEmptiedBlur() {
            testHarness.fireEvent(tb1, 'onfocus');
            tb1.value = '';
            testHarness.fireEvent(tb1, 'onblur');
            checkEmptyState();
        }

        // Register the tests
        function registerTests(harness)
        {
            testHarness = harness;

            // Get the controls from the page
            tb1 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox1');
            tb2 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox2');
            tbb1 = testHarness.getObject('ctl00_ContentPlaceHolder1_TextBoxWatermarkExtender1');
            btn = testHarness.getElement('ctl00_ContentPlaceHolder1_Button1');
            lbl = testHarness.getElement('ctl00_ContentPlaceHolder1_Label1');

            var test = testHarness.addTest('Initial');
            test.addStep(testInitialState);
            
            test = testHarness.addTest('Focus');
            test.addStep(testInitialState);
            test.addStep(testFocus);
            
            test = testHarness.addTest('Empty Blur');
            test.addStep(testInitialState);
            test.addStep(testFocus);
            test.addStep(testEmptyBlur);
            
            test = testHarness.addTest('Full Blur');
            test.addStep(testInitialState);
            test.addStep(testFocus);
            test.addStep(testEmptyBlur);
            test.addStep(testFullBlur);
            
            test = testHarness.addTest('Emptied Blur');
            test.addStep(testInitialState);
            test.addStep(testFocus);
            test.addStep(testEmptyBlur);
            test.addStep(testEmptiedBlur);
            
            test = testHarness.addTest('Empty Submit');
            test.addStep(testEmptiedBlur);
            test.addPostBack(btn);
            test.addStep(checkEmptyState);
            test.addStep(function() { checkLabelContents("::"); });
            
            test = testHarness.addTest('Full Submit');
            test.addStep(testFullBlur);
            test.addPostBack(btn);
            test.addStep(checkFullState);
            test.addStep(function() { checkLabelContents(":full:"); });
            
            test = testHarness.addTest('Text set methods');
            test.addStep(checkEmptyState);
            test.addStep(function() { tbb1.set_Text("full"); });
            test.addStep(checkFullState);
            test.addStep(function() { tbb1.set_Text(""); });
            test.addStep(checkEmptyState);
            
            test = testHarness.addTest('MaxLength');
            test.addStep(function() { testHarness.assertEqual('watermark', tb2.value,
                "TextBox2's value should be 'watermark' instead of '" + tb2.value + "'");});
            
            test = testHarness.addTest('Text property changes');
            test.addStep(checkEmptyState);
            test.addStep(function() { watermarkText = 'watermark2'; });
            test.addStep(function() { tbb1.set_WatermarkText(watermarkText); });
            test.addStep(checkEmptyState);
            test.addStep(function() { watermarkCssClass = 'watermarked2'; });
            test.addStep(function() { tbb1.set_WatermarkCssClass(watermarkCssClass); });
            test.addStep(checkEmptyState);
        }
        
        // (c) Copyright Microsoft Corporation.
        // This source is subject to the Microsoft Permissive License.
        // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
        // All other rights reserved.
        
        // Script objects that should be loaded before we run
        var typeDependencies = ['AjaxControlToolkit.Animation.Animation', 'AjaxControlToolkit.Animation.AnimationBehavior'];
    
        // Test Harness
        var testHarness = null;

        // Controls in the test page
        var panel = null;
        var behavior = null;
        
        function waitChanged(attribute, value) {
            return function() {
                panel = testHarness.getElement('ctl00_ContentPlaceHolder1_target');
                var expected = panel.style[attribute];
                return (expected == value);
            };
        }
        
        function checkFired(attribute, value) {
            return function() {
                panel = testHarness.getElement('ctl00_ContentPlaceHolder1_target');
                var expected = panel.style[attribute];
                testHarness.assertEqual(expected, value, 'Event failed to fire');
            };
        }

        // Fire an onmouseover event at point (x,y)
        function mouseOver(element, x, y) {
            return function() {
                if (!testHarness.getDocument().createEvent) {
                    testHarness.cancel('This test can only be run on a browser that supports document.createEvent (such as Firefox)');
                    return;
                }
                var e = testHarness.getDocument().createEvent('MouseEvents');
                e.initMouseEvent('mouseover', true, false, window, 0, x, y, x, y, false, false, false, false, 0, null);
                element.dispatchEvent(e);
            };
        }
        
        // Fire an onmouseout event at point (x,y)
        function mouseOut(element, x, y) {
            return function() {
                if (!testHarness.getDocument().createEvent) {
                    testHarness.cancel('This test can only be run on a browser that supports document.createEvent (such as Firefox)');
                    return;
                }
                var e = testHarness.getDocument().createEvent('MouseEvents');
                e.initMouseEvent('mouseout', true, false, window, 0, x, y, x, y, false, false, false, false, 0, null);
                element.dispatchEvent(e);
            };
        }

        // Register the tests
        function registerTests(harness) {
            testHarness = harness;

            // Get the controls on the page
            panel = testHarness.getElement('ctl00_ContentPlaceHolder1_target');
            behavior = testHarness.getObject('ctl00_ContentPlaceHolder1_extender');
            
            var id = function() {};
            
            var test = testHarness.addTest('OnLoad');
            test.addStep(id, waitChanged('backgroundColor', 'red'), checkFired('backgroundColor', 'red'));
            
            test = testHarness.addTest('OnClick');
            test.addStep(id, waitChanged('backgroundColor', 'red'), checkFired('backgroundColor', 'red'));
            test.addStep(function() { panel.click(); }, waitChanged('backgroundColor', 'blue'), checkFired('backgroundColor', 'blue'));
            
            test = testHarness.addTest('Mouse Events');
            test.addStep(id, waitChanged('backgroundColor', 'red'), checkFired('backgroundColor', 'red'));
            test.addStep(mouseOver(panel, panel.offsetWidth + 20, panel.offsetHeight + 20), waitChanged('backgroundColor', 'blue'), checkFired('backgroundColor', 'blue'));
            test.addStep(mouseOut(panel, 0, 0), waitChanged('backgroundColor', 'green'), checkFired('backgroundColor', 'green'));
            test.addStep(mouseOver(panel, panel.offsetWidth + 20, panel.offsetHeight + 20), waitChanged('color', 'blue'), checkFired('color', 'blue'));
            test.addStep(mouseOut(panel, 0, 0), waitChanged('color', 'yellow'), checkFired('color', 'yellow'));
        }
        
function FireEvent(el, ev)
{
    if (document.createEventObject) 
    {
        el.fireEvent(ev);
    } 
    else if (document.createEvent) 
    {
        var localE = document.createEvent("HTMLEvents");
        localE.initEvent(ev.substring(2, ev.length), true, true);
        el.dispatchEvent(localE);        
    }    
}

function ClearQuoteScreen()
{
    //var spanHint=document.getElementById("txtHint");
    //spanHint.innerHTML=...;
    
    document.getElementById("ctl00$Contents$txtFirstName").value = ""; 
    document.getElementById("ctl00$Contents$txtFirstName").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtSurName").value = ""; 
    document.getElementById("ctl00$Contents$txtSurName").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtAddressLineOne").value = ""; 
    document.getElementById("ctl00$Contents$txtAddressLineOne").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtAddressLineTwo").value = ""; 
    document.getElementById("ctl00$Contents$txtAddressLineTwo").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtAddressPostCode").value = ""; 
    document.getElementById("ctl00$Contents$txtAddressPostCode").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtMobileNumber").value = ""; 
    document.getElementById("ctl00$Contents$txtMobileNumber").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtHomeNumber").value = ""; 
    document.getElementById("ctl00$Contents$txtHomeNumber").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtEmailAddress").value = ""; 
    document.getElementById("ctl00$Contents$txtEmailAddress").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtNationality").value = ""; 
    document.getElementById("ctl00$Contents$txtNationality").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtRate").value = ""; 
    document.getElementById("ctl00$Contents$txtRate").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtTimeFrame").value = ""; 
    document.getElementById("ctl00$Contents$txtTimeFrame").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtTravel").value = "";
    document.getElementById("ctl00$Contents$txtTravel").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtFood").value = "";
    document.getElementById("ctl00$Contents$txtFood").fireEvent('onchange');
    
    document.getElementById("ctl00$Contents$txtNotes").value = "";    
    document.getElementById("ctl00$Contents$txtNotes").fireEvent('onchange');
}

function AddTotalExpenses()
{    
    var Res1=0.0;
    var Res2=0.0;
    var Res3=0.0;
    var Res=0.0;
    var temp="";
    
    if (document.getElementById("ctl00$Contents$txtSubsistenceCost").value == "")
    {
        Res1 = 0.0;
    }
    else
    {
        temp = document.getElementById("ctl00$Contents$txtSubsistenceCost").value;
        Res1 = eval(temp);
    }
    
    if (document.getElementById("ctl00$Contents$txtTravelCost").value == "")
    {
        Res2 = 0.0;
    } 
    else
    {
        temp = document.getElementById("ctl00$Contents$txtTravelCost").value;
        Res2 = eval(temp);
    } 
    
    if (document.getElementById("ctl00$Contents$txtOtherCost").value == "")
    {
        Res3 = 0.0;
    } 
    else
    {
        temp = document.getElementById("ctl00$Contents$txtOtherCost").value;
        Res3 = eval(temp);
    } 
    
    Res = Res1 + Res2 + Res3;
    
    document.getElementById("ctl00$Contents$txtTotExpenses").value = Res;
    document.getElementById("ctl00$Contents$txtTotExpenses").fireEvent('onchange');
    
}

function changeRateDays()
{
    var IndexValue = document.getElementById("ctl00$Contents$ddlRateType").value;
  
	if(IndexValue==1)
	{
		document.getElementById("ctl00$Contents$ddlTimeFrame").selectedIndex = 1;
		document.getElementById("ctl00$Contents$txtTimeFrame").value = "5";		
		document.getElementById("ctl00$Contents$txtTimeFrame").fireEvent('onchange');
	}
	else if(IndexValue==0)
	{
		document.getElementById("ctl00$Contents$ddlTimeFrame").selectedIndex = 0;
	}
	document.getElementById("ctl00$Contents$ddlTimeFrame").fireEvent('onchange');
	
}

function changeCalcRateDays()
{
    var IndexValue = document.getElementById("ctl00$Contents$ddlRateType").value;
  
	if(IndexValue==1)
	{
		document.getElementById("ctl00$Contents$ddlTimeFrame").selectedIndex = 1;
		document.getElementById("ctl00$Contents$txtTimeFrame").value = "5";		
		document.getElementById("ctl00$Contents$txtTimeFrame").fireEvent('onchange');
	}
	else if(IndexValue==0)
	{
		document.getElementById("ctl00$Contents$ddlTimeFrame").selectedIndex = 0;
	}
	document.getElementById("ctl00$Contents$ddlTimeFrame").fireEvent('onchange');
	
}

function changeFoodDurationType()
{
    var IndexValue = document.getElementById("ctl00$Contents$ddlTravelDurationType").value;
  
	if(IndexValue==1)
	{
		document.getElementById("ctl00$Contents$ddlFoodDurationType").selectedIndex = 1;
	}
	else if(IndexValue==0)
	{
		document.getElementById("ctl00$Contents$ddlFoodDurationType").selectedIndex = 0;
	}
	document.getElementById("ctl00$Contents$ddlFoodDurationType").fireEvent('onchange');
}
    
function CheckEven(source, args) {
    var val = parseInt(args.Value, 10);
    if (isNaN(val)) {
        args.IsValid = false;
    }
    else {
        args.IsValid = ((val % 2) == 0);
    }
}

function validateDate(source, args)
{
  var iDay, iMonth, iYear;
  var arrValues;
  arrValues = args.Value.split("/");
  iDay = arrValues[0];
  iMonth = arrValues[1];
  iYear = arrValues[2];

  var testDate = new Date(iYear, iMonth - 1, iDay);
  if ((testDate.getDate() != iDay) ||
      (testDate.getMonth() != iMonth - 1) ||
      (testDate.getFullYear() != iYear))
  {
     args.IsValid = false;
     return;
  }
      
  return true;
}

function CheckGreaterThanZero(source, args)
{
    var val = parseInt(args.Value, 10);
    if (isNaN(val)) 
    {
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = (val > 0);
    }
}

var ajaxRequest;

function initAJAX()
{
    try
    {
        ajaxRequest = new XMLHttpRequest();        
    }
    catch(error)
    {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
}

// ]]>