//size full screen						
var winX = 0;
var winY = 0;
var winWidth = screen.availWidth;
var winHeight = screen.availHeight;			


//Size to 1024x768 centered if at higher resolution
if (screen.availWidth >= 1024 & screen.availHeight >= 768)
{
	winWidth = 1024;
	winHeight = 768;
	winX = (screen.availWidth-1024)/2;
	winY = (screen.availHeight-768)/2;
}

//Move window
//window.moveTo(winX,winY);

//Size window
//window.resizeTo(winWidth, winHeight);	



var strLocation = window.location.href;

//Parse Quesry String into Array
    
    function parseQueryString(pArray) 
    {
        var query = window.location.search.substring(1);
        var parms = query.split('&');
        for (var i=0; i<parms.length; i++) {
            var pos = parms[i].indexOf('=');
            if (pos > 0) 
            {
                var key = parms[i].substring(0,pos);
                var val = parms[i].substring(pos+1);
                pArray[key] = val;
            }
        }
    } 	

//============================================================
// Confirm delete
//============================================================
	function GlobalConfirmDelete()
	{
		if (!confirm("Are you sure you want to delete this?"))
		{
			return false;
		}
	}
		
//============================================================
// Global confirm send
//============================================================
	function GlobalConfirmSend()
	{
		if (!confirm("Are you sure you want to send?"))
		{
			return false;
		}
	}	
	
		
//============================================================
// Show saving annimation
//============================================================
	function showSaveGraphic()
	{
	    document.getElementById("PageSaving").style.zIndex = 100000;
		document.getElementById("PageSaving").style.visibility = 'visible';
		//Hide all selects
		igcmbo_dropDowns = document.all.tags("SELECT");
		for (i=0; i<igcmbo_dropDowns.length;i++)
		{
			igcmbo_dropDowns[i].style.visibility='hidden';		
		}		
	}


//============================================================
// CLOSE WINDOW
//============================================================
  function CloseWin()
	{
	window.opener = self;
	window.close();
	}

//============================================================
// GoBack
//============================================================
 function GoBack()
 	{
        window.history.go(-1)
	}

//============================================================
// SET FOCUS
//============================================================
function init()
	{
	//	if (document.forms[0]["txt_UserID"] != null)
			document.forms[0][txt_UserID].focus();
	//		document.Form1..focus();			
	}
	

//============================
// PUSHBUTTON - DELETE        
//============================
function PB_Delete()
		{
		agree=confirm("THIS ACTION WILL DELETE THIS ITEM!")
		if (agree)
			window.location.href="Default.asp";
		}

//============================================================
// POPUP
//============================================================
 function PopUp(pScreen)
   	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.opUp(pScreen)
		} 
		else 
		{
			opener.opUp(pScreen)
		} 	
  	}

//============================================================ 
// PRINT THE SCREEN SCREEN 
//============================================================
 function Print()
	{
		window.print();
	}

//============================================================
// SHOW HELP IN NEW WINDOW 
//============================================================
 function ShowHelp(pScreen)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowHelp(pScreen)
		} 
		else 
		{
			opener.ShowHelp(pScreen)
		} 		
	}

//============================================================
// SHOW SCREEN IN NEW WINDOW 
//============================================================
 function ShowScreen(pScreen)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowNewScreen(pScreen, null)
		} 
		else 
		{
			opener.ShowNewScreen(pScreen, null)
		}         	
	}

//============================================================
// SHOW HELP IN NEW WINDOW 
//============================================================
 function ShowRoboHelp(pScreen, pScreenName, pScreenOptions)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowRoboHelp(pScreen, pScreenName, pScreenOptions);
		} 
		else if (strLocation.indexOf('PLM_LogonSiteSelect.aspx',0) > 0)
		{
			nShowRoboHelp(pScreen, pScreenName, pScreenOptions);
		} 
		else 
		{
			opener.ShowRoboHelp(pScreen, pScreenName, pScreenOptions);
		}  		
	}	

