// JavaScript Document
function swapProductImage(currentImage) {
	currentImage.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div')[0].getElementsByTagName('img')[0].src=currentImage.src
}

// *************************** Prototype Only Javascript *****************************************
//cookie stuff
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//dashboard link location
function processDashboardLink() {
	userType=readCookie('user');
	if (userType=="member" || userType==null) {
		window.document.location="../memberLoggedIn/dashboard.html";
	} else {
		window.document.location="../ownerLoggedIn/dashboard.html";
	}
}
//write dashboard link
function writeDashboardLink() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="false" || loggedIn==null) {
		document.write('');
	} else {
		document.write('<a href="#" onClick="processDashboardLink();">dashboard</a> | ');
	}
}
//write login/out link
function writeLogoutLink() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="false" || loggedIn==null) {
		document.write('<a  href="../publicVisitor/login.html">login / signup</a>');
	} else {
		document.write('<a  href="../publicVisitor/index.html">logout</a>');
	}
}
//write yourStuff Link
function writeYourStuffLink() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="false" || loggedIn==null) {
		document.write('');
	} else {
		document.write('<li><a  href="yourStuff.html">Your Stuff</a></li>');
	}
}
//write Sell Stuff
function writeSellStuff() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="false" || loggedIn==null) {
		document.write('<tr><td colspan="2" ><span class="required">Email Address:</span><br /><input name="title" type="text" class="inputField" style="width:480px;margin-top:5px;"/></td></tr><tr><td colspan="2" ><span class="required">Confirm Email Address:</span><br /><input name="title" type="text" class="inputField" style="width:480px;margin-top:5px;"/></td></tr>');
	} else {
		document.write('');
	}
}
//write Buy Item
function writeBuyItem1() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="true") {
		document.write('<table class="tableDisplay1"><tr><th colspan="2"> Your Info <span></span></th></tr><tr class="row2"><td>Name:</td><td class="expander">Mike Padilla </td></tr><tr class="row2"><td class="row1">Email:</td><td>mikepadilla1@comcast.net</td></tr><tr class="rowblank"><td height="10" colspan="2">&nbsp;</td></tr></table>');
	} else {
		document.write('');
	}
}
//write Buy Item
function writeBuyItem2() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn=="false" || loggedIn==null) {
		document.write('<tr><td><span class="required">First Name:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:280px;margin-top:5px;"/></td><td colspan="2"><span class="required">Last Name:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:280px;margin-top:5px;"/></td></tr><tr><td colspan="3"><span class="required">Email Address:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:640px;margin-top:5px;"/></td></tr><tr><td colspan="3"><span class="required">Confirm Email Address:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:640px;margin-top:5px;"/></td></tr><tr><td colspan="3"><span class="required">Address:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:640px;margin-top:5px;"/></td></tr><tr><td><span class="required">City:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:280px;margin-top:5px;"/></td><td><span class="required">State:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:100px;margin-top:5px;"/></td><td><span class="required">Zip:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:100px;margin-top:5px;"/></td></tr>');
	} else {
		document.write('');
	}
}
function writeAskSeller() {
	loggedIn=readCookie('loggedIn');
	if (loggedIn!="true") {
		document.write('<tr><td colspan="2" ><span class="required">Your Email Address:</span><br /><input name="title" type="text" class="inputField" style="color:#000000;width:640px;margin-top:5px;"/></td></tr>');
	} else {
		document.write('');
	}
}
//image Zoom stuff
function zoomer2(magnifier) {
	var kvar1 = magnifier.parentNode.firstChild.src;
	var kvar2 = kvar1.replace("th_","");
	//	alert(kvar2);	
	document.getElementById('bigImage').src=kvar2;
	thumbnail=magnifier.parentNode.parentNode.parentNode.parentNode.parentNode;
	document.getElementById('bigPic').style.left=findPosX(thumbnail)+"px";
	//document.getElementById('bigPic').style.left="25px";
	document.getElementById('bigPic').style.top=findPosY(thumbnail)+"px";
}
function zoomer(magnifier) {
	thumbnail=magnifier.parentNode.parentNode.parentNode.parentNode.parentNode;
	document.getElementById('bigPic').style.left=findPosX(thumbnail)+"px";
	//document.getElementById('bigPic').style.left="25px";
	document.getElementById('bigPic').style.top=findPosY(thumbnail)+"px";		
	document.getElementById('bigImage').src=magnifier.parentNode.firstChild.src;
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function goAway() {
document.getElementById('bigPic').style.left="-1000px";
document.getElementById('bigImage').src='../images/spacer.gif';
}

function deleteImage(thisImage,imageno) {
	var form = document.forms.form1;
	var vimage = form.noimage.value;
	if(thisImage.style.borderColor!='red'){
		thisImage.style.borderColor='red';
		thisImage.style.borderWidth='3px'
		vimage += imageno+"='',";
	} else {
		thisImage.style.borderColor='#A9A9A9';
		thisImage.style.borderWidth='1px'
		vimage = vimage.replace(imageno+"='',","");
	}
	//alert(vimage);
	form.noimage.value = vimage;
}
function progressBar() {
	document.getElementById('sellButtons').style.display='none';
	document.getElementById('progressBar').style.display='block';
	setTimeout('reanimate()',200);
}
function reanimate() {
	currentImage = document.getElementById('progressBarImage');
	currentImage.src=currentImage.src;
}
function calculateCharacters() {
	charactersUsed=document.getElementById('description').value.length;	
	charactersLeft=1000-charactersUsed;
	if(charactersLeft < 0) {
		charactersLeft=0;
	}
	charactersUsed=document.getElementById('characters').innerHTML=charactersLeft;
	if(charactersLeft == 0) {
		document.getElementById('description').value=document.getElementById('description').value.substring(0,1000);
		alert("You've entered the maximum amount of characters allowed for the description.");
	}
}
function allow_numeric(obj){
 if (/[^0-9]/i.test(obj.value))
 	if(obj.value.indexOf('.')!=-1) {
	 alert("Please only enter whole dollar amount - no cents.");	
	}
  obj.value=obj.value.replace(/[^0-9]/g,'')
  obj.value+=''
  obj.focus()
}

