// Global Code for BNET
// D. Archer 24-Mar-07

function confirmDeleteMsg() {
    return msgConfirmDelete;    
}

function jShowAddress() {
	
	if (document.getElementById('ShowAddress').checked == true) {
	    document.getElementById('AddressBlock2').style.display = "none";		
//        document.getElementById('sAddress1').value = "";
//        document.getElementById('sAddress2').value = "";
//        document.getElementById('sPostCode').value = "";
//        document.getElementById('sCity').value = "";
//        document.getElementById('sCountry').value = document.getElementById('Country').value;
//        //document.getElementById('sStateProvince').value = "";
//        document.getElementById('sStateProvince2').value = "";		
		}
	else {
		document.getElementById('AddressBlock2').style.display = "block";}
}

// Beginning of phone validation routines
var digits = "0123456789";
var phoneNumberDelimiters = " ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
// End of phone validation

function validPhone(Phone){	
	if ((Phone.value==null)||(Phone.value=="")){
		Phone.className = 'textBox1';
		return false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		Phone.className = 'textBoxError';
		return false;
	}
	Phone.className = 'textBox1';
	return true;
 }






function jDown(el) {
//el.style.borderLeft = "1px solid rgb(25,35,130)";
el.style.borderRight = "1px solid rgb(237,240,255)";
//el.style.borderTop = "1px solid rgb(25,35,130)";
el.style.borderBottom = "1px solid rgb(237,240,255)";  
}
function jUp(el) {
//el.style.borderLeft = "none";
el.style.borderRight = "none";
//el.style.borderTop = "none";
el.style.borderBottom = "none";  
}
function validateLink(TxtBox) {
		if (TxtBox.value.length > 3) {
			if (TxtBox.value.indexOf("://") == -1) {
				TxtBox.value = "http://" + TxtBox.value;
			}
		}
}
function SelectAllCheckboxes(spanChk){
	var xState = spanChk.checked;	
	var elm=spanChk.form.elements;
	for(i=0;i<elm.length;i++)
		if(elm[i].type=="checkbox" && elm[i].id!=spanChk.id) {
			if(elm[i].checked!=xState)
			elm[i].click();
		}
}
function HighlightRow(chkB)	{
	window.event.cancelBubble=true;
}
function hrw (row,action) {
	if (action==0) {
		row.className='DGItemStyle';
	}
	if (action==1) {
		row.className='DGAlternatingItemStyle';
	}				
	if (action==2) {
		row.className='DGAlternatingItemStyle_Light';
	}				
}
function openB(Customer, Project, Batch) {
	//window.IDa = IDa;
	//window.Country = Country;
	
	var myfeatures = new String();
	myfeatures += 'width=535,';
	myfeatures += 'height=360,';
	myfeatures += 'top=0,';
	myfeatures += 'left=250,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';

	newWinFin = window.open("../Upload/FileUpload.aspx?C=" + Customer + "&P=" + Project + "&B=" + Batch ,"F", myfeatures);
	
	newWinFin.focus();
}
function openASG(TaskID) {
	//Opens the Assignment Window
	
	var myfeatures = new String();
	myfeatures += 'width=535,';
	myfeatures += 'height=380,';
	myfeatures += 'top=0,';
	myfeatures += 'left=250,';
	myfeatures += 'resizable=no,';
	myfeatures += 'scrollbars=no,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=no';

	newWinFin = window.open("../Project/Assignment.aspx?TaskID=" + TaskID ,"F", myfeatures);
	
	newWinFin.focus();
}
function openASGV(TaskID) {
	//Opens the Assignment Window
	
	var myfeatures = new String();
	myfeatures += 'width=535,';
	myfeatures += 'height=360,';
	myfeatures += 'top=0,';
	myfeatures += 'left=250,';
	myfeatures += 'resizable=no,';
	myfeatures += 'scrollbars=no,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=no';

	newWinFin = window.open("../Project/AssignmentV.aspx?TaskID=" + TaskID ,"F", myfeatures);
	
	newWinFin.focus();
}



function getRadioValue(radioName)
{
 var collection;
 collection = document.getElementById(radioName);
 for (i=0;i<collection.length;i++) 
{
 if (collection[i].checked)
 return(collection[i].value);
 }
}
function setSelectListToValue(value, selectId){
	var i, si, v, args=setSelectListToValue.arguments;
	if ((obj=document.getElementById(args[1])) != null){
		v = args[0];
		for(i=0; i<obj.length; i++){
			if(obj.options[i].value == v){
				si = i;
			}
		}
		obj.selectedIndex = si;
	}
}

