﻿// JScript File

//  Pop-up window script
var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
    var centerWidth = (window.screen.width - width) / 2;
    var centerHeight = (window.screen.height - height) / 2;

    if(popUpWin)
    {
        if(!popUpWin.closed) popUpWin.close();
    }
    
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbar=0,resizable=0,copyhistory=1,width='+width+',height='+height+',left='+centerWidth+', top='+centerHeight+',screenX='+centerWidth+',screenY='+centerHeight+'');
}

function popUpWindowWithResize(URLStr, width, height)
{
    var centerWidth = (window.screen.width - width) / 2;
    var centerHeight = (window.screen.height - height) / 2;

    if(popUpWin)
    {
        if(!popUpWin.closed) popUpWin.close();
    }
    
    popUpWin = open(URLStr, 'popUpWinResize', 'scrollbar=1,menubar=0,statusbar=0,resizable=1,width='+width+',height='+height+',left='+centerWidth+', top='+centerHeight+',screenX='+centerWidth+',screenY='+centerHeight+'');
}

function popUpWindowWithResizewithScroll(URLStr, width, height)
{

    var windowWidth =document.body.clientWidth;
    
    var windowHeight =document.body.clientHeight;
    
    var centerWidth = (window.screen.width - width) / 2;
    var centerHeight = (window.screen.height - height) / 2;

    if(popUpWin)
    {
        if(!popUpWin.closed) popUpWin.close();
    }
    
    popUpWin = open(URLStr, 'popUpWin', 'width='+width+',height='+height+',left='+centerWidth+', top='+centerHeight+',screenX='+centerWidth+',screenY='+centerHeight+'');
}

function Get85PercentWindow (URLStr)
{
    var mywidth=0;
    var myheight=0;
    
    if (typeof(window.innerWidth) == 'number')
    {    
        mywidth = window.innerWidth;
        myheight = window.innerHeight;
    }
    else if (document.DocumentElement && (document.DocumentElement.clientWidth || document.DocumentElement.clientHeight))
    {
        mywidth = document.DocumentElement.clientWidth;
        myheight = document.DocumentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        mywidth = document.body.clientWidth;
        myheight = document.body.clientHeight;
    }       

    alert (mywidth + ', ' + myheight);
    
    var width = 0.85 * mywidth;
    var height = 0.85 * myheight;
    
    alert (width + ', ' + height);
    
    var centerWidth = (window.screen.width - width) / 2;
    var centerHeight = (window.screen.height - height) / 2;       
    
    if(popUpWin)
    {
        if(!popUpWin.closed) popUpWin.close();
    }
    
    alert ('width='+width+',height='+height+',left='+centerWidth+', top='+centerHeight+',screenX='+centerWidth+',screenY='+centerHeight+',scrollbar=yes,menubar=no,statusbar=no,resizable=yes');
    
    popUpWin = open(URLStr, 'popUpWin', 'width='+width+',height='+height+',left='+centerWidth+', top='+centerHeight+',screenX='+centerWidth+',screenY='+centerHeight+',scrollbar=yes,menubar=no,statusbar=no,resizable=yes');
}

//  Pop-up window script ends here

//  Script for Header Images
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.Images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//  Script for Header images ends here

//  Script for Delete

//  Code for Hide Div
function hideDiv()
{				
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById("Div2").style.display = 'none';
		document.getElementById("Div3").style.display = 'none';
	}
}

//  Code for show Div
function openDiv()
{
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById("Div2").style.display = 'block';
		document.getElementById("dvMain").style.display = 'none';
		document.getElementById("Div3").style.display = 'none';
	}
}

//	Code for Delete
var f = false;

function XMLHTTPObject()
{
	var xmlhttp;
	if(window.ActiveXObject)
	{
		// Instantiate the latest Microsoft ActiveX Objects
		if(_XML_ActiveX)
		{
			xmlhttp = new ActiveXObject(_XML_ActiveX);
		}
		else
		{
			// loops through the various versions of XMLHTTP to ensure we're using the latest
			var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];
			for(var i = 0; i < versions.length ; i++)
			{
				try
				{
					// Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
					xmlhttp = new ActiveXObject(versions[i]);
					if(xmlhttp)
					{
						var _XML_ActiveX = versions[i];
						break;
					}
				}
				catch (e)
				{
					alert("Exception : "+e);
				};
			};
		}
	} // Well if there is no ActiveXObject available it must be firefox, opera, or something else
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			alert("Exception : "+xmlhttp);
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

var http = XMLHTTPObject(); // Create the XMLHttpRequest Object.

