currPid="";
function togglePic(pid, imgState)
{
	if (typeof(imgState) == "undefined") imgState="";
	currPid=pid;
	obj=document.getElementById(pid);
	currSource=obj.src;
	if (currSource.indexOf("alternate")>-1) currSource=currSource.substring(0,currSource.indexOf("alternate")-1) + currSource.substring(currSource.length-4, currSource.length);
	if (imgState != "original" && currSource.indexOf("original")>-1)
	{
		obj.src=currSource.substring(0,currSource.indexOf("original")-1) + currSource.substring(currSource.length-4, currSource.length)
	}
	else if (imgState != "modified")
	{
		if (currSource.indexOf("_original") == -1)
			obj.src=currSource.substring(0,currSource.length-4) + "_original" + currSource.substring(currSource.length-4, currSource.length)
	}
	//obj.onclick=openPic;
}

function alternatePic(pid)
{
	obj=document.getElementById(pid);
	currSource=obj.src;
	ext=currSource.substring(currSource.length-4, currSource.length)
	if (currSource.indexOf("original")>-1)
	{
		altP=currSource.substring(0,currSource.indexOf("original")-1) + "_alternate";
		obj.src=altP + ext;
	}
	else	if (currSource.indexOf("alternate2")>-1)
	{
		orP=currSource.substring(0,currSource.indexOf("alternate")-1);
		obj.src=orP  + "_alternate" + ext;
	}
	else	if (currSource.indexOf("alternate")>-1)
	{
		orP=currSource.substring(0,currSource.indexOf("alternate")-1);
		obj.src=orP  + ext;
	} else 
	{
		obj.src=currSource.substring(0,currSource.length-4) + "_alternate"  + ext;
	}
}

function alternate2Pic(pid)
{
	obj=document.getElementById(pid);
	currSource=obj.src;
	ext=currSource.substring(currSource.length-4, currSource.length)
	if (currSource.indexOf("original")>-1)
	{
		altP=currSource.substring(0,currSource.indexOf("original")-1) + "_alternate2";
		obj.src=altP + ext;
	}
	else	if (currSource.indexOf("alternate.")>-1)
	{
		orP=currSource.substring(0,currSource.indexOf("alternate")-1);
		obj.src=orP  + "_alternate2" + ext;
	}
	else	if (currSource.indexOf("alternate2")>-1)
	{
		orP=currSource.substring(0,currSource.indexOf("alternate")-1);
		obj.src=orP  + ext;
	} else 
	{
		obj.src=currSource.substring(0,currSource.length-4) + "_alternate2"  + ext;
	}
}

function replayPic(pid)
{
	obj=document.getElementById(pid);
	currSource=obj.src;
	obj.src=currSource;
}

//ENTER MAX VALUES FOR SLIDESHOWS

function advanceSlides(picId)
{
	if (typeof(eval(picId+"_maxSlides"))=="undefined") return;
	maxNum=parseInt(eval(picId+"_maxSlides"))
	obj=document.getElementById(picId);
	currentSlideNum=parseInt(obj.src.substring(obj.src.indexOf(picId)+picId.length)) + 1;
	if (currentSlideNum>maxNum) currentSlideNum=1;
	nextImage=picId + currentSlideNum+ ".jpg";
	obj.src="/images/" + nextImage;
}

function getParmFromUrl(sUrl,parm)
{
	var quesIndex = sUrl.indexOf("?");
	if (quesIndex == -1)
		return "";
	var search = sUrl.substr(quesIndex+1);
	var parmList = "&" + search + "&";
	var re = new RegExp("&" + parm + "=([^&]*)&","i");
	var foundArray = re.exec(parmList);
	if (foundArray == null) return "";
	return foundArray[1];
}

function getParm(parm)
{
	if (location.search=="") return "";
	var parmList = "&" + location.search.substring(1, location.search.length) + "&";
	var re = new RegExp("&" + parm + "=([^&]*)&","i");
	var foundArray = re.exec(parmList);
	if (foundArray == null) return "";
	return foundArray[1];
}

function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0)
			return null;
	}
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, seconds)
{
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() + (seconds * 1000));
   thisCookie = name + "=" + escape(value) + "; path=/"
      + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
   document.cookie = thisCookie;
}

function openPic(pid)
{
	if (typeof(pid)=="undefined") pid=currPid;
	if (pid=="") return;
	obj=document.getElementById(pid);
	if (obj != null)
	{
		pSource=obj.src;
		window.open(pSource);
	}
}

function openArchives(comicData)
{
	window.open("http://comicbooth.com/comicbooth_archives.htm?c=" + comicData,"archives");
}
soundOn=false;
lastSoundId="";
function playSound(file,buttonId)
{
	if (lastSoundId != buttonId && lastSoundId!="")
	{
		butId=obj=document.getElementById(lastSoundId);
		if (soundOn) soundOn=false;
		if (butId != null) butId.src="http://comicbooth.com/images/sound_on.gif";
	}
	lastSoundId=buttonId;
	obj=document.getElementById('soundFrame');
	if (obj==null) return;
	if (file.indexOf("youtube")>-1)
	{
		obj=document.getElementById('yt');
		if (obj==null) return;
		if (file.indexOf("v=") > -1) yturl="http://www.youtube.com/embed/" + file.substring(file.indexOf("v=") +2,file.length);
			else yturl=file;
		if (!soundOn) obj.innerHTML="<iframe title=\"YT\" width=\"2\" height=\"2\" src=\"" + yturl + "?autoplay=1\" frameborder=\"0\"></iframe>";
			else obj.innerHTML="";
//if (!soundOn) window.open(file)
	}
	else
	{
		//window.open("http://comicbooth.com/playsound.htm?sound=/sounds/" + file + ".mp3")
		if (!soundOn) obj.src="http://comicbooth.com/playsound.htm?sound=/sounds/" + file + ".mp3";
			else obj.src="about:blank";
	}
	butId=obj=document.getElementById(buttonId);
	suffix=(soundOn) ? "on.gif" : "off.gif";
	if (butId != null) butId.src="http://comicbooth.com/images/sound_" + suffix;
	soundOn = !soundOn;
}

