//====================================
// ==============================================================
//  Interactive 3D Portfolio: CMS - Globals
// ==============================================================
//====================================

// V. 1.00

// "Interactive 3D Portfolio" content mangement system allows either
// a veteran or a aspiring 3D artist to quickly create and customize
// an efficient interactive portfolio website. It is meant to act
// like a reel with options. Any person viewing your interactive
// reel will be able to quickly identify your skillsets because of its
// easability in use. This often keeps the viewers attention rather than
// getting bored of a simple video reel and giving you no more than 30
// seconds of their time.

// (c)Snc Design - Quality Graphics and Code - [www.sncdesign.net]

// Notes: This document contains most of the dynamic effects and functions 
// of this website.

// ========================================
//  Force PDF Download
// ========================================

function download(i)
{
	var downloadWindow = window.open('download.php?filename=' + i,'Download', "height=0, width=0, menubar=0, scrollbars=0, status=0, toolbar=0, location=0");
}

// ========================================
//  Unhide Boxes
// ========================================
function uploadBoxes()
{
	if (document.getElementById('advancedWin').checked == true)
	{
		document.getElementById('hiddenfields').innerHTML = 
		'Color Turn-around: <input name="colorFile" type="file"><font size="2" color="707070">(FLV/SWF)</font><p>' +
		'Wire  Turn-around: <input name="wireFile" type="file"><font size="2" color="707070">(FLV/SWF)</font><p>' +
		'Clay  Turn-around: <input name="clayFile" type="file"><font size="2" color="707070">(FLV/SWF)</font><p>';
	}
	else
		document.getElementById('hiddenfields').innerHTML = '';
		
}
// ========================================
//  Update Contact Form
// ========================================
function mailResult(response)
{
	document.getElementById('mail_result').innerHTML = response;
      	document.getElementById('f1_upload_process').innerHTML = '';
}

// ========================================
//  Contact Form Validation
// ========================================
function validate(mainform) 
{
	var mNve    = document.mainform.Email.value;
	var mNvp    = document.mainform.Phone.value;
	var mNvm    = document.mainform.Message.value;
	var f       = '2';
	var phone   = new RegExp(/^\d{3}-\d{3}-\d{4}$/);
	var email   = new RegExp(/^[-._&0-9a-zA-Z]+[@][-._&0-9a-zA-Z]+[.][._0-9a-zA-Z]+[a-zA-Z]$/);

	if (((mNve == '') || (!email.test(mNve)))  && ((mNvp == '') || (!phone.test(mNvp))))
	{
		alert('Please enter either your phone number, your email or both so I can respond to your message. Please ensure that it is in a correct format.');
		f = '1';
	}

	if ((mNvm == '') || (mNvm == 'You must enter a message before submitting.') || (mNvm == 'Enter Message Here.'))
	{
		alert('You must enter a message.');
		document.mainform.Message.value = 'Enter Message Here.'
		f = '1';
	}

	if (f == '1')
	{
		return false;
	}

      	document.getElementById('f1_upload_process').innerHTML =
	'<table><tr><td><img src="images/animated/loading.gif"></td><td class="whitetext">Working...</td></tr></table>';
	return true;
}

//Mouse over submit button when nothing is filled in displays error.
function mouseovervalidate() 
{
	var mNvm = document.mainform.Message.value;

	if ((mNvm == '') || (mNvm == 'Enter Message Here.'))
	{
		document.mainform.Message.value = 'You must enter a message before submitting.'
	}
}

//Mouse leaves submit button when nothing is filled in displays error.
function clearform() 
{
	var mNvm = document.mainform.Message.value;

	if (mNvm == 'You must enter a message before submitting.')
	{
		document.mainform.Message.value = ''
	}
}

// ========================================
//  Send necessary data to the Flash Banner
// ========================================
function addBanner()
{
	var soOne = new SWFObject('images/applets/header.swf','firstmovie','100%','200', '8', '#276985');
  	soOne.addParam('allowfullscreen','false');
  	soOne.addParam('wmode','transparent');
  	soOne.addParam('scale','noscale');
 	soOne.addVariable('autostart','true');
 	soOne.write('flashbanner');
}

// ================================
//  Log Out and Destroy Cookies
// ================================

function logOut()
{
	document.cookie = "remember_me=false; expires=15/02/2020 00:00:00";
	window.loggedin = 0;
	loadContent("content");
	winLaunch('dynamicForm');
}

// =================================
//  Key Press Check
// =================================

