// JavaScript page methods for pctsWeb
// PAGE = why.php

// --- namespace variables -------
page.mousedSlideTop = '';
page.mousedSlideLeft = '';
page.mousedSlideCaption = '';
	
// --- page functions -------

page.GetElementLeft = function(eElement) {
	// determine the true left coordinate of an element
	
    // initialize var to store calculations
	var nLeftPos = eElement.offsetLeft;          
    
	// identify first offset parent element
	var eParElement = eElement.offsetParent;     
	
	// now move up through element hierarchy and calculate the left offset
    while (eParElement != null)
    {                                            
        nLeftPos += eParElement.offsetLeft;      
        eParElement = eParElement.offsetParent; 
		
    }
	
	// return the offset calculated
    return nLeftPos;                             
}

page.mainImageLoaded = function() {
	// perform certain operations after the main page image has fully loaded
	
	// first, make sure the menu bar is fully visible
	document.getElementById('mainMenuBar').style.visibility = 'visible';
}

page.GetElementTop = function(eElement) {
	// determine the true top coordinate of an element
	
    // initialize var to store calculations
	var nTopPos = eElement.offsetTop;            
    
	// identify first offset parent element
	var eParElement = eElement.offsetParent;
	
	// now move up through element hierarchy and calculate the top offset
    while (eParElement != null)
    {                                            
        nTopPos += eParElement.offsetTop;        
        eParElement = eParElement.offsetParent;  
		
    }
	
	// return the offset calculated
    return nTopPos;                              
}

page.evaluateSiteState = function() {
	// evaluate the site status to see if the site is set to on or off
	if (pctsFramework.siteState == '0' && pctsFramework.inCMS=='0') {
		pctsFramework.loadMaintenance();
	}
}

page.evaluatePlatform = function() {
	// check the framework for the platform, and if this is an iPhone, alert
	pctsFramework.browserParent = theParent;
	// pctsFramework.popAlert(pctsFramework.browserParent);

	page.setVerticalSize();
}

page.setItemStyle = function() {
	// set the style for the selected item.
	if (pctsFramework.currentPage != null) {
		// alert(pctsFramework.currentPage);
		// now set the BG style.
		try {
			if (pctsFramework.browserPath == 'ie') {
				//var content = document.getElementById(pctsFramework.currentPage).innerHTML;
				//document.getElementById(pctsFramework.currentPage).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='../images/leftNavItemBG.png');"
				//document.getElementById(pctsFramework.currentPage).innerHTML = content;
				// document.getElementById(pctsFramework.currentPage).style.color = '#FFFFFF';
			} else {
				document.getElementById(pctsFramework.currentPage).style.backgroundImage = 'url(../images/leftNavItemBG.png)';
				document.getElementById(pctsFramework.currentPage).style.backgroundRepeat = 'repeat-y';
				document.getElementById(pctsFramework.currentPage).style.color = '#FFFFFF';
			}
			
		} catch(err) {
			
		}
		
	}
	
}

page.setVerticalSize = function() {
	// set the vertical size of of page elements
	var theHeight = page.getClientHeight();
	document.getElementById('mainImageContainer').style.height = theHeight + 'px';
}

page.getClientHeight = function() {
	return document.getElementById('primaryBody').offsetHeight + 250;
}

page.handleMenuMouse = function(theId, theAction) {
	// handle mouse actions across a main menubar item

	// first create an id for the underline of the menu item
	var theUnder = theId + '_under';

	if (theAction == 'in') {
		// this is a mouse enter event
		document.getElementById(theUnder).className = 'lsep_lbl';
	} else {
		document.getElementById(theUnder).className = '';
	}
		
}

page.goHome = function() {
	// navigate to the home page, as appropriate, depending on the browser
	if (pctsFramework.browserPath == 'ie') {
		// direct to ie main
		window.location.href = "../index.php";

	} else {
		// direct to other main
		window.location.href = "../index.php";

	}
	
	// hide any balloons that are lingering
	pctsFramework.hideSlideThumbCaptionBalloon();

}