//============================================================
// SHOW SCREEN IN NEW WINDOW WITH SCREEN NAME - used on dispatch calendar display links in new windows in Hints                
//============================================================
 function ShowItemChargesScreen(pItemKey, pListKey)
	{
		strURL = "../Builder Lists/PLM_ItemDetail.aspx?k=" + pItemKey + "&lk=" + pListKey + "&chg=1";
		window.location.href = strURL; 
	}
 function ShowItemEquipmentScreen(pItemKey, pListKey)
	{
		strURL = "../Builder Lists/PLM_ItemEquipment.aspx?k=" + pItemKey + "&lk=" + pListKey;
		window.location.href = strURL; 
	}
 function ShowItemScreen(pItemKey, pListKey)
	{
		strURL = "../Builder Lists/PLM_ItemDetail.aspx?k=" + pItemKey + "&lk=" + pListKey;
		window.location.href = strURL; 
	}
 function ShowListScreen(pListKey, pJobKey)
	{
		strURL = "../Builder Lists/PLM_ListDetail.aspx?k=" + pListKey + "&jk=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowListScreenRM(pListKey, pJobKey)
	{
		strURL = "../Builder Lists/RM_ListDetail.aspx?k=" + pListKey + "&jk=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowJobScreen(pJobKey)
	{
		strURL = "../Builder Jobs/PLM_JobDetail.aspx?k=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowJobScreenRM(pJobKey)
	{
		strURL = "../Builder Jobs/RM_JobDetail.aspx?k=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowJobCorr(pCorrKey, pJobKey)
	{
		strURL = "../Builder Jobs/PLM_JobCorr.aspx?k=" + pCorrKey + "&jk=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowJobCostsDetail(pJobKey, pListKey, pListTypeKey, pJobCostTypeKey, pIsEst)
	{
		strURL = "../Builder Jobs/PLM_JobCostsDetail.aspx?jk=" + pJobKey + "&lk=" + pListKey + "&ltk=" + pListTypeKey + "&jctk=" + pJobCostTypeKey + "&est=" + pIsEst;
		window.location.href = strURL; 
	}
 function ShowJobAccountingDetail(pJobKey, pListTypeKey, pJobCostAccountingTypeKey)
	{
		strURL = "../Builder Jobs/PLM_JobCostsAccountingDetail.aspx?jk=" + pJobKey + "&ltk=" + pListTypeKey + "&jcatk=" + pJobCostAccountingTypeKey;
		window.location.href = strURL; 
	}
 function ShowJobQPDetail(pQPDetailKey, pJobKey)
	{
		strURL = "../Builder Jobs/PLM_JobQPDetail.aspx?k=" + pQPDetailKey + "&jk=" + pJobKey;
		window.location.href = strURL; 
	}
 function ShowVendorScreen(pVendorKey)
	{
		strURL = "../Builder Vendors/PLM_VendorDetail.aspx?k=" + pVendorKey;
		window.location.href = strURL; 
	}	
 function ShowVendorCorr(pVendorKey)
	{
		strURL = "../Builder Vendors/PLM_VendorCorr.aspx?k=" + pVendorKey;
		window.location.href = strURL; 
	}	
 function ShowProjectScreen(pProjectKey)
	{
		strURL = "../Builder Projects/PLM_ProjectDetail.aspx?k=" + pProjectKey;
		window.location.href = strURL; 
	}	
 function ShowProjectCorr(pProjectKey)
	{
		strURL = "../Builder Projects/PLM_ProjectCorr.aspx?k=" + pProjectKey;
		window.location.href = strURL; 
	}	
 function ShowEmailScreen(pEmailAddress,pContactKey,pAssocKey,pAssoc)
	{
		strURL = "../Email/PLM_BuildEmail.aspx?f=" + pAssoc + "Detail&mm=0&" + pAssoc.substr(0,1).toLowerCase() + "k=" + pAssocKey + "&ck=" + pContactKey + "&a=&e=" + pEmailAddress;
		window.location.href = strURL; 
	}	

//============================================================
// SHOW SCREEN IN NEW WINDOW WITH SCREEN NAME                 
//============================================================
 function ShowNewScreen(pScreen, pScreenName)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowNewScreen(pScreen, pScreenName);
		} 
		else 
		{
			opener.ShowNewScreen(pScreen, pScreenName);
		}   		
	}

 function ShowNewScreenCombo(pScreen, pScreenName, pTop, pLeft)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowNewScreenCombo(pScreen, pScreenName, pTop, pLeft)
		} 
		else 
		{
			opener.ShowNewScreenCombo(pScreen, pScreenName, pTop, pLeft)
		} 		
	}
	
 function ShowNewScreenComboSized(pScreen, pScreenName, pTop, pLeft, pWidth, pHeight)
	{
		if (strLocation.indexOf('PLM_List.aspx',0) > 0 || strLocation.indexOf('RM_List.aspx',0) > 0)
		{
			parent.ShowNewScreenComboSized(pScreen, pScreenName, pTop, pLeft, pWidth, pHeight)
		} 
		else 
		{
			opener.ShowNewScreenComboSized(pScreen, pScreenName, pTop, pLeft, pWidth, pHeight)
		}   		
	}	
 function GenPass(pField)
	{
		myField = document.getElementById(pField);
		myField.value = getPassword();
	}	
//============================================================	
//Password Functions
//============================================================
function getRandomNum(lbound, ubound) 
	{
		return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
	}
function getPassword() 
	{
		var length = 10;
		var rc = "";
		var charSet = "123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ~!@#&-_?";
		if (length > 0)
				
		//rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
		for (var idx = 1; idx < length; ++idx) 
		{
			rc = rc + charSet.charAt(getRandomNum(0, charSet.length));
		}
		return rc;
	}
function UpdateField(pSource, pDestination)
	{
		//alert(pSource + "  " + pDestination)
		myField1 = document.getElementById(pSource);
		myField2 = document.getElementById(pDestination);
		myField2.value = myField1.value;	
	
	}
//============================================================
// TIME STAMP 
//============================================================
//Get current time/ date stamp
function DateTimeStamp(pName)
{
	var myDate = new Date();
	var hours = myDate.getHours();
	var minutes = myDate.getMinutes();
	var seconds = myDate.getSeconds();
	var amOrPm = "AM";
	if (hours > 11) amOrPm = "PM";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;
	var GMToffset = myDate.getTimezoneOffset();
	var timeZone = ""
	
	//Check for Daylight savings time
	var gmt = new Date;
	var lsm = new Date;
	var lso = new Date;
	var dst = 0;
	//Find Start Date - second Sunday in March
	lsm.setMonth(2); // March
	lsm.setDate(8); // first possible second Sunday
	var day = lsm.getDay();// day of week of 8th
	if (day > 0) // not Sunday
	    lsm.setDate(9+(6-day)); // second Sunday
	
	//Find End Date - First Sunday in November
	lso.setMonth(10); // November
	lso.setDate(1); // first possible Sunday
	day = lso.getDay();// day of week of 1st
	if (day > 0) // not Sunday
	    lso.setDate(2+(6-day)); // first Sunday
	
	// Check if dst
	if (gmt >= lsm && gmt < lso) dst = 1;
	
	//if we are in Daylight savings time fix it
	if(dst == 1)
	{
		GMToffset = GMToffset + 60;
	}
	
	//Eastern
	if (GMToffset == 300)
	{
		timeZone = " (Eastern)";
	}
	//Central
	if (GMToffset == 360)
	{
		timeZone = " (Central)";
	}
	//Mountain
	if (GMToffset == 420)
	{
		timeZone = " (Mountain)";
	}
	//Pacific
	if (GMToffset == 480)
	{
		timeZone = " (Pacific)";
	}
	var returnValue = "\n[" + pName + "] " + parseInt(myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getYear() + " " + hours + ":" + minutes + ":" + seconds + " " + amOrPm + timeZone + "\n";
	//myField = document.getElementById(pField);
	//myField.value = myField.value + returnValue;
	return(returnValue);
}

function insert(el,ins) 
{ 
    if (el.setSelectionRange)
    { 
        el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length); 
    } 
    else if (document.selection && document.selection.createRange)
    { 
        el.focus(); 
        var range = document.selection.createRange(); 
        range.text = ins + range.text; 
    } 
} 

function positionCursorAtEnd(input)
{
	var range = input.createTextRange();
	range.collapse(false);
	range.select();
}
//============================================================
//Auto log them out
//============================================================
function LogoutTimeout()
{
	//top.location.href = "../Builder Logon/PLM_Logout.aspx";
	//alert("Your logon is getting ready to timeout due to inactivity.");
}
if (window.location.href.indexOf("PLM_Logon.aspx") <= 0)
{
	window.setTimeout(LogoutTimeout,1680000);
}

//============================================================
//add page to history for back button
//============================================================
if (parent.location.href.indexOf("PLM_Dashboard.htm") > 0 || parent.location.href.indexOf("RM_Dashboard.htm") > 0)
{
	parent.appHistoryAdd(this.location.href,document.title);
}
//Function for deselecting all rows in an RadGrid
function RadGridDeselectAllRows(grid)
{
    grid.AllowMultiRowSelection = true;
    for(var i = 0; i < grid.MasterTableView.Rows.length; i++)
    {
        if(grid.MasterTableView.Rows[i].Selected)
        {
            grid.MasterTableView.SelectRow(grid.MasterTableView.Rows[i].Control, false);
        }
    }
    grid.AllowMultiRowSelection = false;
}  

//============================================================
//Is Something selected in DDL
//============================================================
function IsDDLSelected(oSrc, args)
{
    if(args.Value == "0" || args.Value == "" || args.Value == " ")
    {
        args.IsValid = false;
        return;
    }
    else
    {
        return true;
    }
}