//---------------------------------------------------------------------------------------------------------------------\\
//                                                    Clearview Core Files                                             \\
//                                          Developed and Maintained by E-volution                                     \\
//---------------------------------------------------------------------------------------------------------------------\\
//  All code, images and data collected remains the property of AJ Parkes & Co and may not be edited, re-distributed   \\
//            copied or sold. All work is subject to copyright and infringement may result in legal action.            \\
//---------------------------------------------------------------------------------------------------------------------\\
//          Phone: 07 3349 7224     ---     Mobile: 0401 499 477     ---     E-mail: admin@e-volution.com.au           \\
//---------------------------------------------------------------------------------------------------------------------\\
//                                      Designer: Brent Wilkinson     Date: Mar, 2008                                  \\
//                                            ----- Javascript Functions -----                                         \\
//---------------------------------------------------------------------------------------------------------------------\\

//--- _CORE_siteLinker_MOVE --->>
// Moves partner_list div to match page bottom when scrolled
function _CORE_siteLinker_SET() {
	var obj				= document.getElementById('_CORE_siteLinker_partnerlist-div');
	obj.style.top		= (document.documentElement.clientHeight - 25) + 'px';
	obj.style.position	= 'fixed';
}

//--- _CORE_siteMaintenance_ALERT --->>
// Alerts user of sites undergoing maintenance from link bar and blocks access
function _CORE_siteMaintenance_ALERT(site) {
	alert('Sorry!\n\nThe ' + site + ' web site is currently undergoing maintenance.\n\nPlease check back soon....');
}

//--- _CORE_contact_FOCUS --->>
// Focuses on first name field in Contact form --->>
function _CORE_siteForm_FOCUS() {
	if(document.getElementById('enq_fname')) {
		document.getElementById('enq_fname').focus();
	}
}

//--- _CORE_error_FRIEND --->>
// Friendly joke message for error page finders --->>
function _CORE_error_FRIEND() {
	var message	= 'ADMINISTRATOR MESSAGE:\n'
				+ '------------------------------------------------------------------------------------------------------\n\n'
				+ 'Please don\'t fall for his antics! He has work to do....\n\n'
				+ 'Please come back again tomorrow....he may be able to play then.\n\n'
				+ 'Regards,\nThe Administrator (his boss).';
	alert(message);
}

//--- _CORE_siteClock_RUN --->>
// Recurring function to run and update clock display --->>
function _CORE_siteClock_RUN() {
	var today			= new Date();
	var time_variant	= "Standard Time";
					  
	var months 	= new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var days 	= new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	
	// Convert to 12 hour clock
	if(today.getHours() > 12) {
		var h		= today.getHours() - 12;
		var a		= "pm";
	}
	else {
		var h		= today.getHours();
		var a		= "am";
	}
	var m		= today.getMinutes();
	var s		= today.getSeconds();
	
	// add a zero in front of numbers < 10
	h			= _CORE_siteClock_TIME(h);
	m			= _CORE_siteClock_TIME(m);
	s			= _CORE_siteClock_TIME(s);
	
	// Output new time details to page
	document.getElementById('_CORE_siteClock_TIME').innerText	= "AEST " + h + ":" + m + ":" + s + a;
	document.getElementById('_CORE_siteClock_TIME').title		= days[today.getDay()] + " " + _CORE_siteClock_TIME(today.getDate()) + " " + months[today.getMonth()] + " " + today.getFullYear();
	
	setTimeout('_CORE_siteClock_RUN()',500);
}

//--- _CORE_siteClock_TIME --->>
// _CORE_siteClock_TIME(time number) --->>
// Converts all time variables to double digit (ie. numbers < 10) --->>
function _CORE_siteClock_TIME(i)
{
	if (i<10) {
		i="0" + i
	}
  	return i
}

//--- _CORE_document_ONLOAD --->>
// Processes _CORE_ startup functions for body component --->>
function _CORE_document_ONLOAD() {
	_CORE_siteForm_FOCUS();
	_CORE_siteClock_RUN();
	setTimeout("_CORE_siteLinker_SET();",100);
}

//--- _CORE_contact_EDITNAME --->>
//--- _CORE_contact_EDITNAME(user name input) --->>
// Adds name as signature at end of contact form --->>
function _CORE_contact_EDITNAME(sig)
{
	document.getElementById('contact_name').innerText	= sig + '.';
}

//--- _CORE_contact_CHECKMAIL --->>
//--- _CORE_contact_CHECKMAIL(email address) --->>
// Checks for suitable email address format --->>
function _CORE_contact_CHECKMAIL(email) {
	var AtPos 	= email.indexOf("@")
	var StopPos = email.lastIndexOf(".")
	
	if(AtPos < 1 || StopPos == -1) 
	{	return false;	}
	
	if (StopPos < AtPos) 
	{	return false;	}
	
	if (StopPos - AtPos == 1) 
	{	return false;	}
	
	if (StopPos == (email.length - 1)) 
	{	return false;	}
	
	var dom_ext	= new Array('.com','.co','.org','.net','.edu','.ca');
	
	for(a=0; a<dom_ext.length; a++)
	{
		var ExtPos	= email.indexOf(dom_ext[a]);
		if(ExtPos != -1)
		{	return true;	}
	}
	
	return false;
}