page.handleNavMouse = function(theObject, theAction) {
	// handle mouse behaviors associated with a nave element mouse action
	if (theAction == 'in') {
		// the mouse is over the region
		theObject.className = "leftNavTextLP";
	
	} else {
		// the mouse is out
		theObject.className = "leftNavTextLP";

	}
}

page.handleHomeMouse = function(theObject, theAction) {
	// handle mouse behaviors associated with a nave element mouse action
	if (theAction == 'in') {
		// the mouse is over the region
		document.getElementById('homeText').className = "leftNavTextLargeMoused";
		document.getElementById('homeIcn').className = "homeIcnMoused";
	
	} else {
		// the mouse is out
		document.getElementById('homeText').className = "leftNavTextLarge";
		document.getElementById('homeIcn').className = "homeIcn";

	}
}

page.goToURL = function(theURL, theID) {
	// navigate to a specified URL
	window.location.href = theURL;
	if (theID != 'undefined') {
		// set the clicked ID
		pctsFramework.currentPage = theID;
	} else {
		pctsFramework.currentPage = null;
	}

	// hide any balloons that are lingering
	pctsFramework.hideSlideThumbCaptionBalloon();
	
}

page.noAction = function(theURL, theID) {
	// do nothing - used as the function call from a disabled nav item

}

page.goToSub = function(theURLSet, theID) {
	// navigate to a specified sub page of an item
	
	// the URLSet will be a complex of the URL plus the page token
	// we split it apart
	var theParts = theURLSet.split('?');
	var theURL = theParts[0];
	var theID = theParts[1];
	
	window.location.href = theURL;
	if (theID != 'undefined') {
		// set the clicked ID
		pctsFramework.currentPage = theID;
	} else {
		pctsFramework.currentPage = null;
	}
	
	// hide any balloons that are lingering
	pctsFramework.hideSlideThumbCaptionBalloon();
	
}


page.handleSubMouse = function(theObject, theAction, theLevel) {
	// handle mouse behaviors associated with a nave element mouse action
	if (theAction == 'in') {
		// the mouse is over the region
		theObject.className = "navSub" + theLevel + "Moused";
	
	} else {
		// the mouse is out
		theObject.className = "navSub" + theLevel;

	}
}

page.handleSub2Mouse = function(theObject, theAction, theLevel) {
	// handle mouse behaviors associated with a nave element mouse action
	if (theAction == 'in') {
		// the mouse is over the region
		theObject.className = "navSub2" + "Moused";
	
	} else {
		// the mouse is out
		theObject.className = "navSub2";

	}
}

page.gallerySlideMouseIn = function(theId, theCaption) {
	// handle mouseIn to a gallery slide
	var theOuter = theId;
	var theInner = theId + '_image';
	
	// if this is IE, we handle things differently than other browsers
	if (pctsFramework.browser == 'IE') {
		// page.setOpacity(100, theId);
		// page.setOpacity(100, theId + '_image');
		// $('#' + theOuter).fadeTo("normal", 1);
		$('#' + theInner).fadeTo("normal", 1);
		
	} else {
		page.setOpacity(100, theId);
		// $('#' + theOuter).fadeTo("normal", 1);
	}
	
	// set the top tracking, etc.
	page.mousedSlideTop = page.GetElementTop(document.getElementById(theId));
	page.mousedSlideLeft = page.GetElementLeft(document.getElementById(theId));
	page.mousedSlideCaption = theCaption;
	
	// instantiate a timer to show the caption for this slide
	pctsFramework.balloonTimer = window.setInterval(page.showThumbCaption, 400);

}