function checkEnter(event)
{    
	NS4 = (document.layers) ? true : false; 
	var code = 0;
    
	if (NS4)
        	code = event.which;
    	else
        	code = event.keyCode;
   	if (code==13)
        	ajaxPassCheck();
}

// =================================
//  Commence upload/Show loading bar
// =================================

function startUpload()
{
      	document.getElementById('f1_upload_process').innerHTML =
	'<table><tr><td><img src="images/animated/loading.gif"></td><td class="whitetext">Working...</td></tr></table>';
	winLaunch('f1_upload_process');
	return true;
}

// =================================
//  Update File upload Progress
// =================================

function stopUpload(success, alternatesuccess)
{
	if ((success == 3) || (success == 2))
	{
		document.getElementById('f1_upload_process').innerHTML =
		'The item has been added/edited successfully.';
		if (alternatesuccess == 1)
		{
			setTimeout("clearinfo()", 1000);
		}
		else
		{
			setTimeout("clearinfo_i()", 1000);
		}

	}
	else if (success == 5)
	{
		document.getElementById('f1_upload_process').innerHTML =
		'The custom thumbnail you have attempted to upload is not 40x90 pixels.';
	}
	else if (success == 6)
	{
		document.getElementById('f1_upload_process').innerHTML =
		'You have uploaded a file that is not in JPEG format.<br /> Uploaded files must be in JPEG format else thumbnails result in loss of color and quality.';
	}
      	else 
	{
      		document.getElementById('f1_upload_process').innerHTML =
		'There was an error during your file upload! Be sure to verify a few things:<br /> 1. Your upload folders are CHMOD 777 <br />2. You are not having connection problems.<br />3. Make sure you attach a file before pressing OK.<br /> 4. Make sure your attached file is under 100MB.';
	}
	if ((success != 3) || (success != 2))
 	setTimeout("expire()", 6000);
}
// =================================
//  Remove an effect after a while
// =================================

function expire() 
{ 
	winLaunch('f1_upload_process');
}
function sadvancedwin() 
{ 
	winLaunch('advancedwin');
}
function clearinfo()
{
	document.getElementById('f1_upload_process').innerHTML = "";
	winLaunch('dynamicForm');
	setTimeout("reloadcontent()", 100);
}
function clearinfo_i()
{
	loadContent("content");
	document.getElementById('f1_upload_process').innerHTML = "";
	winLaunch('dynamicForm');
}
function reloadcontent()
{
	var suid = document.getElementById('suid').value;
	loadContent("item", suid);
}
function closeform()
{
	winLaunch('dynamicForm');
	enlargeImage(0);
	addPreviewer();
}

// =================================
//  Launch an Item
// =================================

function itemLaunch(lights, image, desc, md5name, uid, suid, id, swfname)
{
	winLaunch('bgwin');
	loadContent("item", suid);
	document.getElementById('windowtitle').innerHTML = "<img src=\"images/temp/items/titles/" + md5name + "\">";
	document.getElementById('swftoload').value = swfname;
	document.getElementById('windowdescription').innerHTML = desc;
	setTimeout("sadvancedwin()", 1000);
}

// =================================
//  Close an Item
// =================================
// There is a conflict between lightbox
// and js flash embedding. To prevent issues
// I write an empty string to where the
// flash was placed when the window is closed.

function itemClose()
{
	document.getElementById('imagepreviewer').innerHTML = "";
	document.getElementById('flashbanner').innerHTML = "";
	winLaunch('bgwin');
	winLaunch("advancedwin");
}

// =================================
//  Read Extended redundant naming convention params
// =================================
function returnValues(i)
{
	var str    = i.substr(0,2);
	if(str == "i_")
	{
		var suid    = document.getElementById("suid").value;
		var prepend = '&prepend=i_&suid=' + suid;
		var type    = 'i_functions';
		i           = i.substr(2);
	}
	else
	{
		str	    = '';
		var prepend = '';
		var type    = 'functions';
	}

	return [str,prepend,type,i];
}

// =================================
//  Initiates Admin Options
// =================================

