/* call with preloadimages("http://mydomain.com/firstimage.gif","http://mydomain.com/thirdimage.gif") */

var myimages=new Array()
function preloadimages()
{
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}


function iz(what){ // comments follow

if(!what) return navigator.appName+'; '+ navigator.userAgent;


	var agnt= navigator.userAgent.toLowerCase();


	var wot=what.toLowerCase();

	switch (wot){

	case 'df':return !!(document.createDocumentFragment);

	case 'dom':return !!(document.createDocumentElement);

	case 'id':return !!(document.getElementById);

	case 'ie':return !!(agnt.indexOf('msie')!= -1);

	case 'moz':return !!(agnt.indexOf('gecko')!= -1);

	case 'agt':return agnt.toLowerCase()

	default:return !!(agnt.indexOf(wot) != -1);

	}
}


function updatetitledesc(the_id, which)
{
	
	//newtitle = document.changetitle.getElementById('titleID').value;
	//the_id is the id in question; either a photo id or a set id
	
	
	/*
	document.getElementById('change' + which + the_id).submit();
	return true;	
	testing only turn off
	*/
	
	if (!ok_for_xml_http_and_xml()) return true;	//we return true and follow the link
	newtitle = document.getElementById(which + '_' + the_id).value;
	
	document.getElementById(which + '_orig_' + the_id).innerHTML = newtitle;	//this rewrites the HTML
	
	
	var req = new XMLHttpRequest();
	
	
	var PAGE = '/photos/edit/title_description.php';
	var Q = 'ju=1&' + which + '=' + newtitle + '&the_id=' + the_id;
	
	req.open('POST', PAGE);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	req.send(Q);
	
	return false;
	
}

function dorotate(photo_id)
{
	
	if (!ok_for_xml_http_and_xml()) return true;	//we return true and follow the link
	var degrees90 = document.getElementById('rot90').checked;
	var degrees270 = document.getElementById('rot270').checked;
	
	if(!degrees90 && !degrees270) return false;
	
	degrees = (degrees90) ? 90 : 270;
	alert(degrees);
	var req = new XMLHttpRequest();
	
	
	var PAGE = '/photos/edit/rotate.php';
	var Q = 'ju=1&degrees=' + degrees + '&photo_id=' + photo_id;
	
	req.open('POST', PAGE);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	req.send(Q);
	
	return false;
	
}


function removetag(tag_id, photo_id, tag){
	if (window.confirm('Are you sure you want to delete the tag "'+tag+'"?')) {
		
		if (!ok_for_xml_http_and_xml()) return true;	//we return true and follow the link
		//we do the remove here
		removetag_do(tag_id, photo_id);
		return false;
	} else {
		return false;
	}
}

function removetag_do(tag_id, photo_id) {
	document.getElementById('thistag_'+tag_id).style.display = 'none';
	var req = new XMLHttpRequest();
	
	
	var PAGE = '/photos/edit/remove_tag.php';
	var Q = 'tag_id=' + tag_id + '&photo_id=' + photo_id;
	
	req.open('POST', PAGE);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	req.send(Q);
	
}

function ok_for_xml_http_and_xml(){
	//if (global_fakeOperaXMLHttpRequestSupport) return false;
	return ok_for_xml_http();
}

function ok_for_xml_http(){
	/*
	var isMac = (navigator.userAgent.indexOf("Mac") != -1);
	var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
	if(isIE && isMac)return false;
	*/
	if (!window.XMLHttpRequest) return false;
	if (navigator.appVersion.toLowerCase().indexOf("mac") > 0 && navigator.userAgent.indexOf('MSIE') > 0 && navigator.userAgent.indexOf('Opera') == -1) return false;
	return true;
}



function popUp(strURL,strType,strWidth,strHeight,addOptions)
{
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth+addOptions;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth+addOptions;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth+addOptions;

	window.open(strURL, 'newWin', strOptions);
	//screenX=400,screenY=400,top=400,left=400'
	// msgWindow = window.open('','newWin','width=100,height=100,screenX=400,screenY=400,top=400,left=400');

	//call with <a href = 'x.html' onclick="popUp(this.href,'elastic',500,500,'');return false;" target = 'newWin'>
}

// toggle visibility 




function toggle(targetId ){

  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
  	
}

function toggle_flip(target, which)
{
	var newstyle = (which == 'hide') ? 'none' : '';
	if (document.getElementById)
	{
		var showtarget = document.getElementById( target + '_show' );
		var hidetarget = document.getElementById( target + '_hide' );
		document.getElementById(target).style.display = newstyle;
		if (showtarget.style.display == "none"){
  				showtarget.style.display = "";
  				hidetarget.style.display = "none";
  		} else {
  				showtarget.style.display = "none";
  				hidetarget.style.display = "";
  		}
	
	}
	return false;
}