page.gallerySlideMouseOut = function(theId) {
	// handle mouseIn to a gallery slide
	var theOuter = theId;
	var theInner = theId + '_image';
	
	// if this is IE, we handle things differently than other browsers
	if (pctsFramework.browser == 'IE') {
		// page.setOpacity(70, theId);
		// page.setOpacity(70, theId + '_image');
		// $('#' + theOuter).fadeTo("normal", 0.70);
		$('#' + theInner).fadeTo("normal", 0.70);
		
	} else {
		page.setOpacity(70, theId);
		// $('#' + theOuter).fadeTo("normal", 0.70);
		
	}
	
	// cancel the slide pop interval
	window.clearInterval(pctsFramework.balloonTimer);
	
	pctsFramework.hideSlideThumbCaptionBalloon();
}

page.galleryControlMouseIn = function(theObject) {
	// handle mouseIn to a gallery slide
	var theClass = theObject.className;
	
	if (theClass == 'slidePage') {
		// it is not selected
		theObject.className = 'slidePageMoused';
		
	} else {
		// it is selected
		theObject.className = 'slidePageSelectedMoused';
		
	}

}

page.galleryControlMouseOut = function(theObject) {
	// handle mouseIn to a gallery slide
	var theClass = theObject.className;
	
	if (theClass == 'slidePageMoused') {
		// it is not selected
		theObject.className = 'slidePage';
		
	} else {
		// it is selected
		theObject.className = 'slidePageSelected';
		
	}

}

page.setOpacity = function(theOpacity, theId) {
	// this is a cross-browser capable method for setting the opacity of an object
	
	var theObject = document.getElementById(theId).style; 
	
	// safari
	theObject.opacity = (theOpacity / 100);

	// mozilla
	theObject.MozOpacity = (theOpacity / 100);

	// IE
	theObject.filter = "alpha(opacity=" + theOpacity + ")";
	
}

page.setNoPropogate = function(theEvent ) {
	// cancel the bubble 
	var theEvent; // the event fired
	
	// first figure out if this is IE and set the cancelBubble property
	theEvent.cancelBubble = true;
	
	// if it isn't IE stopPropagation
	if (pctsFramework.browserPath != 'ie') {
		//alert('this is firefox');
		e.stopPropagation();
	}
}

page.galleryControlClick = function(theObject, theRef) {
	// handle a click to an image gallery paging control
	
	//fist change the classes of all control instances to the unselected class
	for (i=1; i <= 10; i++) {
		// loop through the largest possible extent of control derivatives and change class attributes
		try {
			var theId = 'pageSelector_' + i;
			document.getElementById(theId).className = 'slidePage';
			document.getElementById(theId + 'b').className = 'slidePage';
			
		} catch(err) {
			
		}
	}
	
	// change the class of this control and it's bottom variant to the on class
	var theIdStart = theObject.id;
	var theIdParts = theIdStart.split('_');
	var theId = theIdParts[0];

	document.getElementById(theId + '_' + theRef).className = 'slidePageSelected';
	document.getElementById(theId + '_' + theRef + 'b').className = 'slidePageSelected';
	
	// now retrieve slides for the new page reference
	var theToken = document.getElementById('slideToken').value;
	gallery.getGalleryAssemblyPage(theToken, theRef);
	
}

page.gallerySlideClick = function(theObject, theSrc, theHeight, theWidth, theCaption) {
	// show the full side version of a slide
	
	// first keep a record of the slide clicked
	pctsFramework.selectedGallerySource = theSrc;
	pctsFramework.selectedGalleryWidth = theWidth;
	pctsFramework.selectedGalleryHeight = theHeight;
	pctsFramework.selectedGalleryCaption = theCaption;
	
	// show the window
	pctsFramework.showWindow();
	
}

page.showThumbCaption = function() {
	// trigger display of a slide caption in a balloon for a slide
	if(pctsFramework.balloonShown != true) {

		pctsFramework.showSlideThumbCaptionBalloon(page.mousedSlideCaption, page.mousedSlideTop, page.mousedSlideLeft);
		
	}

}