function adminTools(condition)
{
	if (condition == "item")
		var prepend = "i_";
	else
		var prepend = "";
	//Category Admin options
	id = document.getElementById(prepend + 'catcount').value;
	for(i=1;i<=id;i++)
	{
		i_id = document.getElementById(prepend + 'itemcount' + i).value;
		document.getElementById(prepend + 'ajaxCat' + i).innerHTML = '<a href="#" title="Move Category Up"><img id="' + prepend + 'movecat' + i
		+ '" src="images/admin/moveup.gif" alt="Move Category Up" onclick="window.upDown(\'' + prepend + i + '\',\'upcategory\''
		+ ');" onmouseover="buttonEffect(\'' + prepend + 'movecat' + i
		+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'movecat' + i
		+ '\', \'FALSE\');" class="buttons" border="0"></a><a href="#"></span>' +
	
		'<a href="#" title="Move Category Down"><img id="' + prepend + 'movedcat' + i
		+ '" src="images/admin/movedown.gif" alt="Move Category Down" onclick="window.upDown(\'' + prepend + i + '\',\'downcategory\''
		+ ');" onmouseover="buttonEffect(\'' + prepend + 'movedcat' + i
		+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'movedcat' + i
		+ '\', \'FALSE\');" class="buttons" border="0"></a>' +

		'<a href="#" title="Edit Category"><img id="' + prepend + 'editcat' + i
		+ '" src="images/admin/edit.gif" alt="Edit Category" onclick="editCat(\'' + prepend + i
		+ '\');" onmouseover="buttonEffect(\'' + prepend + 'editcat' + i
		+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'editcat' + i
		+ '\', \'FALSE\');" class="buttons" border="0"></a>' +

		'<a href="#" title="Delete Category"><img id="' + prepend + 'deletecat' + i
		+ '" src="images/admin/delete.gif" alt="Delete Category" onclick="deleteObject(\'' + prepend + i + '\', \'deletecat\''
		+ ');" onmouseover="buttonEffect(\'' + prepend + 'deletecat' + i
		+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'deletecat' + i
		+ '\', \'FALSE\');" class="buttons" border="0"></a>';

		document.getElementById(prepend + 'ajaxcatItems' + i).innerHTML = '<a href="#" title="Add Item"><img id="' + prepend + 'additem' + i
		+ '" src="images/admin/add.gif" alt="New Item" onclick="launchadminWindows(\'' + prepend + i + '\', \'add\''
		+ ');" onmouseover="buttonEffect(\'' + prepend + 'additem' + i
		+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'additem' + i
		+ '\', \'FALSE\');" class="buttons" border="0"></a>';

		if(i_id != 0) //make sure theres items to add admin options too
		{
			for(ii=1;ii<=i_id;ii++)
			{
				if(ii != i_id)
				{
					document.getElementById(prepend + 'itemswitch'  + i + ii).innerHTML = '<a href="#" title="Move Item Left/Right(Items on either side will switch places.)"><img id="' + prepend + 'leftright' + i + ii
					+ '" src="images/admin/leftright.gif" alt="Move Item Left/Right(Items on either side will switch places.)" onclick="upDown(\'' + prepend + i + 'i' + ii + '\',\'swapitems\''
					+ ');" onmouseover="buttonEffect(\'' + prepend + 'leftright' + i + ii
					+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'leftright' + i + ii
					+ '\', \'FALSE\');" class="buttons" border="0"></a>';
				}

				document.getElementById(prepend + 'ajaxItem'  + i + ii).innerHTML = '<a href="#" title="Edit Item"><img id="' + prepend + 'editItem' + i + ii
				+ '" src="images/admin/editsmall.gif" alt="Edit Item" onclick="launchadminWindows(\'' + prepend + i + 'i' + ii + '\', \'edit\''
				+ ');" onmouseover="buttonEffect(\'' + prepend + 'editItem' + i + ii
				+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'editItem' + i + ii
				+ '\', \'FALSE\');" class="buttons" border="0"></a>' +

				'<a href="#" title="Delete Item"><img id="' + prepend + 'deleteItem' + i + ii
				+ '" src="images/admin/deletesmall.gif" alt="Delete Item" onclick="deleteObject(\'' + prepend + i + 'i' + ii + '\', \'deleteitem\''
				+ ');" onmouseover="buttonEffect(\'' + prepend + 'deleteItem' + i + ii
				+ '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'deleteItem' + i + ii
				+ '\', \'FALSE\');" class="buttons" border="0"></a>';
			}
		}
	}
	
	document.getElementById(prepend + 'addcat').innerHTML =  '<table width="174" height="33"><tr><td><input type="text" name="newcategory" id="' + prepend + 'newcategory" value="New Category" size="18" maxlength="18"></td>' +
	'<td><a href="#" title="Add Category"><img src="images/admin/ok.gif" id="' + prepend + 'ok' + i + '" onclick="addCat(\'' + prepend + i +'\');" alt="Add Category" border="0" class="buttons"' +
	'onmouseover="buttonEffect(\'' + prepend + 'ok' + i + '\', \'TRUE\');" onmouseout="buttonEffect(\'' + prepend + 'ok' + i + '\', \'FALSE\');"></a></td></tr></table>';
}