/*
-----------------------------------------------
 THIRTEEN website / JS CUSTOMER SITE FUNCTIONS
 Developed by Ollie Bettany / Thirteen
 Created: 17/11/08
 Updated: 17/12/08
-----------------------------------------------
*/		

// Open window

			function openWin(strUrl) {
				window.open(strUrl);
			}
			
			
// Go to URL

			function goToUrl(strUrl) {
				window.location = strUrl;
			}
			
			
// Display alert msg

			function displayMsg(strMsg) {
				strMsg = strMsg.replace(/<br>/g, '\n');
				alert(strMsg);
			}
			
			
// Confirm delete item

			function deleteItem() {
				tmp = confirm("Are you sure you want to delete this item? This will also delete all associated resources.");
				if (tmp == true) {
					document.getElementById('process').value = 'delete';
					submitForm();
				}
			}
			
// Submit form

			function submitForm() {
				document.form1.submit();
				return true;
			}
			

// Reload parent window from iframe

			function redirectParent(str_url) {
				parent.location.href = str_url;	
			}
		

// Reload iframe1 with new content based on query id
// and highlight associated 'WORK' subnav item

				function gotoContent(int_nav_id, int_action, int_sub_id, int_order_id, int_type) {
					
					//alert("Hello Team");
				
					var str_nav_id = document.getElementById('currentnav').value;
				
					var int_current_id = document.getElementById('navnum').value
					if (int_current_id != 0) {
						var str_current_id = 'nav' + int_current_id;
						document.getElementById(str_current_id).className = '';	
					}
						
					var int_currsub_id = document.getElementById('subnum').value
					if (int_currsub_id != 0) {
						var str_currsub_id = 'sub' + int_currsub_id;
						document.getElementById(str_currsub_id).className = '';	
					}
						
					if (int_nav_id > 0) {		
						
						if (int_action == 1) {
														
							var str_nav_id = 'nav' + int_nav_id;
							document.getElementById(str_nav_id).className = 'current';
							
							document.getElementById('navnum').value = int_nav_id;
							document.getElementById('subnum').value = 0;
							
						} else {
							
							var str_nav_id = 'nav' + int_nav_id;
							document.getElementById(str_nav_id).className = 'current';
							
							var str_sub_id = 'sub' + int_sub_id;
							document.getElementById(str_sub_id).className = 'current';
							
							document.getElementById('navnum').value = int_nav_id;
							document.getElementById('subnum').value = int_sub_id;
						}
						
						if (int_type == 1 || int_type == 3) {
							//alert("Hello World");
							document.getElementById('iframe1').src = '/content.php?id=' + int_nav_id + '&action=' + int_action + '&sid=' + int_sub_id + '&oid=' + int_order_id + '&type=' + int_type;
						}
						
					} else {
		
						document.getElementById('navnum').value = 0;
						document.getElementById('subnum').value = 0;
						
						if (int_type == 1) {
							window.frames[0].showhideFeature('show');
							//alert("Hello Dolly");
						}
					}		
				}
			

// Show/hide main nav items
		
			function displayNav(str_nav_id) {
				document.getElementById('currentnav').value = str_nav_id;
				
				document.getElementById('welcome-content').style.display = 'none';
				document.getElementById('about-content').style.display = 'none';
				document.getElementById('work-content').style.display = 'none';
				document.getElementById('contact-content').style.display = 'none';
				
				document.getElementById('about-link').className = '';
				document.getElementById('work-link').className = '';
				document.getElementById('contact-link').className = '';
				
				if (str_nav_id != 'none') {
					str_nav_content_id = str_nav_id + '-content';
					str_nav_link_id = str_nav_id + '-link';
				
					if (str_nav_content_id == 'welcome-content') {
						document.getElementById('main-nav').className = '';
					} else {
						if (str_nav_content_id == 'work-content' || str_nav_content_id == 'about-content') {
							document.getElementById('main-nav').className = 'no-borders';
						}
						if (str_nav_content_id == 'contact-content') {
							document.getElementById('main-nav').className = 'border-bottom';
						}
						document.getElementById(str_nav_link_id).className = 'current';	
					}
					document.getElementById(str_nav_content_id).style.display = 'block';
				} else {
					document.getElementById('welcome-content').style.display = 'block';
					document.getElementById('main-nav').className = '';
				}
				
				if (str_nav_id == 'work') {
					document.getElementById('content-div').style.display = 'none';
					document.getElementById('content-frame').style.display = 'block';
				} else {
					document.getElementById('content-div').style.display = 'block';
					document.getElementById('content-frame').style.display = 'none';
				}
			}
			
			