page.hideThumbCaption = function() {
	// hide the thumb caption
	pctsFramework.hideSlideThumbCaptionBalloon();
	
}

page.getContentPlusData = function(theContentSource, theTarget, showSpinner) {
	// ajax some content asynchronously along with a data packet.  Return content to a target
	// container after return AND process data.

	// first, set up a request object.  We have to do this so it degrades gracefully for IE6
	if (window.XMLHttpRequest) {
		// this is IE7, safari, etc.

		var xmlhttp =  new XMLHttpRequest();

	} else {
		// this is probably IE6, so see if we can instantiate an activeX obejct
		if (window.ActiveXObject) {

     		var xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');

  		}
	}

	// inject a loading indicator into the target object
	if (showSpinner != false) {
		// we do not show the spinner in IE6 because it will cause a crash
		// interacts with Ajax activeX object
		if (pctsFramework.browserVersion != '6.0') {
			pctsFramework.injectSpinner(theTarget);
		}

	}
	
	// wire up the callBack handler
	xmlhttp.onreadystatechange = function() {  
  		if(xmlhttp.readyState == 4)  
		var theReturn = xmlhttp.responseText;

		// populate the target only if it is not 'undefined'
		if (theReturn != undefined) {
			
			// break the return into parts.  The first part will be the script block returned, the second will be the content
			var theParts = theReturn.split('#content');
			var theData = theParts[0];
			
			// evaluate the returned data packet
			// and populate the innerHTML
			
			try {
				theTarget.innerHTML = theParts[1];
				
				eval(theData);
				
			} catch(err) {
				
			}

		} else {
			// alert(theReturn);

		}
		
	};  

    // send the ajax request after the desired data
	xmlhttp.open('GET', theContentSource, true);
	xmlhttp.send(null);
}

page.doContact = function() {
	// handle a click to a contact control
	page.goToURL('contact.php');
}

page.handleCountrySelect = function(theValue) {
	// handle selection of a country in the country selector
	var theIndex = document.getElementById('country').selectedIndex;
	var theControl = document.getElementById('country');
	var theText = theControl[theIndex].text;
	
	if(theValue == 'US') {
		// the US has been selected so we need to load the US state list
		
		// get a random number so as to prevent IE from using a cached accessor return
		var theRan = pctsFramework.randomNumber();
		
		// Create an accessor
		var theAccessor = "../accessors/getStates.php?anticache=" + theRan;
		
		// set the target
		var theTarget = document.getElementById('stateContainer');
	
		pctsFramework.getContent(theAccessor, theTarget, false);
		
		// set the state label
		document.getElementById('stateLabelContainer').innerHTML = "State";
		
		// set the code label
		document.getElementById('codeLabelContainer').innerHTML = "Zip Code";
	}
	
	if(theValue == 'CA') {
		// Canada has been selected so we need to load the Canada province list
		
		// get a random number so as to prevent IE from using a cached accessor return
		var theRan = pctsFramework.randomNumber();
		
		// Create an accessor
		var theAccessor = "../accessors/getProvinces.php?anticache=" + theRan;
		
		// set the target
		var theTarget = document.getElementById('stateContainer');
	
		pctsFramework.getContent(theAccessor, theTarget, false);
		
		// set the label
		document.getElementById('stateLabelContainer').innerHTML = "Province";
		
		// set the code label
		document.getElementById('codeLabelContainer').innerHTML = "Postal Code";
		
	}
	
	if(theValue != 'CA' && theValue != 'US') {
		// neither has been selected, so we need to remove both the state selector and the label
		
		// hide the state / province label
		document.getElementById('stateLabelContainer').innerHTML = "";
		
		// hide the state / province label
		document.getElementById('stateContainer').innerHTML = "";
		
		// set the code label
		document.getElementById('codeLabelContainer').innerHTML = "Postal Code";
		
	}	
	
}
 