function toggleboth2(targetId, offid){
	
	if (document.getElementById){
  		go_on = document.getElementById( targetId );
  		go_off = document.getElementById( offid );
		
		go_on.style.display = '';
		
		go_off.style.display = 'none';
		document.getElementById('theform').submit();
		return false;	/* check this, so the form is not submitted */
	}
  	
}

/*used in upload*/
function toggleboth3(targetId, offid, off2id){
	
	if (document.getElementById){
  		go_on = document.getElementById( targetId );
  		go_off = document.getElementById( offid );
  		go_off2 = document.getElementById( off2id );
		
		go_on.style.display = '';
		
		go_off.style.display = 'none';
		go_off2.style.display = 'none';
		document.getElementById('theform').submit();
		return false;	/* check this, so the form is not submitted */
	}
  	
}

function toggleboth(targetId, offid){
	
	if (document.getElementById){
  		target = document.getElementById( targetId );
  		target2 = document.getElementById( offid );
		if (target.style.display == "none"){
			target.style.display = "";
		} else {
			target.style.display = "none";
		}
		if (target2.style.display == "none"){
			target2.style.display = "";
		} else {
			target2.style.display = "none";
		}
	}
  	
}

function enlarge(targetId ){
	if (document.getElementById){
  		target = document.getElementById( targetId );
  		target.setAttribute("style", "background:red");
  			
  	}
  	
}

function togglecolor(targetId, color){
	
	target = document.getElementById( targetId );
	target.style.background = color;
  	
}

function togglecolor2(targetId ){
	if (document.getElementById){
  		target = document.getElementById( targetId );
  		target.setAttribute("style", "background:red");
  			
  	}
  	
}

function toggleheight(targetId, original, alter ){

  if (document.getElementById){
  		target = document.getElementById( targetId );
  		
			if (target.style.height == alter){
  				target.style.height = original;
  			} else {
  				target.style.height = alter;
  			}
  	}
  	
}




function toggle3(targetId ){
//  newNote.setAttribute("style", "background:red");
//  newNote.setAttribute("style", "background:red");
	//getElementsByAttribute.
	
	//getIdProperty("s" + divNum, "display") != "block"


  if (document.getElementById){
  		target = document.getElementById( targetId );
  		
  		
  		
  		alert (getIdProperty('extrahelp', "display"));
  			if (target.style == "background:red"){
  				target.setAttribute("style", "background:blue");
  			} else {
  				target.setAttribute("style", "background:red");
  			}
  	}
  	
}

function bigtoggle(targetId, origStyle, newStyle ){

  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == origStyle){
  				target.style.display = newStyle;
  			} else {
  				target.style.display = origStyle;
  			}
  	}
  	
}

function toggle2(targetId)
{
	var buttonId;
	buttonId = targetId + "button";
	target2 = document.getElementById( buttonId );

  if (document.getElementById)
  {
  		target = document.getElementById( targetId );
		if (target.style.display == "none"){
			target.style.display = "";
			target2.style.backgroundImage = 'url(/manage/html/pics/dingbats/minus.gif)';
		} else {
			target.style.display = "none";
			target2.style.backgroundImage = 'url(/manage/html/pics/dingbats/plus.gif)';
		}
  		
  }
}

/* change page location to option selected from navigation drop-down */
	function doit(Selected, go) {
		var newURL;
		var doIt = Selected.options[Selected.selectedIndex].value ;
		newURL = '/' + go + '/action/do/?do=' + doIt;
		if (doIt!=" ") {
			document.location.href = newURL;
		}
	}
/*******************************************************
FORMS
All code by Ryan Parman, unless otherwise noted.
(c) 1997-2003, Ryan Parman
http://www.skyzyx.com
Distributed according to SkyGPL 2.1, http://www.skyzyx.com/license/
*******************************************************/


/*******************************************************
ALLOW ONLY ONE SUBMISSION OF THE FORM
Attach an onload to the form tag.  Can use this.name.
*******************************************************/
function submitOnce(formName)
{
	this.formName=(formName) ? formName:0;

	if (document.forms && document.getElementsByTagName)
	{
		var subFields=eval('document.forms["'+this.formName+'"].getElementsByTagName("input");');

		var subFieldsLen=subFields.length;
		for (k=0; k<subFieldsLen; k++)
		{
			if (subFields[k].getAttribute("type").toLowerCase() == "submit") subFields[k].disabled=true;
			if (subFields[k].getAttribute("type").toLowerCase() == "reset") subFields[k].disabled=true;
		}
	}
}




