// Common Scripts Used On All Pages //
// Version V1.0.0, 04/08/2007 WBM. //
// Copyright 2007. Property of Pip Consulting //
// Produced by Design Atom - www.designatom.com //

// Test for browser type
var strUserAgent = navigator.userAgent.toLowerCase();
var bolIExplorer = (document.getElementById && document.all); 
var bolNetscape = (document.getElementById && !document.all); 
var bolSafari = (strUserAgent.indexOf('applewebkit') != -1 ? 1 : 0);

// Status Bar Message
function fctStatusBar(strMessage){
	window.status = strMessage;
	return true;
}

// Pad Side Menus when Page is too long
function fctPadSides(){
	// Get the actual heights of the content areas
	intContentMain = document.getElementById('contentmain').offsetHeight;
	intContentLeft = document.getElementById('contentleft').offsetHeight;
	intContentRight = document.getElementById('contentright').offsetHeight;
	
	// Check if the Left side is shorter than the Middle or the Right
	if (intContentLeft < intContentMain || intContentLeft < intContentRight) {
		// Get the largest difference
		intDiff = Math.max(intContentMain - intContentLeft, intContentRight - intContentLeft)
		
		// Pad the Left to the same length
		document.getElementById('leftpad').style.height = document.getElementById('leftpad').offsetHeight + intDiff + 'px';
	}
	
	// Check if the Right side is shorter than the middle
	if (intContentRight < intContentMain || intContentRight < intContentLeft) {
		// Get the largest difference
		intDiff = Math.max(intContentMain - intContentRight, intContentLeft - intContentRight)
		
		// Pad the Right to the same length
		document.getElementById('rightpad').style.height = document.getElementById('rightpad').offsetHeight + intDiff + 'px';
	}
}

// Add this Website to the Users Favourites
function fctFavourites() { 
	// Set defaults
	var strTarget = "http://www.mycontent.co.uk/pipconsultancy/"; 
	var strTitle = "Pip Consultancy For All Recruitment Needs."; 
	
	// Check if users browser allows this facility
	if (window.external) { 
		window.external.AddFavorite(strTarget,strTitle) 
	} 
	else { 
		alert("Sorry! Your browser doesn't\nsupport this function."); 
	} 
} 

// Hide this website by shrinking this window and opening a new window in front
function fctHide() { 
	// Shrink this window to hide it
	window.resizeTo(100, 100)
	
	// Open a New Window to hide this one
	window.open("http://www.google.co.uk", "", "directories=yes, fullscreen=yes, menubar=yes, resizable=no, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes")
} 

// Show the selected map in a new window
function fctShowMap(strMap) { 
	// Open a New Window to hide this one
	myMap = window.open("../company/" + strMap, "Hinckley", "directories=no, width=600px, height=650px, menubar=no, resizable=no, scrollbars=yes, status=no, titlebar=yes, toolbar=no")
} 

// This function should be called from the initialisation function and run once when the page is loaded
// Change later to make functionality compatible with Netscape
function fctCheckDateTime() {
	// Check if this document has a date function embedded in it
	if(document.all.datedisplay != null) {
		// Date display object was found so retrieve format type
		var strDateFormat = document.all.datedisplay.formattype;
		
		// Get a formatted date and dispay it in the document
		var strDate = fctFormatDate(strDateFormat)
		document.all.datedisplay.innerText = strDate;
	}
	
	// Check if this document has a time function embedded in it
	if(document.all.timedisplay != null) {
		// Time display object was found so retrieve format type
		var strTimeFormat = document.all.timedisplay.formattype;
		
		// Get a formatted time and dispay it in the document
		var strTime = fctFormatTime(strTimeFormat)
		document.all.timedisplay.innerText = strTime;
	}
}