//--- _CORE_contact_SUBMIT --->>
// Checks user data is suiatbel for sending and enables send button --->>
function _CORE_contact_SUBMIT()
{
	var checks	= new Array('enq_fname','enq_lname','enq_enquiry','enq_email');

	for(a=0;a<checks.length;a++) {
		if(document.getElementById(checks[a]).value == '' || document.getElementById(checks[a]).value == ' ') {
			document.getElementById('send').disabled 			= true;
			document.getElementById('button_note').innerText	= '(button enabled when message is complete)';
			return false;
		}
	}
	if(_CORE_contact_CHECKMAIL(document.getElementById('enq_email').value)) {
		document.getElementById('send').disabled 			= false;
		document.getElementById('button_note').innerText	= 'Your message is ready to be sent....';
		return true;
	}
	document.getElementById('send').disabled 			= true;
	document.getElementById('button_note').innerText	= '(button enabled when message is complete)';
	return false;
}

//--- _CORE_contact_CLEARTEXT --->>
//--- _CORE_contact_CLEARTEXT(textarea element) --->>
// Clears text when user focuses on textarea - changes back to default content if left blank --->>
function _CORE_contact_CLEARTEXT(el)
{
	if(event.type == 'focus' && el.value == 'Add comments here....')
	{	el.value = '';		}
	
	else if(event.type == 'blur' && (el.value == '' || el.value == ' '))
	{	el.value = 'Add comments here....';		}
}