function setSelectListTextToValue(value, selectId){
	var i, si, v, args=setSelectListTextToValue.arguments;
	if ((obj=document.getElementById(args[1])) != null){
		v = args[0];
		for(i=0; i<obj.length; i++){
			if(obj.options[i].text == v){
				si = i;
			}
		}
		obj.selectedIndex = si;
	}
}
function openA(IDa, Office) {
	window.IDa = IDa;
	window.Office = Office;
	
	var myfeatures = new String();
	myfeatures += 'width=535,';
	myfeatures += 'height=360,';
	myfeatures += 'top=0,';
	myfeatures += 'left=250,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';

	newWinA =window.open("../reports_cs/p_Assets.asp","P", myfeatures);

	newWinA.focus();
}
 function openS(number) {
	window.Fnumber = number;

	var myfeatures = new String();
	myfeatures += 'width=535,';
	myfeatures += 'height=600,';
	myfeatures += 'top=0,';
	myfeatures += 'left=180,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';

	newWin99 =window.open("C_Combined.asp","C", myfeatures);
	newWin99.focus();
}
 function openBL(Employee,IDa) {
	window.Employee = Employee;
	window.IDa = IDa;

	var myfeatures = new String();
	myfeatures += 'width=400,';
	myfeatures += 'height=300,';
	myfeatures += 'top=0,';
	myfeatures += 'left=300,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';

	newWinBL =window.open("BL_Employee_Details.asp","BL", myfeatures);
	newWinBL.focus();
}


function openP(number, phase, yearY) {
	window.Mode = "M"
	var myfeatures = new String();
	myfeatures += 'width=575,';
	myfeatures += 'height=430,';
	myfeatures += 'top=0,';
	myfeatures += 'left=235,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	var ambientMode = "";
	if (window.Mode != null){ambientMode = "&Mode=" + window.Mode}
	newWin1 =window.open('../Project/ProjectCard.aspx?ProjectID=' + number + ambientMode ,"P", myfeatures);
	newWin1.focus();
}
function openPL(globalsid, number) {
	window.Mode = "LD"
	var myfeatures = new String();
	myfeatures += 'width=590,';
	myfeatures += 'height=560,';
	myfeatures += 'top=0,';
	myfeatures += 'left=205,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	var ambientMode = "";
	if (window.Mode != null){ambientMode = "&Mode=" + window.Mode}
	newWin1 =window.open('../reports/p_Details.asp?psid=' + globalsid + '&locnumber=' + number + ambientMode ,"P", myfeatures);
	newWin1.focus();
}
function openPL2(number, phase, yearY) {

	var myfeatures = new String();
	myfeatures += 'width=590,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=205,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	var ambientMode = "";
	if (window.Mode != null){ambientMode = "&Mode=" + window.Mode}
	newWin1 =window.open('../reports/p_LocalDetails.asp?pnumber=' + number + ambientMode ,"P", myfeatures);
	newWin1.focus();
}

function openC(number) {
	window.Fnumber = number;

	var myfeatures = new String();
	myfeatures += 'width=675,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=160,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	
	var MyFileName = window.location.href;
	var startstr = MyFileName.lastIndexOf ("/");
	var endstr = MyFileName.length;
	var midstr = MyFileName.indexOf ("_",startstr);
	
	if (midstr > startstr + 3) {midstr = startstr;}

	var Header = MyFileName.substring(startstr + 1, midstr + 1);
	MyFileName =  MyFileName.substring(midstr + 1, endstr);
	
	

	if (window.DrillOption=='Summary'){
	MyFileName = "../reports/C_Combined.asp?ParentCo_sid=" + number;}
	else {
	MyFileName = "../reports/CD_" + MyFileName;}

	
	newWin2 =window.open(MyFileName,"C", myfeatures);
	newWin2.focus();
}


function openE1(number) {
	
	window.Fnumber = number;

	var myfeatures = new String();
	myfeatures += 'width=675,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=160,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	
	//alert(number);

	var country =


	alert(country);


	newWinEE1 =window.open("../reports/C_Combined.asp?Parentco_Sid=" + number, "E", myfeatures);
	newWinEE.focus();
}