// Date Format. Used by the date display to return the current date in the specified format
function fctFormatDate(strFormat) {
	// Create a Date object
	var datNow = new Date();
	
	// Create and array of Months
	var arrMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	
	// Create an array of date values
	var arrDateValues = new Array("1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st");

	// Create an array of Weekdays
	var arrWeekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

	// Build a date in the selected format
	switch (strFormat) {
		case "1":
			// Format: dd/mm/yyyy
			strDate = datNow.getDate() + "/" + (datNow.getMonth()+1) + "/" + datNow.getFullYear();
			break;
		case "2":
			// Format: dd-mm-yyyy
			strDate = datNow.getDate() + "-" + (datNow.getMonth()+1) + "-" + datNow.getFullYear();
			break;
		case "3":
			// Format: dd/mm/yy
			strDate = datNow.getDate() + "/" + (datNow.getMonth()+1) + "/" + datNow.getFullYear().toString().substr(2,2);
			break;
		case "4":
			// Format: dd-mm-yyyy
			strDate = datNow.getDate() + "-" + (datNow.getMonth()+1) + "-" + datNow.getFullYear().toString().substr(2,2);
			break;
		case "5":
			// Format: dd monthname yyyy
			strDate = datNow.getDate() + " " + arrMonths[datNow.getMonth()] + " " + datNow.getFullYear();
			break;
		case "6":
			// Format: dd"st" monthname yyyy
			strDate = arrDateValues[datNow.getDate()-1] + " " + arrMonths[datNow.getMonth()] + " " + datNow.getFullYear();
			break;
		case "7":
			// Format: weekday, dd monthname yyyy
			strDate = arrWeekdays[datNow.getDay()] + ", " + datNow.getDate() + " " + arrMonths[datNow.getMonth()] + " " + datNow.getFullYear();
			break;
		case "8":
			// Format: weekday, dd"st" monthname yyyy
			strDate = arrWeekdays[datNow.getDay()] + ", " + arrDateValues[datNow.getDate()-1] + " " + arrMonths[datNow.getMonth()] + " " + datNow.getFullYear();
			break;
		default:
			strDate = datNow.getDate() + "/" + (datNow.getMonth()+1) + "/" + datNow.getFullYear();
	}
	// Return the formatted date	
	return strDate;
}

// Time Format. Used by the time display to return the current time in the specified format
function fctFormatTime(strFormat) {
	// Create a Date object
	var datNow = new Date();
	
	// Format for 12 hour clock
	var strPost = "am"
	var datHours = datNow.getHours();
	if (datHours > 12) {
		datHours -= 12;
		strPost = "pm";
	}
	
	// Pad Minutes and Seconds with leading zeros
	var strMinutes = datNow.getMinutes().toString();
	var strSeconds = datNow.getSeconds().toString();
	if (strMinutes.length == 1) strMinutes = "0" + strMinutes;
	if (strSeconds.length == 1) strSeconds = "0" + strSeconds;
	
	// Build a date in the selected format
	switch (strFormat) {
		case "1":
			// Format: hh:mm
			strTime = datNow.getHours() + ":" + strMinutes;
			break;
		case "2":
			// Format: hh:mm:ss
			strTime = datNow.getHours() + ":" + strMinutes + ":" + strSeconds;
			break;
		case "3":
			// Format: hh:mm am/pm
			strTime = datHours + ":" + strMinutes + " " + strPost;
			break;
		case "4":
			// Format: hh:mm:ss am/pm
			strTime = datHours + ":" + strMinutes + ":" + strSeconds + " " + strPost;
			break;
		default:
			strTime = datNow.getHours() + ":" + strMinutes;
	}
	
	// Return the formatted date	
	return strTime;
}