//--- _CORE_editor_APPEND --->>
// Append editor function collection to <head> if required --->>
function _CORE_editor_APPEND(func) 
{
	if(func == 'start') {
	// e-loading div
	// Application startup display
	eloadingbDiv 							= document.createElement('div');
	eloadingbDiv.id							= 'e-loaderb';
	eloadingbDiv.style.position				= 'fixed'; 
	eloadingbDiv.style.zIndex				= '198'; 
	eloadingbDiv.style.left					= '0px'; 
	eloadingbDiv.style.top					= '0px';  
	eloadingbDiv.style.width				= document.documentElement.clientWidth + 'px'; 
	eloadingbDiv.style.height				= document.documentElement.clientHeight + 'px';
	eloadingbDiv.style.filter				= 'Alpha(Opacity=50)';
	eloadingbDiv.style.backgroundColor		= '#333333';
	document.body.appendChild(eloadingbDiv);
	
	var loadtext							= '<img src="sys/apps/siteEditor/img/clearView_loading_logo.png" border="0" style="background:url(sys/apps/siteEditor/img/clearView_loading_logo.png) no-repeat;">'
											+ '<br><span style="font-size:10px;">Registered to AJ Parkes & Co Pty Ltd</span><br>&nbsp;<br>'
											+ '<span id="loading_response">Loading work site....</span><br>&nbsp;'
											+ '<table cellpadding="0" cellspacing="0" width="100%"><tr>'
											+ '<td align="left" valign="bottom">&copy; Copyright E-volution 2008</td>'
											+ '<td align="right" valign="bottom">Pre-Release Version A</td>'
											+ '</tr></table>';
											
	var passtext							= '<img src="sys/apps/siteEditor/img/clearView_loading_logo.png" border="0" style="background:url(sys/apps/siteEditor/img/clearView_loading_logo.png) no-repeat;">'
											+ '<br><span style="font-size:10px;">Registered to AJ Parkes & Co Pty Ltd</span><br>&nbsp;<br>'
											+ '<span id="loading_response">siteEditor Login:</span>'
											+ '<table id="logtable" cellpadding="0" cellspacing="0">'
											+ '<tr><td align="right">User: </td><td align="left"><input type="text" id="loguser" value="" size="30"></td></tr>'
											+ '<tr><td align="right">Pass: </td><td align="left"><input type="password" id="logpass" value="" size="30"></td></tr>'
											+ '</table><br>&nbsp;'
											+ '<table cellpadding="0" cellspacing="0" width="100%"><tr>'
											+ '<td align="left" valign="bottom">&copy; Copyright E-volution 2008</td>'
											+ '<td align="right" valign="bottom">Pre-Release Version A</td>'
											+ '</tr></table>';
	// e-loading div
	// Application startup display
	eloadingDiv 							= document.createElement('div');
	eloadingDiv.id							= 'e-loader';
	eloadingDiv.style.position				= 'fixed'; 
	eloadingDiv.style.zIndex				= '199'; 
	eloadingDiv.style.left					= ((document.documentElement.clientWidth-400)/2) + 'px'; 
	eloadingDiv.style.top					= ((document.documentElement.clientHeight-225)/2) + 'px';  
	eloadingDiv.style.width					= '400px'; 
	eloadingDiv.style.height				= 'auto'; 
	eloadingDiv.style.textAlign				= 'center';
	eloadingDiv.style.filter				= 'Alpha(Opacity=85)';
	eloadingDiv.style.fontFamily			= '"MS Reference Sans Serif", Arial';
	eloadingDiv.style.fontSize				= '11px';
	eloadingDiv.style.backgroundColor		= '#FFFFFF';
	eloadingDiv.style.color					= '#333333';
	eloadingDiv.style.padding				= '12px 3px 2px 3px';
	eloadingDiv.style.border				= '1px solid #999999';
	eloadingDiv.style.letterSpacing			= '-1px';
	eloadingDiv.innerHTML					= '<img src="sys/apps/siteEditor/img/clearView_loading_logo.png" border="0" style="background:url(sys/apps/siteEditor/img/clearView_loading_logo.png) no-repeat;">'
											+ '<br><span style="font-size:10px;">Registered to AJ Parkes & Co Pty Ltd</span><br>&nbsp;<br>'
											+ '<span id="loading_response">siteEditor Login:</span>'
											+ '<table id="logtable" cellpadding="0" cellspacing="0">'
											+ '<tr><td align="right">User: </td><td align="left"><input type="text" id="loguser" value="" size="30" onkeyup="if(window.event.keyCode==13) { _CORE_editor_APPEND(\'login\'); }"></td></tr>'
											+ '<tr><td align="right">Pass: </td><td align="left"><input type="password" id="logpass" value="" size="30" onkeyup="if(window.event.keyCode==13) { _CORE_editor_APPEND(\'login\'); }"></td></tr>'
											+ '<tr><td align="center" colspan="2"><button style="letter-spacing:0px; cursor:pointer; font-size:10px;" onClick="_CORE_editor_APPEND(\'login\');">login</button></td></tr>'
											+ '</table><br>&nbsp;'
											+ '<table cellpadding="0" cellspacing="0" width="100%"><tr>'
											+ '<td align="left" valign="bottom">&copy; Copyright E-volution 2008</td>'
											+ '<td align="right" valign="bottom">Pre-Release Version 1.0</td>'
											+ '</tr></table>';
	document.body.appendChild(eloadingDiv);
	document.getElementById('loguser').focus();
	}
	else {
		var eloadingResponse					= document.getElementById('loading_response');
	
		if(document.getElementById('loguser').value == 'user' && document.getElementById('logpass').value == 'parkes') {
		
		document.getElementById('logtable').style.display	= 'none';
		eloadingDiv.style.top		= ((document.documentElement.clientHeight-200)/2) + 'px';
		eloadingResponse.innerText	= 'Loading work site....';
		
		while(!document.all) {
			
		}
		
		eloadingResponse.innerText	= 'Loading work site....done';
		
		
		setTimeout(		function () {
						eloadingResponse.innerText	= 'Initialising application....';
		
						setTimeout( 	function () {
										eloadingResponse.innerText	= 'Initializing application....done';
										newJS 						= document.createElement('script');
										newJS.type					= 'text/javascript';
										newJS.src					= 'sys/boot/js/core_editor_func.js';
										document.getElementsByTagName('head')[0].appendChild(newJS);
										eloadingResponse.innerText	= 'Loading function library....';
							
										setTimeout( 	function () {
														eloadingResponse.innerText	= 'Loading function library....done';
														newJS2 						= document.createElement('script');
														newJS2.type					= 'text/javascript';
														newJS2.src					= 'sys/boot/js/core_editor_ajax.js';
														document.getElementsByTagName('head')[0].appendChild(newJS2);
														eloadingResponse.innerText	= 'Loading ajax library....';
							
														setTimeout( 	function () {
																		eloadingResponse.innerText	= 'Loading ajax library....done';
																		newJS3 						= document.createElement('script');
																		newJS3.type					= 'text/javascript';
																		newJS3.src					= 'sys/boot/js/core_editor_load.js';
																		document.getElementsByTagName('head')[0].appendChild(newJS3);
																		},500);
														},500);
										},500);
						},100);
		}
		else {
			eloadingResponse.innerText	= 'Login failed....';
			document.getElementById('loguser').value 	= '';
			document.getElementById('logpass').value 	= '';
			document.getElementById('loguser').focus();
		}
	}
}

//--- Set event handling --->>
window.onresize =   function ()
					{
						setTimeout("_CORE_siteLinker_SET();",100);
					};
window.onload	= 	function ()
					{
						_CORE_document_ONLOAD();
						if(document.getElementById('e-win')) {
							//_CORE_editor_APPEND('start');
						}
					};
document.onkeydown	= function () 
					{	
						if(window.event.ctrlKey && window.event.altKey && window.event.keyCode == 69) {
							if(document.getElementById('e-win')) {
								_CORE_editor_APPEND('start');
							}
							else {
								var page_ref	= location.href.match(/nav=([0-9]*)/i)[1];
								alert('Page Reference: #'+page_ref+'\n\nSorry! This page contains no editable content.\n\nContact the Administrator to request changes to this page....');
							}
						}
					};