function Response()
{
	if(http.readyState == 4)
	{
		if(http.status == 200)
		{
			if(f)
			{
				f=false;
			}
			strResult = http.responseText;
			
			opener.window.location.reload();
			self.close();
			/*
			document.getElementById('divProjects').innerHTML = strResult;
			document.getElementById('divProjects').style.display="";
			document.getElementById('divProjects').style.visibility="visible";
			*/
		}
		else
		{
			var results = "Sorry, there was an error finding the server-side file. Please contact support.";
			f=false;
			alert(results);
		}
	}
}
function project_detail(nProject, userName)
{				
	if(!f && http)
	{
		var url = "confirmDelete.aspx?ID="+nProject+"&user="+userName+"&ms=" + new Date().getTime();
		
		http.open("GET", url, false);
		http.onreadystatechange = Response;
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.send(null);
	}
}

function project_detail_Cancel(nProject, status, parentID, userName)
{				
	if(!f && http)
	{
		var url = "confirmDelete.aspx?ID="+nProject+"&CreditStatus="+status+"&parent="+parentID+"&user="+userName+"&ms=" + new Date().getTime();
		//alert (url + " " + document.frmMain.method);
		http.open("GET", url, false);
		http.onreadystatechange = Response;
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.send(null);
	}
}			
//  End Script for Delete

//  Script for Print
function CallPrint()
{			
    window.print();
}
//  End script for Print

//  Check Speed Code
    
// Written by Martin Krolik (martin@krolik.net)
// You may want to use a much larger file size (3 to 4 MB) to more
// accurately test FASTER networks.

var iFileSize = 268945; // size of image (SpeedTest.gif) in bytes
var objImage = new Image();
objImage.onload = StopWatch;
var objDate = new Date();
var objStartTime = objDate.getTime();
var objStopTime = objDate.getTime();
var objTimerHandle = 0;
var iIterations = 0;

function Working()
{
    document.form1.SpeedTestHiddenField.value = document.form1.SpeedTestHiddenField.value + ".";
    iIterations++;
    
    if (iIterations < 3600)
    {
        objTimerHandle = setTimeout("Working();", 500);
    }  
    else 
    {
        document.form1.SpeedTestHiddenField.value = document.form1.SpeedTestHiddenField.value + "\nERROR:  Either the test 'load test' file could not be found, or your network is too slow or not functioning properly. (Took more than 30 minutes to complete.)";
    }
}

function StartWatch()
{
    document.form1.SpeedTestHiddenField.value = "Testing in progress  ..."
    objDate = new Date()
    objStartTime = objDate.getTime();
    objImage.src = "Images/SpeedTest.gif?Epoch=" + objStartTime ;
    objTimerHandle = setTimeout("Working();", 500);
}

function StopWatch()
{
    objDate = new Date()
    objStopTime = objDate.getTime();
    
    if (objTimerHandle) 
    {
        clearTimeout(objTimerHandle);
        objTimerHandle=0;
    }
    
    var iDuration = (objStopTime - objStartTime) / 1000;  // the number of seconds it took
    var iThroughPut = (iFileSize / iDuration) / 1024;
    var iThroughPutBits = ((iFileSize * 8) / iDuration) / 1024;
    iThroughPut = (Math.round(iThroughPut * 100)) / 100
    iThroughPutBits = (Math.round(iThroughPutBits * 100)) / 100
    document.form1.SpeedTestHiddenField.value = document.form1.SpeedTestHiddenField.value + "\nTest completed.";
    document.form1.SpeedTestHiddenField.value = document.form1.SpeedTestHiddenField.value + "\nNetwork throughput is " + iThroughPut + " kilobytes per second. \n(" + iThroughPutBits + " kilobits per second)";
    document.form1.SpeedTestHiddenField.value = iThroughPut;
    iIterations = 0;
}
//  End Check Speed Code

//  Code for Refresh Window
function refreshParent() 
{
    window.opener.location.href = window.opener.location.href;

    if (window.opener.progressWindow)
    {
        window.opener.progressWindow.close()
    }
    
    window.close();
}
//  End Code for Refresh Window

var win=null;
    function NewWindow(mypage,myname,scroll,pos, width, height){
    
    var myWidth=0;
    var myHeight=0;
    
    if( typeof( window.innerWidth ) == 'number' ) {
        
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        
        
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        
        
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
                
      }  

    /*var width = 0.95 * myWidth;
    var height = 0.95 * myHeight;*/
    
	if(pos=='random'){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-width)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-height)-75)):100;}
    if(pos=='center'){LeftPosition=(screen.width)?(screen.width-width)/2:100;TopPosition=(screen.height)?(screen.height-height)/2:100;}
    else if((pos!='center' && pos!='random') || pos==null){LeftPosition=0;TopPosition=20}
    settings='width='+width+',height='+height+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
    win=window.open(mypage,myname,settings);}