function openR(number) {
//rename all openPM functions to Drill()
	window.PMnumber = number;

	var myfeatures = new String();
	myfeatures += 'width=675,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=160,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	
	var MyFileName = window.location.href;
	
	var startstr = MyFileName.lastIndexOf ("/");
	var endstr = MyFileName.length;
	var midstr = MyFileName.indexOf ("_",startstr);
	
	if (midstr > startstr + 3) {midstr = startstr;}

	var Header = MyFileName.substring(startstr + 1, midstr + 1);
	
	MyFileName =  MyFileName.substring(midstr + 1, endstr);
	
	var TempFileName = MyFileName;

	if (Header=='BK_'){
	TempFileName = "AK_" + MyFileName;}
	else {
	TempFileName = "MD_" + MyFileName;}

	if (Header=='AM_'){
	TempFileName = "AD_" + MyFileName;}
	
	newWin3 =window.open(TempFileName,"Details", myfeatures);
	newWin3.focus();
}
function openAM(number) {
	window.AMnumber = number;

	var myfeatures = new String();
	myfeatures += 'width=675,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=160,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	
	var MyFileName = window.location.href;
	var startstr = MyFileName.lastIndexOf ("/");
	var endstr = MyFileName.length;
	var midstr = MyFileName.indexOf ("_",startstr);
	
	if (midstr > startstr + 3) {midstr = startstr;}

	var Header = MyFileName.substring(startstr + 1, midstr + 1);
	MyFileName =  MyFileName.substring(midstr + 1, endstr);
	MyFileName = "AD_" + MyFileName;

	newWin4 =window.open(MyFileName,"AM", myfeatures);
	newWin4.focus();
}
function openD(vType,vParam) {

	window.Param = vParam;

	var myfeatures = new String();
	myfeatures += 'width=675,';
	myfeatures += 'height=500,';
	myfeatures += 'top=0,';
	myfeatures += 'left=180,';
	myfeatures += 'resizable=yes,';
	myfeatures += 'scrollbars=yes,';
	myfeatures += 'toolbar=no,';
	myfeatures += 'location=no,';
	myfeatures += 'menubar=yes';
	
	var MyFileName = window.location.href;
	var startstr = MyFileName.lastIndexOf ("/");
	var endstr = MyFileName.length;
	var midstr = MyFileName.indexOf ("_",startstr);
	
	if (midstr > startstr + 3) {midstr = startstr;}

	var Header = MyFileName.substring(startstr + 1, midstr + 1);
	MyFileName =  MyFileName.substring(midstr + 1, endstr);

	MyFileName = vType + "D_" + MyFileName;

	alert("This drill-down report is under construction");

	//newWin5 =window.open(MyFileName,"C", myfeatures);
	//newWin5.focus();
}
function sorttable(colname) {
    //var ScrollVal = document.body.scrollTop;
	var oDSO;

	oDSO = DataSource1;

    oDSO.Sort = colname;
    oDSO.Reset();

   // window.scroll(0,ScrollVal);
   //SourceTable.scrollIntoView(true);
  }
function sorttable2(colname) {
	var Dsrc = window.event.srcElement.parentElement.parentElement.parentElement.parentElement.dataSrc;

	if (Dsrc== '#DataSource1') {DataSource1.Sort = colname;DataSource1.Reset();}
	if (Dsrc== '#DataSource2') {DataSource2.Sort = colname;DataSource2.Reset();}
	if (Dsrc== '#DataSource3') {DataSource3.Sort = colname;DataSource3.Reset();}
}
function ChangeDisplay(mylist) {
	SourceTable.dataPageSize = mylist.options(mylist.selectedIndex).value;
}
function PageChange(direction,vFlag) {
	var oTable;

	if (vFlag==null) {
		oTable = document.all.SourceTable;
	}
	if (vFlag=='a') {
		oTable = window.event.srcElement.parentElement.parentElement.parentElement.parentElement.parentElement;
	}
	if (direction=="previous") {
		oTable.previousPage(); 
	}
	if (direction=="next") {
		oTable.nextPage();
	}		
}
function FindQuarter (vDate) {
		var vYear = vDate.substr(4,2);
		var vMonth = vDate.substr(0,3);
		var vQuarter;
			
		if (vMonth =="Jan" || vMonth=="Feb" || vMonth=="Mar") {
			vQuarter = "Q1";}
		if (vMonth =="Apr" || vMonth=="May" || vMonth=="Jun") {
			vQuarter = "Q2";}
		if (vMonth =="Jul" || vMonth=="Aug" || vMonth=="Sep") {
			vQuarter = "Q3";}
		if (vMonth =="Oct" || vMonth=="Nov" || vMonth=="Dec") {
			vQuarter = "Q4";}
		return (vQuarter + "-" + vYear);
}
function LoadData (vReport) {
	if (DataSource1.DataURL != vReport) {
		DataSource1.DataURL = vReport;}
}
function LoadData2 (vReport) {
	if (DataSource2.DataURL != vReport) {
		DataSource2.DataURL = vReport;}
}
function LoadData3 (vReport) {
	if (DataSource3.DataURL != vReport) {
		DataSource3.DataURL = vReport;}
}