page.handleDepOtherClick = function(theObject) {
	// handle a click to the "dept other" checkbox
	
	if (theObject.checked) {
		// the checkbox is checked, so show the "other" field
		document.getElementById('otherRow').style.display = "block";
		
	} else {
		document.getElementById('otherRow').style.display = "none";
		
	}
}

page.validateContactForm = function() {
	// validate the contact form before submission
	var valid = true;
	
	var theValue = document.getElementById('fname').value;
	if(theValue == '') {
		valid = false;
		page.setFieldError('fname');
	}
	
	var theValue = document.getElementById('lname').value;
	if(theValue == '') {
		valid = false;
		page.setFieldError('lname');
	}
	
	var theValue = document.getElementById('companyField').value;
	if(theValue == '') {
		valid = false;
		page.setFieldError('companyField');
	}
	
	var theValue = document.getElementById('email').value;
	if(theValue == '') {
		valid = false;
		page.setFieldError('email');
	}
	
	var theValue = document.getElementById('email').value;
	var theErr = theValue.search('@');
	if(theErr == -1) {
		valid = false;
		page.setFieldError('email');
	}
	
	// if it is valid, process submit, otherwise alert
	if(valid) {
		pctsFramework.alertTitle = "Submission response...";
		pctsFramework.alertBody = "Thank you for your request.  We value your interest and a qualified PCTS representative will respond to you shortly.";
		
		// submit the form
		page.submitContactForm();
		
		// show the result alert.  We do not actually check for
		// errors because it doesn't alter behavior in this case.
		pctsFramework.showAlert('');
		
	} else {
		pctsFramework.alertTitle = "Form error...";
		pctsFramework.alertBody = "You did not complete, or entered incorrect values for, one or more required fields.  Please try again.";
		window.scrollTo(0, 0);
		pctsFramework.showAlert('');
	}
	
}

