$('html').addClass('js');

var chosensource;
var giLoggedIn;
var giGalleryLoaded = 0;
var iAdmin = -1;
var gsCurrentDoc = '';

var gsLoadingXHTML = '<img src="/site/1362/ajax-loader.gif">';

$(function() 
{	
	//MAKE A BUTTON LOOK LIKE A BUTTON
	$("button").button();
	
	//LOAD GALLERY CONTENT
	GalleryPreview();

	//CHECK IF ON THE LOGON PAGE
	if(msOnDemandDocumentId == 37972 || msOnDemandDocumentId == 39139)
	{
		var sParam = 'method=SITE_IS_LOGGED_ON&site=' + msOnDemandSiteId;
		var sReturn = onDemandSite(sParam);
		//CHECK IF A USER IS LOGGED IN
		if (sReturn == 'OK|OK')
		{
			giLoggedIn = 1;
			if(giGalleryLoaded == 0)
			{
				LoadContent();
			}
			$($(this).attr('href')).fadeIn('250');
		}
		else
		{
			$($(this).attr('href')).fadeIn('250');
			//ASK THE USER TO LOGIN
			$('#loginButton').click(function(event)
			{
				//SET Logon bind
				Logon();
			})
		}
	}
	
	//CHECK IF ON THE UPLOAD PAGE
	if(msOnDemandDocumentId == 38016)
	{
		var sParam = 'method=CORE_GET_USER_NAME';
	
			//GET USER NAME AND HENCE CHECK IF THEY ARE LOGGED ON
			$.ajax(
			{
				type: 'GET',
				url: '/directory/ondemand/object.asp?' + sParam,
				dataType: 'text',
				async: false,
				cache: false,
				success: function(data, textStatus, XMLHttpRequest) 
				{
					sReturn = data;
					var aValues = sReturn.split('|');

					if( aValues[0] == 'ER')
					{
						$('#loginButton').click(function(event)
						{
							//SET Logon bind
							Logon();
						})
					}
					else
					{
						giLoggedIn = 1;
						//CHECK FOR NICKS LOGIN
						ShowAdminHome();
						if(aValues[7] == '24633')
						{
							iAdmin = 1;
							ShowDocumentList();
						}
						SearchDocumentContent('38017');
					}	
				}
			})
	}

	$("body").delegate("li a", "click", function(e)
	{	
			/*e.preventDefault();*/
			if($(this).text() == 'Lectures' || $(this).text() == 'Clinical Cases' || $(this).text() == 'Services' || $(this).hasClass('preview'))
			{
				e.preventDefault();
				if($(this).text() == 'Clinical Cases')
				{
					$('#treatmentsub').slideDown();
				}
				if($(this).text() == 'Lectures')
				{
					$('#treatmentsub').slideDown();
				}
				if($(this).text() == 'Services')
				{
					$('#servicesub').slideDown();
				}			
			}
			else
			{
				/*if($(this).text() == 'Contact')
				{
					window.location.href = '/contact'
				}
								
				if($(this).text() == 'Home')
				{
					window.location.href = '/'
				}
				
				if($(this).text() == 'Upcoming')
				{
					window.location.href = '/upcominglectures'
				}
				
				if($(this).text() == 'Archive')
				{
					window.location.href = '/archivelectures'
				}
				
				if($(this).text() == 'Dentist')
				{
					window.location.href = '/dentist'
				}
				
				if($(this).text() == 'Hygienist')
				{
					window.location.href = '/hygienist'
				}
				
				if($(this).text() == 'Sedation Methods')
				{
					window.location.href = '/sedation'
				}
				
				if($(this).text() == 'Whitening')
				{
					window.location.href = '/whitening'
				}
				
				if($(this).text() == 'Implant')
				{
					window.location.href = '/implants'
				}*/
				
				//$('#treatmentsub, #lecturesub, #servicesub').slideUp();
			}
		});	
		
		$("body").delegate(".sedlink", "mouseenter", function()
		{	
			$(this).css('cursor', 'pointer');
			$(this).css('color','#71A8C4');
		})
		
		$("body").delegate(".sedlink", "click", function()
		{	
			if($(this).hasClass('halcion'))
			{
				$('#halcion').dialog({
					resizable : false,
					modal: true,
					height: 600,
					width: 450			
				});
			}
			
			if($(this).hasClass('sleep'))
			{
				$('#sleep').dialog({
					resizable : false,
					modal: true,
					height: 250,
					width: 450			
				});
			}
		})
		
		$("body").delegate("#submitcontact", "click", function(e)
		{
			if(ValidateForm())
			{
				SubmitEnquiry();
			}
		});
		
		$("body").delegate(".sedlink", "mouseleave", function()
		{	
			$(this).css('color','#2E5C9A');
		})
		
		$("body").delegate("li a", "mouseenter", function()
		{	
			if($(this).text() == 'Clinical Cases' || $(this).text() == 'Implant')
			{
				$('#treatmentsub').show();
			}
			else
			{
				$('#treatmentsub').hide();
			}	
			if($(this).text() == 'Lectures' || $(this).text() == 'Upcoming' || $(this).text() == 'Archive')
			{
				$('#lecturesub').show();
			}
			else
			{
				$('#lecturesub').hide();
			}
			if($(this).text() == 'Services' || $(this).text() == 'Dentist' || $(this).text() == 'Hygienist' || $(this).text() == 'Periodontist' || $(this).text() == 'Sedation Methods' || $(this).text() == 'Whitening')
			{
				$('#servicesub').show();
			}
			else
			{
				$('#servicesub').hide();
			}				
		});	
			
		$("body").delegate("li a", "mouseleave", function()
		{
			$('#treatmentsub, #lecturesub, #servicesub').hide();
		});
			
		$("body").delegate(".surgery .surgeryphoto", "click", function()
		{	
			if($(this).parent('.surgery').hasClass('chosen'))
			{
				//USER HAS SELECTED THE SAME CASE THEY ALREADY PICKED
			}
			else
			{
				//CHECK IF THIS IS A SECURED CASE
				if($(this).parent('.surgery').hasClass('secured'))
				{
					window.location.href = '/login';
				}
			$('.chosen').children('img').attr('src', chosensource);
			$('.surgery').removeClass('chosen');
			$('.history, .treatmentoptions, .treatmentcarriedout, .patientsexperience, .bottombuttons').fadeOut(200);
			var aChange = $(this).attr('src').split('-');
			chosensource = aChange[0] + '.jpg';
			$(this).parent().addClass('chosen');
			
			$(this).parents('.maindiv').children('.sidepaneldiv, .bottompaneldiv').fadeIn(250);	
			$(this).animate({height: "245px",
					width: "280px",
					}, 500);
			
			$('.chosen').children('.casebutton').hide();
			
			$(this).parent().animate({top: "60px",
									left: "20px",
									height: "650px",
									width: "770px"},500, function()
									{
										$('.chosen').children('.casebutton').hide();
										$('.chosen').children('.history, .treatmentoptions, .treatmentcarriedout, .patientsexperience, .bottombuttons').fadeIn(500);
									});
							
				//MOVE OTHER IMAGES 
				$(this).parent().siblings('.surgery:not(chosen)').each(function(index) {
					$(this).children('.casebutton').animate({top: "89px", width: "112px"
										},1000);
					$(this).children('.casebutton').children('img').animate({height: "9px", width: "112px"
										},1000);
					if(index == 0)
					{
						$(this).animate({top: "11px", 
										left: "820px",
										height: "98px",
										width: "112px"},1000);
						}
						if(index == 1)
						{
							$(this).animate({top: "131px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 2)
						{
							$(this).animate({top: "251px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 3)
						{
							$(this).animate({top: "371px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 4)
						{
							$(this).animate({top: "491px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
									
						$(this).children('img').animate({
							height: "98px",
							width: "112px",
							}, 1000, function(){
						});
				})
			}
		});	
		
		$("body").delegate(".surgery .casebutton", "click", function()
		{	
			if($(this).parent('.surgery').hasClass('chosen'))
			{
				//USER HAS SELECTED THE SAME CASE THEY ALREADY PICKED
			}
			else
			{
				//CHECK IF THIS IS A SECURED CASE
				if($(this).parent('.surgery').hasClass('secured'))
				{
					window.location.href = '/login';
				}
			$('.chosen').children('img').attr('src', chosensource);
			$('.surgery').removeClass('chosen');
			$('.history, .treatmentoptions, .treatmentcarriedout, .patientsexperience, .bottombuttons').fadeOut(200);
			var aChange = $(this).siblings('.surgeryphoto').attr('src').split('-');
			chosensource = aChange[0] + '.jpg';
			$(this).parent().addClass('chosen');
			
			$(this).parents('.maindiv').children('.sidepaneldiv, .bottompaneldiv').fadeIn(250);	
			$(this).siblings('.surgeryphoto').animate({height: "245px",
					width: "280px",
					}, 500);
			
			$('.chosen').children('.casebutton').hide();
			
			$(this).parent().animate({top: "60px",
									left: "20px",
									height: "650px",
									width: "770px"},500, function()
									{
										$('.chosen').children('.casebutton').hide();
										$('.chosen').children('.history, .treatmentoptions, .treatmentcarriedout, .patientsexperience, .bottombuttons').fadeIn(500);
									});
							
				//MOVE OTHER IMAGES 
				$(this).parent().siblings('.surgery:not(chosen)').each(function(index) {
					$(this).children('.casebutton').animate({top: "89px", width: "112px"
										},1000);
					$(this).children('.casebutton').children('img').animate({height: "9px", width: "112px"
										},1000);
					if(index == 0)
					{
						$(this).animate({top: "11px", 
										left: "820px",
										height: "98px",
										width: "112px"},1000);
						}
						if(index == 1)
						{
							$(this).animate({top: "131px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 2)
						{
							$(this).animate({top: "251px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 3)
						{
							$(this).animate({top: "371px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
						if(index == 4)
						{
							$(this).animate({top: "491px", 
											left: "820px",
											height: "98px",
											width: "112px"},1000);
						}
									
						$(this).children('img').animate({
							height: "98px",
							width: "112px",
							}, 1000, function(){
						});
				})
			}
		});	
		
		$("body").delegate(".surgery .casebutton", "mouseenter", function()
		{	
			//CHANGE BACKGROUND IMAGE TO THE COLOR VERSION
			$(this).css('cursor', 'pointer');
		});
		
		$("body").delegate(".surgery .surgeryphoto", "mouseenter", function()
		{	
			//CHANGE BACKGROUND IMAGE TO THE COLOR VERSION
			$(this).css('cursor', 'pointer');
			if($(this).parent().hasClass('chosen'))
			{
			
			}
			else
			{
				var aChange = $(this).attr('src').split('.');
				$(this).attr('src', aChange[0] + '-roll.jpg');
			}
		});
		$("body").delegate(".surgery .surgeryphoto", "mouseleave", function()
		{	
			if($(this).parent().hasClass('chosen'))
			{
			
			}
			else
			{
				var aChange = $(this).attr('src').split('-');
				$(this).attr('src', aChange[0] + '.jpg');
			}
		});
		
		$("body").delegate(".gallerylink", "click", function()
		{	
			var aID = $(this).attr('id').split('-');
		});	
		
		
		$("body").delegate(".gallerylink", "mouseenter", function()
		{	
			$(this).css('color','#2E5C9A');
			$(this).css('cursor', 'pointer');
		});	
		$("body").delegate(".gallerylink", "mouseleave", function()
		{	
			$(this).css('color','#FFFFFF');
		});	
		
		/*$("body").delegate(".caselink", "mouseenter", function()
		{	
			//CHANGE BACKGROUND IMAGE TO THE COLOR VERSION
			$(this).css('cursor', 'pointer');
			$(this).css('color','#71A8C4');
		});
		$("body").delegate(".caselink", "mouseleave", function()
		{	
			$(this).css('color','#2E5C9A');
		});*/
		
		$("body").delegate(".caselink", "click", function()
		{	
			//$('.maindiv:visible').hide();
			if($(this).hasClass('immediateplacement'))
			{
				$('#immediateplacement').fadeIn('250');
			}
			if($(this).hasClass('delayedplacement'))
			{
				$('#delayedplacement').fadeIn('250');
			}
			if($(this).hasClass('graftingcases'))
			{
				$('#graftingcases').fadeIn('250');
			}
			if($(this).hasClass('multipleimplantbridge'))
			{
				$('#multipleimplantbridge').fadeIn('250');
			}
			if($(this).hasClass('fullarch'))
			{
				$('#fullarch').fadeIn('250');
			}
			if($(this).hasClass('interesting'))
			{
				$('#interesting').fadeIn('250');
			}
		});
	
	
	/*if(msOnDemandDocumentId == 33939)
	{
		//BIND BUTTON TO CREATE DOCUMENT
		$('#addreport').click(function(event)
		{
			//CREATE NEW DOCUMENT FOR FILING
			AddReport();
		});
		
		$("body").delegate(".plus", "click", function()
		{
			alert("BIND");
			var aCount = $(this).attr('id').split('-');
			
			//SLIDE IT DOWN
			ShowUpload(0, aCount[1]);
		});		
			
	}*/
	
});

function Logon()
{
	$('#divLogonMessage').html("<p>Logging In...</p>");	
	var sUserName = $('#txtUserName').val();
	var sPassword = $('#txtPassword').val();
	$.ajax({
		type: 'POST',
		url: '/directory/ondemand/logon.asp?',
		dataType: 'text',
		async: false,
		cache: false,
		data: {"logon": sUserName, "password": sPassword },
		success: function(data, textStatus, XMLHttpRequest) 
		{
			if (data.substring(0, 2) == 'OK')
			{
				var aValues = data.split('|');
				if (aValues[0] == 'OK') 
				{
					if (unescape(aValues[1]) == "NO") 
					{
						if (aValues[2] == "LOGONFAILED")
						{
							$('#divLogonMessage').html("<p>Username or password is invalid<br /> Please re-enter your details.</p>");
						
						}
					}
					else 
					{
						$('#divLogonMessage').html("<p>Login Successful.</p>");	
						LoadContent();
					}
				}
			}
		}
	});
}

function LoadContent()
{
	/*$('#divLogonMessage').html('<p><img src="/site/1293/ajax-loader.gif" />&nbsp;Loading...</p>');	
	$('#immediateplacement').load('/implant-immediate');
	$('#delayedplacement').load('/implant-delayed');+
	$('#graftingcases').load('/implant-grafting');
	$('#multipleimplantbridge').load('/implant-multiple');
	$('#fullarch').load('/implant-full');
	$('#interesting').load('/implant-interesting', function() {*/
	if(msOnDemandDocumentId == 37972)
	{
		window.location.href = '/securedcases';
	}
	else if(msOnDemandDocumentId == 38016)
	{
		window.location.href = '/admin';
	}
	else if(msOnDemandDocumentId == 39139)
	{
		var aHTML = [];
		//BUILD UP THE LINKS FOR THE LECTURES
		aHTML.push('<table border="0" cellspacing="0" cellpadding="10" width="460">');
		aHTML.push('<tbody>');
		aHTML.push('<tr>');
		aHTML.push('<td style="text-align: center;">Implant Prosthodontics<a href="/site/1293/23092011-LectureC.pdf" target="_blank"><img style="display: block; margin-left: auto; margin-right: auto; border: medium none;" title="Dr Nicholas Hocking Implant Prosthodontics" src="/site/1293/implantprosthodontics.png" alt="Dr Nicholas Hocking Implant Prosthodontics" />View</a></td>');
		aHTML.push('<td style="text-align: center;">Materials Troubleshooting<a href="/site/1293/23092011-LectureD.pdf" target="_blank"><img style="display: block; margin-left: auto; margin-right: auto; border: medium none;" title="Dr Nicholas Hocking Materials Troubleshooting" src="/site/1293/materialslecture.png" alt="Dr Nicholas Hocking Materials Troubleshooting" width="150" height="113"/>View</a></td>');
		aHTML.push('</tr>');
		aHTML.push('<tr>');
		aHTML.push('<td style="text-align: center;">Impressions<br /><a href="/site/1293/23092011-LectureB.pdf" target="_blank"><img style="display: block; margin-left: auto; margin-right: auto; border: medium none;" title="Dr Nicholas Hocking Impressions" src="/site/1293/impressions.png" alt="Dr Nicholas Hocking Impressions" /></a><a style="text-align: center;" href="/site/1293/DrHockingImpressions.pdf" target="_blank">View</a></td>');
		aHTML.push('<td style="text-align: center;">Treatment Planning <br /><a href="/site/1293/23092011-LectureA.pdf" target="_blank"><img style="display: block; margin-left: auto; margin-right: auto; border: medium none;" title="Dr Nicholas Hocking Treatment Planning" src="/site/1293/treatmentplanning.png" alt="Dr Nicholas Hocking Treatment Planning" /></a><a style="text-align: center;" href="/site/1293/DrHockingTreatmentPlanning.pdf" target="_blank">View</a></td>');
		aHTML.push('</tr>');
		aHTML.push('</tbody></table>');
		
		$('.leftcolumn').html(aHTML.join(''));
	}
	//$('#implant').load('/implants', function (){Cufon.refresh();});
	
	//giGalleryLoaded = 1;
}

function GalleryPreview()
{
	tooltip();//active les tooltip simple
	imagePreview();//active les tooltip image preview
	screenshotPreview();//active les tooltip lien avec preview
}

function AddReport()
{
	$("#report").slideDown();
	ShowUpload(1);
}

function ShowUpload(iFirstOne, iCount)
{
	//iFirstOne will be 1 for the first Show of the Upload and 0 for the additional.
	if(iFirstOne == 1)
	{
		$("#fileupload").html(interfaceMasterAttachmentsUpload());
	}
	else
	{
		var i = iCount;
		//INJECT INPUT
		$('#plusinput-' + i).html('<input type="hidden" class="filetype" name="filetype' + i 
									+ '" 	id="filetype' + i + '" value="' + iAttachmentType + '">' +
									'<div style="display:none;" id="plusinput-' + i + '">&nbsp;</div>');
		
		
		//INJECT THE INTERFACE
	}
}

function SearchDocumentContent(document)
{
	var aDocument = document;
	//PERFORM AN ATTACHMENT SEARCH ON THE DOCUMENT
	var sParam = 'method=CORE_ATTACHMENT_SEARCH' +
						'&object=14' +  
						'&objectcontext=' + aDocument;
		$.ajax(
		{
			type: 'GET',
			url: '/ondemand/core/?' + sParam,
			dataType: 'json',
			success: function(asData) {
				ShowDocumentContent(asData, aDocument);
			}
		});
}

function ShowAdminHome()
{
	var aHTML = [];
	aHTML.push('<div id="divDocumentPage" class="interfaceMaster">');
	aHTML.push('<div id="editable">&nbsp;');
	aHTML.push('</div>');
	aHTML.push('<div id="type000">');
	aHTML.push('<p class="documenttype">All Files</p>');
	aHTML.push('<div class="docattachments">' + gsLoadingXHTML + '</div>');
	aHTML.push('</div>');
	
	$('.leftcolumn').html(aHTML.join(''));
}

function RemoveAttachment(attachment)
{
	//PERFORM AN ATTACHMENT SEARCH ON THE DOCUMENT
	var sParam = 'method=CORE_ATTACHMENT_MANAGE' +
						'&id=' + attachment + 
						'&remove=1';
		$.ajax(
		{
			type: 'GET',
			url: '/ondemand/core/?' + sParam,
			dataType: 'json',
			success: function(asData) {
				$('#del-' + attachment).parent('tr').remove();
			}
		});
}

function ShowDocumentList()
{
	var aHTML = [];
	aHTML.push('<table><tr><td>Document Name</td><td></td></tr>');
	aHTML.push('<tr><td>Home Content</td><td><span id="doc-34905" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Dr Hocking Info</td><td><span id="doc-34903" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Dr Hocking News Feed</td><td><span id="doc-34915" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Archived Lectures</td><td><span id="doc-34911" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Upcoming Lectures</td><td><span id="doc-34909" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Dentist</td><td><span id="doc-34958" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Hygienist</td><td><span id="doc-34946" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Sedation Methods</td><td><span id="doc-34957" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Whitening</td><td><span id="doc-37971" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('<tr><td>Refer a Patient</td><td><span id="doc-38225" class="edit">&nbsp;</span></td></tr>');
	aHTML.push('</table>');
	$('#editable').html(aHTML.join(''));
	
	$('.edit').button(
	{
		label: "Edit"
	})
	.click(function() 
	{
		var aDoc = $(this).attr('id').split('-');
		EditDocument(aDoc[1]);
	});	
}

function EditDocument(DocumentId)
{
	//tinyMCE.execCommand('mceRemoveControl', true, 'inputDocument');
	//BUILD UP THE DYNAMIC DIALOG
	var aHTML = [];
	aHTML.push('<table><tbody>' + 
			   '<tr><td><textarea rows="24" cols="35" onDemandType="TEXTMULTI" id="inputDocument" ></textarea></td></tr>' +
			   '</tbody></table>');
	$('#dynamicDialog').html(aHTML.join(''));
	
	$.ajax({
		type: 'GET',
		url: '/ondemand/document/' + '?method=DOCUMENT_SEARCH&includecontent=1&id=' + DocumentId,
		dataType: 'json',
		async: false,
		success: function(data, textStatus, XMLHttpRequest) 
		{
			var obj = data;
			
			if (obj.data.rows.length == 0)
			{
				$('#inputDocument').html('Content not found');
			}
			else
			{
				$.each(obj.data.rows, function(key, val) 
				{
					/*alert(this.content);*/
					$('#inputDocument').html(this.content);
					/*var sHTML = unescape(this.content);
					alert(sHTML);*/
				});	
			}		
			
		}
	});
		
	//SHOW THE DIALOG
	$('#dynamicDialog').dialog(
	{
		title: "Edit Document",
		resizable: true,
		height: 600,
		width: 800,
		modal: true,
		open: function() {
			setTimeout('addMCE()',250);
		},
		beforeclose: function(){
                    tinyMCE.execCommand('mceRemoveControl',false,'inputDocument');
        },
		buttons: {
			"Cancel": function() {
				$( this ).dialog( "close" );
			},
			"Save": function() {
				SaveDocument(DocumentId);
				$( this ).dialog( "close" );
			}
		}
	});
}

function addMCE()
{
	tinyMCE.execCommand('mceRemoveControl', false, 'inputDocument');
	
	tinyMCE.init(
					{
						mode : "none",
						height : "400px", 
						width : "750px",
						theme : "advanced",
						/*content_css : "/site/1293/1293_main.css",*/
						plugins : "table,advimage,advlink,emotions,iespell,insertdatetime,templateFields,preview,media,fullscreen,print,visualchars,nonbreaking,pagebreak,style,paste,searchreplace,print,contextmenu", 

						theme_advanced_buttons1_add_before : "forecolor,backcolor", 
						theme_advanced_buttons1_add : "fontselect,fontsizeselect", 
				 
						theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,nonbreaking,pagebreak,visualchars", 
						theme_advanced_buttons2_add_before: "cut,copy,paste,pasteword,separator,search,replace,separator", 
						
						theme_advanced_buttons3_add_before : "tablecontrols,separator", 
						theme_advanced_buttons3_add : "emotions,iespell,fullscreen,print,templateFields,media,selectall,advhr",
				 
						
						plugin_insertdate_dateFormat : "%d-%m-%y", 
						plugin_insertdate_timeFormat : "%H:%M:%S", 
					
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_resizing : true,
					
						font_size_style_values : "8pt,10pt,12pt,14pt,18pt,24pt,36pt",
						
						extended_valid_elements : "style,input[accept|accesskey|align<bottom?left?middle?right?top|alt|checked<checked|class|dir<ltr?rtl|disabled<disabled|id|ismap<ismap|lang|maxlength|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onselect|readonly<readonly|size|src|style|tabindex|title|type<button?checkbox?file?hidden?image?password?radio?reset?submit?text|usemap|value],select[class|dir<ltr?rtl|disabled<disabled|id|lang|multiple<multiple|name|onblur|onchange|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|size|style|tabindex|title],ol[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|start|style|title|type],div[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],li[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|type|value],iframe[src|width|height|name|align|frameborder|scrolling|marginheight|marginwidth]",

						fullscreen_new_window : true, 
						fullscreen_settings : 
						{ 
							theme_advanced_path_location : "top" 
						}, 
						relative_urls : false, 
						remove_script_host : false, 
						convert_urls : false, 
						visual : true, 
						gecko_spellcheck : true,
								
						/*external_link_list_url : "/jscripts/ibcom/linkList.asp", 
						external_image_list_url : "/jscripts/ibcom/imageList.asp?LinkType=14&LinkId=" + giObjectContext, 
						media_external_list_url : "/jscripts/ibcom/mediaList.asp?LinkType=14&LinkId=" + giObjectContext,  TemplateLinkType : "0", */

			});
	tinyMCE.execCommand('mceAddControl', false, 'inputDocument');
}

function SaveDocument(sDocId)
{
	var sParam = 'method=DOCUMENT_MANAGE';
	var sData = '_=1';
	
	sParam += '&select=' + sDocId	
		
	sData += '&details=' + encodeURIComponent(tinyMCE.get('inputDocument').getContent());
	
	$.ajax(
	{
		type: 'POST',
		url: '/directory/ondemand/object.asp?' + sParam,
		data: sData,
		dataType: 'text',
		async: false,
		success: function(data, textStatus, XMLHttpRequest) 
		{
			var aValues = data.split('|');
			if (aValues[2] == 'UPDATED') 
			{
				alert('Document has been updated.');
			}
			else
			{
				alert('There was a problem during the update');
			}
		}
	});
}

function ShowDocumentContent(data, document)
{
	var sNoFiles = '<table><tbody><tr><td>No files found.</td></tr></tbody></table>';
	
	var aHTML = [];
	
	var obj = data;
	
	if (obj.data.rows.length == 0)
	{
		aHTML.push(sNoFiles);
	}
	else
	{
		$.each(obj.data.rows, function(key, val) 
		{
			
			//CHECK FOR THE DIFFERENT FILE TYPES AND CREATE THE HEADINGS
			aHTML.push('<tr><td><a href="' + this.link + '" class="download">' + this.filename + '</a></td><td align="right">' + this.createddate + '<span class="deleteattachment" id="del-' + this.id + '"></span></td></tr>');
			
		})
	}
	
	//CHECK IF ANY OF THE FILES HAVE NO CONTENTS THEN PUSH THAT INTO THE ARRAY
	if(aHTML.length == 0)
	{
		aHTML.push(sNoFiles);
	}
	else
	{
		aHTML.unshift('<table width="100%" cellspacing="0"><tbody>');
		aHTML.push('</tbody></table>');
	}

	
	aHTML.push('<p><span id="uploadfile"></span><span id="uploadstatus"></span></p>');
	

	$('#type000 .docattachments').html(aHTML.join(''));

	if(iAdmin == 1)
	{
		$('#uploadfile').button({
				label: "Add File"
		}).
		click(function()
		{
			AddFile('38017');
		});
		
		/*$('.deleteattachment').button({
		text: false,
		icons: {
			primary: "ui-icon-close"
		},
		label: "Delete File"
		}).
		click(function()
		{
			if (confirm("Are you sure you want to Delete this file?")) { 
				$(this).parent('tr').fadeOut('slow');
				var aAttachID = $(this).attr('id').split('-');
				RemoveAttachment(aAttachID[1]);
			}
		});*/
	}
	
}

function AddFile(sDocId)
{
	$( "#upload" ).dialog({ 
		modal: true,
		height: 440,
		width: 400,
		title: 'Upload File',
		buttons: {
			Cancel: function() {
				$( this ).dialog( "close" );
				$(".interfaceUpload").val('');
			},
			Upload: function() {
				$('#linkid').val(sDocId);
				gsCurrentDoc = sDocId;
				//SPECIFY THE ATTACHMENT TYPE
				$('#uploadstatus').html('Uploading...' + gsLoadingXHTML);
				FileUpload();
				//REFRESH FOLDER STRUCTURE
				
				$( this ).dialog( "close" );
				$(".interfaceUpload").val('');
			}
		}
	});
}

function FileUpload()
{
	var oForm = document.frmonDemandFileUpload;
		 
	iOnDemandTimerCount = 0;
  	oForm.submit();
 	UpdateFileUpdateStatus();
	iOnDemandTimer = setInterval('UpdateFileUpdateStatus()', 1000);
}

function UpdateFileUpdateStatus()
{
	var oDivStatus = document.getElementById('divonDemandFileUploadStatus');
	var oFrame = document.getElementById('ifonDemandUpload');
	var sStatus;
	var sCurrentState;
 
	if (oFrame.readyState) 
	{
		//IE
		sCurrentState = oFrame.readyState;
	}
	else 
	{
		//FF
		if (oFrame.contentDocument.body.innerHTML == 'OK') 
		{
			sCurrentState = 'complete';
		}
		else 
		{
			sCurrentState = oFrame.contentDocument.body.innerHTML;
		}
	}
 
	if (sCurrentState == 'complete') 
	{
		$('#uploadstatus').html('Done.');
		//DO A REFRESH OF DOC CONTENT
		SearchDocumentContent(gsCurrentDoc);
		
		clearInterval(iOnDemandTimer);

		if (oDivStatus != null)
		{
			oDivStatus.setAttribute("class", "");
			oDivStatus.style.display = 'none';
		}
	}
}

function SubmitEnquiry()
{
	$('.state').html(gsLoadingXHTML + '&nbsp;Sending...');
	var sEmail = 'reception@nwhocking.com';
	var sMessage = 'An Enquiry has been made on the website with the following details:<br /><br/>' + 
					'Name: <strong>' + $('#name').val() + '</strong><br />' + 'Email: <strong>' + $('#message').val() + 
					'</strong><br />' + 'Phone: <strong>' + $('#telephone').val() + 
					'</strong><br />' + 'Message: <strong>' + $('#message').val() + '</strong><br />'
	var sSubject = 'New Enquiry from nwhocking.com';
	//http://www.nwhocking.com/directory/ondemand/site.asp?method=SITE_SEND_EMAIL&notemplate=1&site=1293&email=bernietoast@gmail.com&subject=HelloWorld!&message=Welcome%20to%20onDemand%20/%20AJAX!
	$.ajax(
	{
		type: 'GET',
		url: '/directory/ondemand/site.asp?method=SITE_SEND_EMAIL',
		dataType: 'text',
		data: 
		{
			"site": '1293',
			"subject": sSubject, 
			"message": sMessage,
			"email": sEmail			
		},
		success: function(data) {
			if(data = 'OK|OK')
			{
				$('.state').html('Enquiry has been sent, Thank you.');
				$('#name, #telephone, #message, #email').val('');
			}
		}
	});
	
}

function ValidateForm()
{
	var iRequired = 0;
	$('.required').each(function(index)
	{
		if($(this).val() == '')
		{
			iRequired = 1;
			$(this).addClass('ui-state-error');
		}
	});
	if(iRequired == 1)
	{
		alert('Please Enter details in the highlighted fields and try again.');
		return false;
	}
	else
	{
		return true;
	}
}



this.screenshotPreview = function(){
        /* CONFIG */

               xOffset = 700;
                yOffset = 30;

                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "" + this.t : "";
                $("#dynamic").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");
    },
        function(){
                this.title = this.t;
                $("#screenshot").remove();
    });
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });
};
this.imagePreview = function(){
        /* CONFIG */

                xOffset = 700;
                yOffset = 30;

                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.preview").hover(function(e){
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "" + this.t : "";
                $("#dynamic").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' /><br /><span class='caption'>"+ c +"</span></p>");
				/*$("#preview")
							.css("top",(e.pageY - xOffset) + "px")
							.css("left",(e.pageX + yOffset) + "px")
							.fadeIn("fast");*/
				$("#preview")
							.css("bottom", "135px")
							.css("left", "230px")
							.fadeIn("fast");
		},
        function(){
                this.title = this.t;
                $("#preview").remove();
    });
        $("a.preview").mousemove(function(e){
                	$("#preview")
							.css("bottom", "135px")
							.css("left", "230px");
        });
};
this.tooltip = function(){
        /* CONFIG */
                xOffset = 700;
                yOffset = 30;
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
        /* END CONFIG */
        $("a.tooltip").hover(function(e){
                this.t = this.title;
                this.title = "";
                $("#dynamic").append("<p id='tooltip'>"+ this.t +"</p>");
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");
    },
        function(){
                this.title = this.t;
                $("#tooltip").remove();
    });
        $("a.tooltip").mousemove(function(e){
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });
};