// Show the Selected Job Details in the Hidden Form
function fctShowJob(strJobID) {
	// Retrieve and Display the Job Title
	strJobTitle = document.getElementById('jobtitle' + strJobID).innerHTML
	document.getElementById('detailsjobtitle').innerHTML = strJobTitle
	
	// Retrieve and Display the Vacancy Location
	strLocation = document.getElementById('location' + strJobID).innerHTML
	document.getElementById('detailslocation').innerHTML = strLocation
	
	// Retrieve and Display the Salary Range
	strSalary = document.getElementById('salary' + strJobID).innerHTML
	document.getElementById('detailssalary').innerHTML = strSalary
	
	// Retrieve and Display the Job Description
	strDescription = document.getElementById('description' + strJobID).innerHTML
	document.getElementById('detailsdescription').innerHTML = strDescription
	
	// Retrieve and Display the Additional Benefits
	//strPackage = document.getElementById('package' + strJobID).innerHTML
	//document.getElementById('detailspackage').innerHTML = strPackage
	
	// Show the hidden details form
	document.getElementById('detail').style.visibility = 'visible'
	
	// Scroll the window so the form is fully visible
	window.scrollTo(0, 250)
	
	// Clip the form and then expand it
	document.getElementById('detail').style.clip = 'rect(0px, 0px, 0px, 0px)'
	fctExpandDetail(0,0)
}

// Hide the Selected Job Details
function fctHideJob() {
	// Shrink the vacancy detail form
	fctShrinkDetail(510,510)
}

// Show the Selected Candidate Details in the Hidden Form
function fctShowCandidate(strCandidateID) {
	// Retrieve and Display the Candidates Name
	strJobTitle = document.getElementById('candidatename' + strCandidateID).innerHTML
	document.getElementById('detailscandidate').innerHTML = strJobTitle
	
	// Retrieve and Display the Job Title
	strJobTitle = document.getElementById('jobtitle' + strCandidateID).innerHTML
	document.getElementById('detailsjobtitle').innerHTML = strJobTitle
	
	// Retrieve and Display the Candidates Location
	strLocation = document.getElementById('location' + strCandidateID).innerHTML
	document.getElementById('detailslocation').innerHTML = strLocation
	
	// Retrieve and Display the Candidates Description
	strDescription = document.getElementById('description' + strCandidateID).innerHTML
	document.getElementById('detailsdescription').innerHTML = strDescription
	
	// Show the hidden details form
	document.getElementById('detail').style.visibility = 'visible'
	
	// Scroll the window so the form is fully visible
	window.scrollTo(0, 250)
	
	// Bring the display window to the front
	document.getElementById('detail').style.zindex = 10;
	
	// Clip the form and then expand it
	document.getElementById('detail').style.clip = 'rect(0px, 0px, 0px, 0px)'
	fctExpandDetail(0,0)
}

// Hide the Selected Job Details
function fctHideCandidate() {
	// Shrink the vacancy detail form
	fctShrinkDetail(550,550)
}

// Expand the hidden detail form to its full size
function fctExpandDetail(width, height) {
	var intClipWidth = width + 10;
	var intClipHeight = height + 10;
	
	// Limit the width and height to their maximium dimensions
	intClipWidth = Math.min(intClipWidth, 550)
	intClipHeight = Math.min(intClipHeight, 550)
	
	// Set the new clipping dimensions
	document.getElementById('detail').style.clip = 'rect(0px, ' + intClipWidth + 'px, ' + intClipHeight + 'px, 0px)'
	
	//alert(intWidth)
	// Recall this function after a short delay
	if (intClipWidth<550 || intClipHeight<550) var tmrExpandDetail = setTimeout("fctExpandDetail(" + intClipWidth + "," + intClipHeight + ")", 1)
}

// Shrink the hidden detail form to its minimum size
function fctShrinkDetail(width, height) {
	var intClipWidth = width - 10;
	var intClipHeight = height - 10;
	
	// Limit the width and height to their minimum dimensions
	intClipWidth = Math.max(intClipWidth, 0)
	intClipHeight = Math.max(intClipHeight, 0)
	
	// Set the new clipping dimensions
	document.getElementById('detail').style.clip = 'rect(0px, ' + intClipWidth + 'px, ' + intClipHeight + 'px, 0px)'
	
	// Check if the form is completely shrunk
	if (intClipWidth>0 || intClipHeight>0) {
		// Recall this function after a short delay
		var tmrShrinkDetail = setTimeout("fctShrinkDetail(" + intClipWidth + "," + intClipHeight + ")", 1)
	}
	else {
		// Hide the details form when the form has been shrunk
		document.getElementById('detail').style.visibility = 'hidden'
	}
}