page.submitContactForm = function() {
	// send the information in the cotact form to the server
	
	// package up the values from the form
	// first, fields
	var fname = document.getElementById('fname').value;
	var lname = document.getElementById('lname').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	var theCompany = document.getElementById('companyField').value;
	var title = document.getElementById('title').value;
	var department = document.getElementById('department').value;
	var city = document.getElementById('city').value;
	
	try {
		var zip = document.getElementById('zip').value;
		
	} catch(err) {
		var zip = '';
		
	}
	
	try {
		var depOtherField = document.getElementById('depOtherField').value;
		
	} catch(err) {
		var depOtherField = '';
		
	}
	
	var comment = document.getElementById('comment').value;
	comment = comment.replace(/\n/g,"<br/>").replace(/\r/g,"");
	
	// next, checkboxes
	var pulse = document.getElementById('pulse').checked;
	var trackPatients = document.getElementById('trackPatients').checked;
	var trackStaff = document.getElementById('trackStaff').checked;
	var enterpriseMedEquipment = document.getElementById('enterpriseMedEquipment').checked;
	var handHygiene = document.getElementById('handHygiene').checked;
	var depEmergency = document.getElementById('depEmergency').checked;
	var depPeriop = document.getElementById('depPeriop').checked;
	var depOutpatient = document.getElementById('depOutpatient').checked;
	var depCC = document.getElementById('depCC').checked;
	var depMedEquip = document.getElementById('depMedEquip').checked;
	var depOther = document.getElementById('depOther').checked;
	var docMD = document.getElementById('docMD').checked;
	var docRN = document.getElementById('docRN').checked;
	var docPaper = document.getElementById('docPaper').checked;
	var evalWF = document.getElementById('evalWF').checked;
	var evalRTLS = document.getElementById('evalRTLS').checked;
	
	// finally, select elements
	var theIndex = document.getElementById('suffix').selectedIndex;
	var theControl = document.getElementById('suffix');
	var theText = theControl[theIndex].text;
	var credential = theText;
	
	theIndex = document.getElementById('country').selectedIndex;
	theControl = document.getElementById('country');
	theText = theControl[theIndex].text;
	var country = theText;
	
	try {
		theIndex = document.getElementById('state').selectedIndex;
		theControl = document.getElementById('state');
		theText = theControl[theIndex].text;
		var state = theText;
		
	} catch(err) {
		
		var state = '';
	}
	
	// now that all values are collected, package a post statement
	var params = "fname=" + fname;
	params = params + "&lname=" + lname;
	params = params + "&email=" + email;
	params = params + "&phone=" + phone;
	params = params + "&company=" + theCompany;
	params = params + "&title=" + title;
	params = params + "&department=" + department;
	params = params + "&city=" + city;
	params = params + "&zip=" + zip;
	params = params + "&depOtherField=" + depOtherField;
	params = params + "&comment=" + comment;
	params = params + "&pulse=" + pulse;
	params = params + "&trackPatients=" + trackPatients;
	params = params + "&trackStaff=" + trackStaff;
	params = params + "&enterpriseMedEquipment=" + enterpriseMedEquipment;
	params = params + "&handHygiene=" + handHygiene;
	params = params + "&depEmergency=" + depEmergency;
	params = params + "&depPeriop=" + depPeriop;
	params = params + "&depOutpatient=" + depOutpatient;
	params = params + "&depCC=" + depCC;
	params = params + "&depMedEquip=" + depMedEquip;
	params = params + "&depOther=" + depOther;
	params = params + "&credential=" + credential;
	params = params + "&country=" + country;
	params = params + "&state=" + state;
	params = params + "&docMD=" + docMD;
	params = params + "&docRN=" + docRN;
	params = params + "&docPaper=" + docPaper;
	params = params + "&evalWF=" + evalWF;
	params = params + "&evalRTLS=" + evalRTLS;
	
	// now set an accessor to post the data
	var theAccessor = "../accessors/insertNewContact.php?region=1";
	
	// add a random number so as to prevent IE from using a chached accessor return
	var theRan = pctsFramework.randomNumber();
	theAccessor = theAccessor + "&anticache=" + theRan;
	
	pctsFramework.postData(theAccessor, params);
	
	// reset the form
	page.clearErrorStates(); 
	document.getElementById('contactForm').reset();
	
	// send a courtesy reply to the poster
	var theAccessor = "../mail/production/contactNotify.php?email=" + email + "&fname=" + fname + "&lname=" + lname + "&webinarmode=" + pctsFramework.webinarMode + "&webinartoken=" + pctsFramework.webinarToken;
	
	// add a random number so as to prevent IE from using a chached accessor return
	var theRan = pctsFramework.randomNumber();
	theAccessor = theAccessor + "&anticache=" + theRan;
	
	pctsFramework.getData(theAccessor);
	
	// send a note to PCTS employees that the contact request was made
	var theAccessor = "../mail/production/contactRequest.php?email=" + email + "&fname=" + fname + "&lname=" + lname + "&credential=" + credential + "&phone=" + phone + "&company=" + theCompany + "&title=" + title + "&dept=" + department + "&city=" + city + "&state=" + state + "&country=" + country + "&zip=" + zip + "&depOther=" + depOtherField + "&trackPatients=" + trackPatients + "&trackStaff=" + trackStaff + "&enterpriseMedEquipment=" + enterpriseMedEquipment + "&handHygiene=" + handHygiene + "&depEmerg=" + depEmergency + "&depPeriop=" + depPeriop + "&depOut=" + depOutpatient + "&depCC=" + depCC + "&depMedEquip=" + depMedEquip + "&pulse=" + pulse + "&comment=" + comment + "&docMD=" + docMD + "&docRN=" + docRN + "&docPaper=" + docPaper + "&evalWF=" + evalWF + "&evalRTLS=" + evalRTLS;
	
	// add a random number so as to prevent IE from using a chached accessor return
	var theRan = pctsFramework.randomNumber();
	theAccessor = theAccessor + "&anticache=" + theRan;
	
	pctsFramework.getData(theAccessor);
	
}