/*******************************************************
SELECT ALL (HIGHLIGHT FIELD)
*******************************************************/
function selectAll(formField)
{
	temp=eval(formField);
	temp.focus();
	temp.select();
}




/*******************************************************
SINGLE-SELECT CHECKBOXES
This gives checkboxes the "one-at-a-time" functionality of radio buttons.
*******************************************************/
function radioButton(formName)
{
	this.formName=(formName) ? formName:0;
	
	this.select=function(what)
	{
		if (document.forms && document.getElementsByTagName)
		{
			var raFields=eval('document.forms["'+this.formName+'"].getElementsByTagName("input");');

			var raFieldsLen=raFields.length;
			for (i=0; i<raFieldsLen; i++)
			{
				if (raFields[i].getAttribute("type").toLowerCase() == "checkbox") raFields[i].checked=false;
				what.checked=true;
			}
		}
	}
}



/*******************************************************
CHECKBOXES
By Ryan Parman
- Click and Drag functionality by Peter Bailey, http://www.peterbailey.net
- Must be initialized as an object, then (optionally) attach an onload to the BODY tag, 
      either objName.enableMouseover(), or objName.enableClickDrag(), but not both.
- Use objName.check(), objName.clear(), or objName.toggle().
*******************************************************/
function checkbox(nameOfForm)
{
	// Store variables.
	this.nameOfForm=(nameOfForm) ? nameOfForm:0;
	this.toggleOnOff=1;

	// Can be used externally, but meant for internal use only.
	this.set=function(bool)
	{
		if (document.forms && document.getElementsByTagName)
		{
			//var theFields=eval('document.getElementById('+nameOfForm+').getElementsByTagName("input");');

			var theFields= document.getElementById( nameOfForm ).getElementsByTagName("input");
			var theFieldsLen=theFields.length;
			for (i=0; i<theFieldsLen; i++)
			{
				if (theFields[i].getAttribute("type").toLowerCase() == "checkbox") theFields[i].checked=bool;
			}
		}
		else alert('Not Supported');
	}

	// Basic functions to use externally.
	this.check=function() { this.set(true); }
	this.clear=function() { this.set(false); }

	// Just a nifty little feature.
	this.toggle=function()
	{
		if (this.toggleOnOff) { this.set(true); this.toggleOnOff=0; }
		else if (!this.toggleOnOff) { this.set(false); this.toggleOnOff=1; }
	}

	// Call this during BODY onLoad to add mouseover functionality to the form.
	this.enableMouseover=function()
	{
		if (document.forms && document.getElementsByTagName)
		{
			var moFields=eval('document.forms["'+this.nameOfForm+'"].getElementsByTagName("input");');

			var moFieldsLen=moFields.length;
			for (i=0; i<moFieldsLen; i++)
			{
				if (moFields[i].getAttribute("type").toLowerCase() == "checkbox")
				{
					onMO=moFields[i];
					onMO.onmouseover=this.change;
				}
			}
		}
	}

	this.change=function() { this.checked=(this.checked) ? false:true; }

	// By Peter Bailey, www.peterbailey.net
	// Slight modifications by Ryan Parman, www.skyzyx.com
	this.enableClickDrag=function(sameNameOnly)
	{
		// Abort if browser can't do script
		if (document.all && !document.attachEvent) return true;
		else if (!document.all && !document.addEventListener) return true;
		//else if (document.all && !document.addEventListener) return true; // For retarded-ass Opera 7...

		// Initialize Variables/properties
		var f=eval('document.forms["'+this.nameOfForm+'"]');
		var dragObj=this;
		this.checked=false;
		this.mousedown=false;
		this.validClick=false;
		this.same=Boolean( sameNameOnly );

		// Attach Events
		if ( document.attachEvent )
		{
			f.attachEvent( "onmousedown", function() { downHandler( event.srcElement, dragObj ) } );
			f.attachEvent( "onmouseover", function() { overHandler( event.srcElement, dragObj ) } );
			document.attachEvent( "onmouseup", function() { upHandler( event.srcElement, dragObj ) } );
		}
		else
		{
			f.addEventListener( "mousedown", function( e ) { downHandler( e.target, dragObj ) }, false );
			f.addEventListener( "mouseover", function( e ) { overHandler( e.target, dragObj ) }, false );
			document.addEventListener( "mouseup", function( e ) { upHandler( e.target, dragObj ) }, false );
		}

		// Handler for form.onMouseDown event
		function downHandler(elem, o)
		{
			if (elem.type=="checkbox")
			{
				o.validClick=true;
				o.firstCB=elem;
				o.mousedown=true;
				o.checked=!elem.checked
				if (o.same) o.name=elem.name;
			}
		}

		// Handler for document.onMouseUp event
		function upHandler(elem, o)
		{
			if (o.validClick && o.firstCB)
			{
				o.firstCB.checked=o.checked;
				o.mousedown=false;
				o.checked=!o.checked;
				o.validClick=false;
				if (elem===o.firstCB) elem.checked=o.checked;
			}
		}

		// Hanlder for form.onMouseOver event
		function overHandler(elem, o)
		{
			if (elem.type=="checkbox" && o.mousedown)
			{
				if (o.same && elem.name == o.name) elem.checked=o.checked;
				else if (!o.same) elem.checked=o.checked;
			}
		}
	}
}