// Show the Selected Testimonial Details in the Hidden Form
function fctShowTestimonial(strTestimonialID) {
	// Retrieve and Display the Contacts Details
	strContact = document.getElementById('contact' + strTestimonialID).innerHTML
	document.getElementById('detailscontact').innerHTML = strContact
	
	// Retrieve and Display the Testimonial Details
	strDescription = document.getElementById('description' + strTestimonialID).innerHTML
	document.getElementById('detailsdescription').innerHTML = strDescription
	
	// Show the hidden details form
	document.getElementById('detail').style.visibility = 'visible'
	
	// Scroll the window so the form is fully visible
	window.scrollTo(0, 250)
	
	// Clip the form and then expand it
	document.getElementById('detail').style.clip = 'rect(0px, 0px, 0px, 0px)'
	fctExpandDetail(0,0)
}

// Hide the Selected Testimonial Details
function fctHideTestimonial() {
	// Shrink the vacancy detail form
	fctShrinkDetail(550,550)
}



// POP-UP TOOLTIP
// Display the tooltip corresponding to the element id that was passed
function fctShowTip(strTipid) {
	// Retrieve the tooltip text
	var tip = document.getElementById(strTipid).innerHTML;
	
	// Check if there is an existing tooltip and if not create one
	if(!document.getElementById('tooltip')) fctCreateTip('tooltip');
	
	// Retrieve the new tooltip container, set content and display it
	var objThisTooltip = document.getElementById('tooltip');
	objThisTooltip.innerHTML = tip;
	objThisTooltip.style.display = 'block';
	
	// Set the position of the tootip
	// Set the mousemove event to move the tooltip with the cursor
	document.onmousemove = fctPositionTip;
}

// Hide all tooltips
function fctHideTip() {
	// Hide all elements with the tootip class
	document.getElementById('tooltip').style.display = 'none';
}

// Create a new element (for display) using the tooltip class
function fctCreateTip(strNewTooltip) { 
	// Check if this browser provides support for creating new elements
	if(document.createElement) { 
		// Create a new element (div) to contain this tooltip
		var objNewElement = document.createElement('div'); 
	
		// Set the id for the new (tooltip) container
		objNewElement.id = strNewTooltip;     
			
		// Set style attributes for the tooltip container
		with(objNewElement.style) { 
			display = 'none';
			position = 'absolute';
		}
		
		// Set default content and add the container to the document (body) 
		objNewElement.innerHTML = '&nbsp;'; 
		document.body.appendChild(objNewElement); 
	} 
} 

// Calculate and set the position of the tooltip on the screen
function fctPositionTip(e) {
	// Tooltip position relative to the mouse 
	// This script is used for data entry forms and the x,y position is effected by other aspects of the page
	var intOffsetX = -320;
	var intOffsetY = -147;

	if(document.getElementById){
		var iebody=(document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
		
		// Retrieve the page offset for this document in relation to the screen
		intPageX = (bolSafari == 1 ? 0 : (bolIExplorer) ? iebody.scrollLeft : window.pageXOffset);
		intPageY = (bolSafari == 1 ? 0 : (bolIExplorer) ? iebody.scrollTop : window.pageYOffset);
		
		// Retrieve the current mouse position in relation to the top left corner of this document (page)
		intPosX = ((bolIExplorer) ? event.screenX : (bolNetscape) ? clientX = e.clientX : false);
		intPosY = ((bolIExplorer) ? event.screenY-110 : (bolNetscape) ? clientY = e.clientY : false);
		
		// Set the position of the tooltip relative to the current position of the mouse
		// This function is called on mousemove so the tooltip will track (move with) the mouse
		var objThisTooltip = document.getElementById('tooltip');
		objThisTooltip.style.left = (intPageX + intPosX + intOffsetX) + 'px';
		objThisTooltip.style.top = (intPageY + intPosY + intOffsetY) + 'px';
	}
}