page.setFieldError = function(theId) {
	// set a field to an error state
	var theWidth = document.getElementById(theId).style.width;
	var theParts = theWidth.split('px');
	var wNum = theParts[0] * 1;
	
	// set the width to - 21px for error style offset
	if (document.getElementById(theId).className != "cInsetFormFieldErr") {
		document.getElementById(theId).style.width = (wNum - 21) + 'px';
	}
	
	// set the style
	document.getElementById(theId).className = "cInsetFormFieldErr";
	
}

page.clearErrorStates = function() {
	// clear the error states for the contact form
	
	// set the styles
	document.getElementById('fname').className = "cInsetFormField";
	document.getElementById('lname').className = "cInsetFormField";
	document.getElementById('email').className = "cInsetFormField";
	document.getElementById('companyField').className = "cInsetFormField";
	
	// set the widths
	document.getElementById('fname').style.width = "174px";
	document.getElementById('lname').style.width = "174px";
	document.getElementById('email').style.width = "174px";
	document.getElementById('companyField').style.width = "174px";
	
}

page.getData = function(theContentSource) {
	// ajax some data asynchronously, and return that data for evaluation

	// first, set up a request object.  We have to do this so it degrades gracefully for IE6
	if (window.XMLHttpRequest) {
		// this is IE7, safari, etc.
		var xmlhttp =  new XMLHttpRequest();

	} else {
		// this is probably IE6, so see if we can instantiate an activeX obejct
		if (window.ActiveXObject) {
     		var xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');

  		}
	}
	
	// wire up the callBack handler
	xmlhttp.onreadystatechange = function() {  
  		if(xmlhttp.readyState == 4) {   
			var theReturn = xmlhttp.responseText;
			// alert(theReturn);

			eval(theReturn);
			// eval(theReturn);	
		}
	};  

    // send the ajax request after the desired data
	xmlhttp.open('GET', theContentSource, true);
	xmlhttp.send(null);
}

page.presentContextMenu = function() {
	// handle attempts to access the context menu
	// alert('you clicked the right mouse button!');
	return false;
}

page.getPageLink = function() {
	// get a URL good for linking directly to the current page
	
	// first get whatever this URL is
	var theURL = window.location.href;
	
	// now split the press URL at the '&' symbol to get the basic link without the other parts.
	var theParts = theURL.split("&");
	var theURL = theParts[0];
	
	// now construct a URL to provide the desired diractAccess string
	// first split out the site URL
	
	// check to see if www is included in the URL
	var wwwFound = theURL.indexOf('http://www');
	
	// if not found, w use no site prefix
	if(wwwFound == -1) {
		var theParts = theURL.split("http://pcts.com/");
	} else {
		var theParts = theURL.split("http://" + pctsFramework.sitePrefix + ".pcts.com/");
		
	}
	
	var theURL = theParts[1];
	
	// now split out the framework mode tag
	var theParts = theURL.split("?frameworkState=true");
	var theURL = theParts[0];
	
	// now build a URL request string
	var theRequest = "http://" + pctsFramework.sitePrefix + ".pcts.com/" + theURL;
	
	// set up for presenting an alert
	pctsFramework.alertTitle = "Direct link...";
	pctsFramework.alertBody = "To link directly to this page, use the following URL...<br/><br/>" + theRequest;
	
	// if it is IE, copy the string to the clipboard for them
	if(pctsFramework.browserPath == 'ie') {
		// window.clipboardData.setData('text', theRequest);
		
		// add some data to the alertBody telling the user a copy has been made.
		// pctsFramework.alertBody = pctsFramework.alertBody + "<br/><br/>As a courtesy, this URL has been copied to your clip-board automatically.";
		
	}
	
	pctsFramework.showAlert();
	
}

