
 

function makeShowcaseImage(num)
{
	if(thisPic == showcase)
		return;
		
	document.getElementById('makeShowcaseImage').innerHTML = 'working...';
	
	var newShowcase = thisPic;
	
	var url = "_ajax_/ajaxShowcaseImage.php";
	var xmlhttp = null; 
	if (window.XMLHttpRequest) 
	{ 
		xmlhttp=new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject) 
	{ 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	if (xmlhttp!=null) 
	{ 
		xmlhttp.onreadystatechange=function() 
		{ 
			if (xmlhttp.readyState==4) 
			{ 
				if (xmlhttp.status==200) 
				{
					var response = xmlhttp.responseText;
					if(response.indexOf('yes') != -1)
					{
						document.getElementById('makeShowcaseImage').innerHTML = 'This is your showcase image';	
						showcase = newShowcase;
					}
					else
					{
						document.getElementById('makeShowcaseImage').innerHTML = '_error_';
					}	
				}
				else 
				{ 
					alert("Problem retrieving XML data"); 
				} 
			} 
		} 
		xmlhttp.open('POST',url,true); 
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlhttp.send('num=' + num + '&showcase=' + newShowcase);
	} 
	else 
	{ 
		alert("Your browser does not support XMLHTTP."); 
	}
}



function thumbClick(picId,f)
{
    f = f.replaceAll('_s','_m');
    
    var caption = document.getElementById('caption_' + picId).innerHTML;

    var newImg = loadImage(f);
    document.getElementById('mainPicDiv').innerHTML = '<img class=\"mainPic\" id=\"mainPic\" src=\"' + f + '\" alt=\"img\" />';


    if(caption == 'none' || caption == '')
    {
        document.getElementById('mainPicDiv').style.width = "700px";
        document.getElementById('caption').style.width = "1px";
        document.getElementById('caption').innerHTML = '';
    }
    else
    {
        document.getElementById('mainPicDiv').style.width = "540px";
        document.getElementById('caption').style.width = "160px";
        document.getElementById('caption').innerHTML = document.getElementById('caption_' + picId).innerHTML;
    }
	
}

function loadImage(imgSrc)
{
	var img = new Image();
	img.src = imgSrc;
	img.onload = function()
	{
		/*
		var dif = workWidth - img.width;
		if(dif > 0)
		{
			document.getElementById('bigImg').style.marginLeft = Math.floor(dif/2) + 'px';
		}
		else
		{
			document.getElementById('bigImg').style.marginLeft = '0px';
		}
		*/
	}
	return img;
}



var thisPic = 0;

function editCaption(picId,picFileName,picTitle)
{
	thisPic = picId;
	document.getElementById('captionFormDiv').style.display = "";
	document.getElementById('captionId').value = picId;
	document.getElementById('picTitle').value = picTitle;
	document.getElementById('mycaption').value = document.getElementById('caption' + picId).innerHTML;
	
	if(showcase == thisPic)
	{
		document.getElementById('makeShowcaseImage').innerHTML = 'This is your showcase image';
	}
	else
	{
		document.getElementById('makeShowcaseImage').innerHTML = 'Make showcase image';
	}
}

function deleteImage()
{
	var sure = confirm('Are you sure you want to delete this image?');
	
	if(sure)
	{
		document.getElementById('deleteId').value = thisPic;
		document.getElementById('hiddenForm').submit();
	}
}

function makeShowcase()
{
	document.getElementById('showcaseId').value = thisPic;
	document.getElementById('hiddenForm2').submit();
}

function validateNotes()
{
	if(document.getElementById('mytitle').value.replace(/^\s+|\s+$/g, '') == '')
	{
		alert("Please Create a Title");
		return false;
	}
	if(document.getElementById('mytitle').value.length > 30)
	{
		alert('Sorry, your title must be 30 charactors or less');
		return false;
	}	
	if(isBadString2(document.getElementById('mytitle').value))
	{
		alert('Sorry, you cannot use some of the charactors in your title (<,>)');
		return false;
	}
	if(isBadString2(document.getElementById('mynotes').value))
	{
		alert('Sorry, you cannot use some of the charactors in your notes (<,>)');
		return false;
	}
	if(isBadString(document.getElementById('myemail').value))
	{
		alert('Sorry, you cannot use some of the charactors in your email (\',\",<,>)');
		return false;
	}
	if(isBadString(document.getElementById('youtubeLink').value))
	{
		alert('Sorry, you cannot use some of the charactors in your youtube link (\',\",<,>)');
		return false;
	}
 	return true;
}

function isBadString(str)
{
	if(str.indexOf('\'') > -1 || str.indexOf('\"') > -1 || str.indexOf('<') > -1 || str.indexOf('>') > -1 || str.indexOf('\\') > -1)
	{
		return true;	
	}
	return false;
}

//allows ' and " for title and notes
function isBadString2(str)
{
	if(str.indexOf('<') > -1 || str.indexOf('>') > -1 || str.indexOf('\\') > -1)
	{
		return true;	
	}
	return false;
}