function toggle_multi_edit(thisid){
	var is_checked = document.getElementById(thisid).checked;

	document.getElementById(thisid).checked = !is_checked;
	
	
	}

function check_multi_edit(nameOfForm, alertmessage){	
	var theFields= document.getElementById( nameOfForm ).getElementsByTagName("input");
	var theFieldsLen=theFields.length;
	for (i=0; i<theFieldsLen; i++)
	{
				//if (theFields[i].getAttribute("type").toLowerCase() == "checkbox") theFields[i].checked=bool;
				if(theFields[i].checked)return true;
				// document.send.recs_name.value
	}
	alert (alertmessage); 
	return false;
}


function showMyToggle(show,hide,ide, classname ) {
	if(document.getElementById) {
		/*
		alert('<span class=\'mytoggle\'><a href="javascript:toggleit(\'' + ide + '\')" class="internal">' +
		'<span id="' + ide + 'showlink" style="display:none;">' + show + '</span>' +
		'<span id="' + ide + 'hidelink">' + hide + '</span>'
		+ '</a></span>');
		*/
		document.writeln('<span class="mytoggle"><a href="javascript:toggleit(\'' + ide + '\')" class="internal">' +
		'<span id="' + ide + 'showlink" style="display:none;">' + show + '</span>' +
		'<span id="' + ide + 'hidelink">' + hide + '</span>'
		+ '</a></span>');
	}
}

/*
document.writeln('<span class="mytoggleTMP"><a href="javascript:toggleit(\'' + ide + '\')" class="internal">' +
		'<span id="' + ide + 'showlink" style="display:none;border:2px solid black;">' + show + '</span>' +
		'<span id="' + ide + 'hidelink">' + hide + '</span>'
		+ '</a></span>');
*/

/*
<div id = "REF">

<script type="text/javascript">showMyToggle("show","hide","REF")</script>

<div id = "REFinside">
This toggles
</div>

</div>
*/

function toggleit(ide) {
	
	var main = document.getElementById(ide);
	var toc = document.getElementById( ide + 'inside' );
	var showlink=document.getElementById(ide + 'showlink' );
	var hidelink=document.getElementById(ide + 'hidelink');
	if(!window.mc){
		mc = main.className;
	}
	if(toc.style.display == 'none') {
		/*to make reappear*/
		toc.style.display = tocWas;
		hidelink.style.display='';
		showlink.style.display='none';
		main.className = mc + ' on ';
		

	} else {

		/* when we click to make disappear */
		tocWas = toc.style.display;
		toc.style.display = 'none';
		hidelink.style.display='none';
		showlink.style.display='';
		main.className = mc + ' off ';
		
	}
}


/* simply toggle flip */

function toggleflip(showid, hideid)	/*hide is initially hidden*/
{

	if (document.getElementById){
	
		on = document.getElementById( showid );
		off = document.getElementById( hideid );
		if (on.style.display == "none"){
  				on.style.display = "";
		} else {
  				on.style.display = "none";
  		}
  		
  		if (off.style.display == "none"){
  				off.style.display = "";
		} else {
  				off.style.display = "none";
  		}
	}
	return false;
}



function emailError (emailStr, basic) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return 1
}
if( basic)return 0;

var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The username doesn't seem to be valid.")
    return 2
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Destination IP address is invalid!")
		return 3
	    }
    }
    return 0
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    return 4
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return 5
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   //alert(errStr)
   return 6
}

// If we've gotten this far, everything's valid!
return 0;
}