page.getPressLink = function() {
	// get a URL good for linking directly to the current page
	
	// first get whatever this URL is
	var theURL = window.location.href;
	
	// now split the press URL at the '&' symbol to get the basic link without the other parts.
	var theParts = theURL.split("&");
	var theURL = theParts[0];
	
	// check to see if www is included in the URL
	var wwwFound = theURL.indexOf('http://www');
	
	// if not found, we use no site prefix
	if(wwwFound == -1) {
		var theParts = theURL.split("http://pcts.com/");
	} else {
		var theParts = theURL.split("http://" + pctsFramework.sitePrefix + ".pcts.com/");
		
	}
	
	var theURL = theParts[1];
	
	// now build a URL request string
	var theRequest = "http://" + pctsFramework.sitePrefix + ".pcts.com/" + theURL;
	
	// set up for presenting an alert
	pctsFramework.alertTitle = "Direct link...";
	pctsFramework.alertBody = "To link directly to this page, use the following URL...<br/><br/>" + theRequest;
	
	// if it is IE, copy the string to the clipboard for them
	if(pctsFramework.browserPath == 'ie') {
		// window.clipboardData.setData('text', theRequest);
		
		// add some data to the alertBody telling the user a copy has been made.
		// pctsFramework.alertBody = pctsFramework.alertBody + "<br/><br/>As a courtesy, this URL has been copied to your clip-board automatically.";
		
	}
	
	pctsFramework.showAlert();
	
}

page.setBookmark = function() {
	// set a bookmark for the page
	// get a URL good for linking directly to the current page
	
	// first get whatever this URL is
	var theURL = window.location.href;
	
	// now split the press URL at the '&' symbol to get the basic link without the other parts.
	var theParts = theURL.split("&");
	var theURL = theParts[0];
	
	// now construct a URL to provide the desired diractAccess string
	// first split out the site URL
	var theParts = theURL.split("http://www.pcts.com/");
	var theURL = theParts[1];
	
	// now build a URL request string
	var theRequest = "http://www.pcts.com?directLoad=" + theURL;
	
	// get the page title
	var theTitle = document.title;
	
	// set the bookmark
	window.external.AddFavorite(theRequest, theTitle);
	
}

page.showBookmarkLink = function() {
	// show the bookmark link, but only if this is IE
	
	if (pctsFramework.browserPath == 'ie') { 
		// if the element exists, show it
		if (document.getElementById('bookmarkControl')) {
			document.getElementById('bookmarkControl').style.display = 'block';
		}
	}
}

page.showSharePage = function() {
	// show the dialogue for sharing a page via various methods
	
	// get a URL good for linking directly to the current page
	
	// first get whatever this URL is
	var theURL = window.location.href;
	
	// now split the press URL at the '&' symbol to get the basic link without the other parts.
	var theParts = theURL.split("&");
	var theURL = theParts[0];
	
	// now construct a URL to provide the desired diractAccess string
	// first split out the site URL
	var theParts = theURL.split("http://www.pcts.com/");
	var theURL = theParts[1];
	
	// now build a URL request string
	pctsFramework.shareLink = "http://www.pcts.com/" + theURL;
	pctsFramework.pageTitle = document.title; 
	
	pctsFramework.windowTitle = "Share this page with others...";
	
	// now crank up the share dialogue
	pctsFramework.showWebWindow(390, 430, "../accessors/getSharePane.php");
	
}

// --- attached events -------

// we attach inside an if statement because IE handles event listeners differently from other browsers.

if (window.attachEvent) {
	// attached events for IE
	window.attachEvent("onload", page.evaluateSiteState);
	window.attachEvent("onload", page.evaluatePlatform);
	window.attachEvent("onload", page.setItemStyle);
	// window.attachEvent("onload", page.showBookmarkLink);
	
} else {
	// attached events for other browsers
	window.addEventListener('load', page.evaluateSiteState, false);
	window.addEventListener('load', page.evaluatePlatform, false);
	window.addEventListener('load', page.setItemStyle, false);
	// window.addEventListener('load', page.showBookmarkLink, false);

}