// Select specific item to view in content page
		
			function selectItem(int_imagenum, int_navblock) {
				
				document.getElementById('imagenum').value = int_imagenum;
				var int_imagetot = parseInt(document.getElementById('imagetot').value);
				
				for (i = 1; i <= int_imagetot; i++) {
					var str_img_id = 'image' + i;
					document.getElementById(str_img_id).style.display = 'none';
					var str_nav_id = 'imagenav' + i + '-' + int_navblock;
					document.getElementById(str_nav_id).className = '';
				}	
				
				var str_img_id = 'image' + int_imagenum;
				document.getElementById(str_img_id).style.display = 'block';
				var str_nav_id = 'imagenav' + int_imagenum + '-' + int_navblock;
				document.getElementById(str_nav_id).className = 'current';	
				
				var prev_link_id = 'prev-link' + int_navblock;
				var next_link_id = 'next-link' + int_navblock;
					
				if (int_imagenum == 1) {
					document.getElementById(prev_link_id).className = 'inactive';
				} else {
					document.getElementById(prev_link_id).className = '';
				}
					
				if (int_imagenum == int_imagetot) {
					document.getElementById(next_link_id).className = 'inactive';
				} else {
					document.getElementById(next_link_id).className = '';
				}	
			}
			

// Move to previous/next content item
			
			function prevnextItem(str_action, int_navblock) {
				var int_imagenum = parseInt(document.getElementById('imagenum').value);
				var int_imagetot = parseInt(document.getElementById('imagetot').value);
				var int_imagenew;
				var changeState = false;
				
				if (int_imagenum != 1 && str_action == 'prev') {
					int_imagenew = int_imagenum - 1;
					changeState = true;
				}
				
				if (int_imagenum != int_imagetot && str_action == 'next') {
					int_imagenew = int_imagenum + 1;
					changeState = true;
				}
				
				if (changeState == true) {	
					var prev_link_id = 'prev-link' + int_navblock;
					var next_link_id = 'next-link' + int_navblock;
					
					if (int_imagenew == 1) {
						document.getElementById(prev_link_id).className = 'inactive';
					} else {
						document.getElementById(prev_link_id).className = '';
					}
					
					if (int_imagenew == int_imagetot) {
						document.getElementById(next_link_id).className = 'inactive';
					} else {
						document.getElementById(next_link_id).className = '';
					}
						
					document.getElementById('imagenum').value = int_imagenew;
													
					var str_imgnew_id = 'image' + int_imagenew;
					document.getElementById(str_imgnew_id).style.display = 'block';
					var str_imgnewnav_id = 'imagenav' + int_imagenew + '-' + int_navblock;
					document.getElementById(str_imgnewnav_id).className = 'current';
					
					var str_img_id = 'image' + int_imagenum;
					document.getElementById(str_img_id).style.display = 'none';
					var str_imgnav_id = 'imagenav' + int_imagenum + '-' + int_navblock;
					document.getElementById(str_imgnav_id).className = '';
				}
			}
			

// Check querystring for preview mode variables
			
			function getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");

				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");

					if (pair[0] == variable) {
						return pair[1];
					}
				}
			}	
			
			
// Display work content onload in preview mode

			function activateWorkContent(int_type) {
				var int_client_id = 0;
				var int_other_id = 0;
				var int_sub_id = 0;
				var int_order_id = 0;
				
				if (int_type == 1) {
					var int_work_id = getQueryVariable("wid");
						
					if (int_work_id == undefined) {
						
						var int_client_id = getQueryVariable("cid");
						var int_order_id = getQueryVariable("oid");
						var int_sub_id = getQueryVariable("sid");
							
						if (int_sub_id != int_client_id) {
							int_other_id = 2;
						} else {
							int_other_id = 1;
						}
					}
				} else {
					var int_parent_id = document.getElementById('parentid').value;
					
					if (int_parent_id != 0) {
						int_client_id = int_parent_id;
						int_sub_id = document.getElementById('clientid').value;
						int_other_id = 2;
					} else {
						int_client_id = document.getElementById('clientid').value;
						int_sub_id = 0;
						int_other_id = 1;
					}	
				}
				gotoContent(int_client_id, int_other_id, int_sub_id, int_order_id, 3);
				var timer = setTimeout("displayNav('work')", 500);
			}
			
	