﻿// JScript File
var myHttpRequest = false;
var txtFullNameID;

if(window.XMLHttpRequest)
     myHttpRequest = new XMLHttpRequest();
else if(window.ActiveXObject)
     myHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");

function loadContent(source, content)
{

    function pageLoaded() {
        if (Silverlight.supportedUserAgent()) {
            // silverlight is supported update any installers
            for (var i in Silverlight.installControls)
                Silverlight.installControls[i].update();
        }
        else {
            // silverlight is not supported, need to tell installers to report this
            for (var i in Silverlight.installControls)
                Silverlight.installControls[i].update(AgInstall.NOT_SUPPORTED);
        }
    }

      
    var topic = gup(location.href);
    var search = location.search;
    var replace;

 
     if(myHttpRequest)
     {
         var data = document.getElementById(content);

          myHttpRequest.open("GET",source);

          myHttpRequest.onreadystatechange = function() {
          if (myHttpRequest.readyState == 4) {
                  data.innerHTML = myHttpRequest.responseText;
              }
          }

          myHttpRequest.send(null);
     }
} 

function gup( name )
{  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var tmpURL = location.href;  
    var results = regex.exec( tmpURL );  
    if( results == null )    
        return "";  
    else    
    return results[1];
}

imgout=new Image(9,9);
imgin=new Image(9,9);

/////////////////BEGIN USER EDITABLE///////////////////////////////
	imgout.src="../../Images/u.gif";
	imgin.src="../../Images/d.gif";
///////////////END USER EDITABLE///////////////////////////////////

//this switches expand collapse icons
function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=eval(objectsrc+".src");
	}
}

//show OR hide funtion depends on if element is shown or hidden
function shoh(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
	
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
			filter(("img"+id),'imgin');			
		} else {
			filter(("img"+id),'imgout');
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
	
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				filter(("img"+id),'imgin');
			} else {
				filter(("img"+id),'imgout');	
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				filter(("img"+id),'imgout');
				document.all.id.style.display = 'none';
			}
		}
	}
}

function ValidateUploadForm()
{

    var ValidF = false;
    var txtFullName = document.getElementById(gettxtFullNameId());
    var txtEmailAddress = document.getElementById(gettxtEmailAddressId());
    var cboStaff = document.getElementById(getcboStaffId());
    var ulFile = document.getElementById(getFileId());
    var btnUpload = document.getElementById(getbtnUploadId());

    //alert(cboStaff.value);

    if (txtFullName.value != '' && txtEmailAddress.value != '' && cboStaff.value != 'Please select recipient')
        ValidF = true;
    else
        ValidF = false;
 
    if (ValidF == true)
        btnUpload.disabled = false;
    else
        btnUpload.disabled = true;

}

function open_it_window()
{
    window.open('http://www.itexpertise.com.au');
}


function onSilverlightError(sender, args) {
        
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            } 
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;
            
            var errMsg = "Unhandled Error in Silverlight 2 Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError")
            {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError")
            {           
                if (args.lineNumber != 0)
                {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }

function makevisible() {

    var d = document.getElementById("silverlightControlHost");

    d.style.visibility = "visible";

}

var slCtl = null;
function pluginLoaded(sender) {    // ASPX version
    slCtl = sender.get_element();
    //alert(slCtl.Content.postit.LoadPostItText);
}

function load_postit() {

    //silverlightControl = document.getElementById("ctl00_Post_It_App");
    
    //alert(silverlightControl);
    //silverlightControl.Content.postit.LoadPostItText();
    //slCtl.Content.postit.Reload();
    //slCtl.Content.postit.LoadPostItText();
    slCtl.Source = slCtl.Source;
    //alert(slCtl.Source);
}

//function Resize(height, width) {
//    silverlightControl = document.getElementById("slSlogan");
//    alert(silverlightControl.style.height);
//    silverlightControl.height = height + "px";
//    silverlightControl.width = width + "px";

//}

function CheckForSilverligh(content) {

    function pageLoaded() {
        if (Silverlight.supportedUserAgent()) {
            // silverlight is supported update any installers
            for (var i in Silverlight.installControls)
                Silverlight.installControls[i].update();
        }
        else {
            // silverlight is not supported, need to tell installers to report this
            for (var i in Silverlight.installControls)
                Silverlight.installControls[i].update(AgInstall.NOT_SUPPORTED);
        }
    }

    var topic = gup(location.href);
    var search = location.search;
    var replace;


    if (myHttpRequest) {
        var data = document.getElementById("frame");

        myHttpRequest.open("GET", '/silverlight.htm');

        myHttpRequest.onreadystatechange = function() {
            if (myHttpRequest.readyState == 4) {
                data.innerHTML = myHttpRequest.responseText;
            }
        }

        myHttpRequest.send(null);
    }
}
function OpenPDF(filePath, title) {

    globalHTML = "<html><head><title>" + title + "</title></head>"
+ "<frameset rows='100%,*'><frame src='" + filePath + "'></frame>"
+ "</frameset></html>";
    window.open("javascript:opener.globalHTML");

}


function GetPath() {
    return location.href;
}

function doHourglass(sender, args) {
    document.body.style.cursor = 'wait';
    document.getElementById('btnUpload').disabled = true;
}

function timeout(code) {
    //alert(code);
    window.setTimeout(code, 200);
}