function openPageInWin(pg)
{
	butId=obj=document.getElementById(lastSoundId);
	if (butId != null)
	{
		butId.src="http://comicbooth.com/images/sound_on.gif";
		lastSoundId=""
		obj=document.getElementById('soundFrame');
		if (obj==null) return;
		obj.src="about:blank";
		soundOn=false;
	}
	window.open(pg);
}

function picMouseOver(objId,dowhat)
{
	if (typeof(dowhat)=="undefined") dowhat="";
	obj=document.getElementById(objId);
	if (obj != null)
	{
		if (dowhat=="toggle") togglePic(objId);
	}
}

function picMouseOut(objId,dowhat)
{
	if (typeof(dowhat)=="undefined") dowhat="";
	obj=document.getElementById(objId);
	if (obj!=null)
	{
		if (dowhat=="toggle") togglePic(objId);
	}
}

function getCurse(st)
{
	lcSt=st.toLowerCase();
	cLetters="abcdefghijklmnopqrstuvwxyz";
	newCurse="";
	for (i=0;i<st.length;i++)
	{
		if (lcSt.charAt(i)==" ") newCurse+="<img src=\"/images/cursing/blank.gif\"> ";
			else if (cLetters.indexOf(lcSt.charAt(i))>-1)
				newCurse+="<img src=\"/images/cursing/" + lcSt.charAt(i) + ".gif\">";
	}
	return newCurse;
}

function showCurse()
{
	st=document.frmCurse.english.value;
	document.getElementById("curse").innerHTML=getCurse(st);
}

function writeCurseTable()
{
	t="<table>"
	cLetters="abcdefghijklmnopqrstuvwxyz ";
	for (i=0;i<27;i++)
	{
		if (i==0 || i % 9==0) t+="<tr>";
		image=cLetters.charAt(i)
		if (image==" ") image="blank";
		t+="<td width=20 align=center><img src=\"/images/cursing/" + image + ".gif\" onclick=\"translate('" + image + "')\" title=\"" + image.toUpperCase() + "\"></td>";
		if (i==8 || i==17) t+="</tr>";
	}
	t+= "</tr></table>";
	document.write(t);
}

function translate(t)
{
	if (t=="blank") t=" ";
	document.getElementById("transcurse").innerHTML=document.getElementById("transcurse").innerHTML+ t.toUpperCase();
	document.getElementById("clear").style.display="block";
}

function clearCurse()
{
	document.getElementById("transcurse").innerHTML="";
	document.getElementById("clear").style.display="none";
}

function loadPage()
{
	//if (location.search.indexOf("jarjar")>-1) setCookie("showOriginal","0", 60*60*24*360);
	//if (location.href.indexOf("jarjar") > -1) alert(getCookie("showOriginal"));
	showOriginal = getCookie("showOriginal");
	if (showOriginal != null && showOriginal == "1") showOriginalFirst("original");
	//alert("Dean testing...")
}

function writeSoCheckbox()
{
	showOriginal = getCookie("showOriginal");
	chkImg="/images/show_original_checked.gif";
	if (showOriginal == null || showOriginal != "1") chkImg="/images/show_original_unchecked.gif";
	imgCode="<img id=originalCheckbox src=\"" + chkImg + "\" onclick=\"clickShowOriginalCheckbox()\"><br>"
	document.write(imgCode);
}

function clickShowOriginalCheckbox()
{
	cImg=document.getElementById("originalCheckbox");
	makeChecked=cImg.src.indexOf("unchecked")>-1;
	if (makeChecked)
	{
		cImg.src="/images/show_original_checked.gif";
		setCookie("showOriginal","1", 60*60*24*360);
		showOriginalFirst("original");
	}
	else
	{
		cImg.src="/images/show_original_unchecked.gif";
		setCookie("showOriginal","0", 60*60*24*360);
		showOriginalFirst("modified");
	}
}

function showOriginalFirst(goState)
{
	if (typeof(goState)=="undefined") goState="";
	for (i=0;i<document.links.length;i++)
	{
		lnk=document.links[i].href;
		wherePicId=lnk.indexOf("javascript:togglePic('");
		if (wherePicId > -1)
		{
			imgId=lnk.substring("javascript:togglePic('".length,lnk.length-2)
			if (document.getElementById(imgId) != null)
			{
				togglePic(imgId,goState);
			}
		}
	}
}

function buyIt(iName,iNumber,cost)
{
	var buyUrl="https://www.paypal.com/cart/add=1";
	buyUrl +="&business=payments%40yo-god.com";
	buyUrl +="&item_name=" + iName;
	buyUrl +="&item_number=" + iNumber;
	buyUrl +="&amount=" + cost;
	buyUrl +="&return=thanksyou.htm"
	buyUrl +="&cancel_return=cancel.htm"
	window.open(buyUrl, 'cartwin','width=600,height=400,scrollbars,resizable,status,location');
}

function floatWin(destination,winName,winW,winH)
{
	if ( typeof(winName) == "undefined") winName="_blank";
	window.open(destination,winName,"width=" + winW + ",height=" + winH + ",toolbar=0,status=0,resizable=1,scrollbars=0");
}
//document.onload="loadPage()";

