/* portions copyright Mysterious Ways 2001-2006 

Part of CForm Library 

http://www.mways.co.uk 

Yes, that means you can't use this without permission.

And hey, Mineral Dealers, if you think I won't notice if you steal this code, you're wrong!

Jolyon (http://www.mindat.org) is watching you....  

you don't want to get into my bad books! Theft of code = instant & permanent ban from mindat.org


*/

var xmlhttp=false;

function switchimage(ctrl)
{
	var newphoto = ctrl.src;
	var bigctrl = document.getElementById('minboxbigimage');
	
	var oldphoto = bigctrl.src;
	
	loadmsg();
	
	bigctrl.src = newphoto.replace("mvthumbs","mvbthumbs");
	ctrl.src = oldphoto.replace("mvbthumbs","mvthumbs");
}


function loadmsg()
{	

	var img = document.getElementById('waitpic');


	
	img.style.visibility='visible';
}

function loadedimg()
{
	var img = document.getElementById('waitpic');
	img.style.visibility='hidden';

}

function getxmlhttp()
{
	var _xmlhttp=false;

	try 
	{
  		_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) 
 	{
  		try 
  		{
   		_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} catch (E) 
  		{
   		_xmlhttp = false;
  		}
 	}
	if(!_xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
  		_xmlhttp = new XMLHttpRequest();
	}
	return _xmlhttp;
}

function quicksearch()
{
	var value = document.getElementById('qs').value;
 
  if(xmlhttp && xmlhttp.readyState!=0)
  {
    xmlhttp.abort()
  }
  xmlhttp=getxmlhttp();
  
  if(xmlhttp)
  {
		if(value.length>2)
  	{
  		xmlhttp.open("GET","searchresults.php?qs="+value,true);
  		xmlhttp.onreadystatechange=function() 
  		{
  	    if(xmlhttp.readyState==4) 
      	{	
      		if(xmlhttp.responseText)
      		{	 
        			document.getElementById('maincontent').innerHTML= xmlhttp.responseText;		
  				} 
      	}	
  		}
			xmlhttp.send(null);
		} else
		{
			document.getElementById('maincontent').innerHTML= "<h1>Searching...</h1>Continue typing, your search will appear and update as you type";	
		}
	}
}

function ajaxsubmit(formname)
{

	var formid = document.forms[formname];
	var param = "searchresults.php?ajax=1";
	for(var i=0;i<formid.elements.length;i++)
	{
		var obj = formid.elements[i];

		param+="&"+obj.name+"="+obj.value;
			
	}
	
	if(xmlhttp && xmlhttp.readyState!=0)
  {
    xmlhttp.abort()
  }
  xmlhttp=getxmlhttp();
  
  if(xmlhttp)
  {
		xmlhttp.open("GET",param,true);
  	xmlhttp.onreadystatechange=function() 
  	{
  		if(xmlhttp.readyState==4) 
     	{	
      	if(xmlhttp.responseText)
      	{	 
					document.getElementById('results').innerHTML= xmlhttp.responseText;		
  			} 
      }	
  	}
		
		xmlhttp.send(null);
	}
}

function setimgloaded(img)
{
	imgscomplete=1;
}

	
function xin() 
{
	imgs = d.getElementById("photobox").getElementsByTagName("img");
	lnks = d.getElementById("photobox").getElementsByTagName("a");
	imgs[1].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	setTimeout(xf,4000);
}

function xf() 
{
	if((!ci(imgs[0]))||(!ci(imgs[1]))||(imgscomplete==0)) 
	{
		setTimeout(xf,50);
		return;
	}

	cOpacity = imgs[current].xOpacity;
	nIndex = 1 - current;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	so(imgs[current]); 
	so(imgs[nIndex]);
	
	if(cOpacity<=0) 
	{		
		imgs[current].style.display = "none";
		imgscomplete = 0;
		imgs[current].src = files[nextimg];
		lnks[current].href= urls[nextimg];
	
		nextimg++;
		if(nextimg>=files.length) nextimg=0;
		current = nIndex;
		setTimeout(xf,4000);
	} else setTimeout(xf,50);

	function so(obj) 
	{
		if(obj.xOpacity>.99) 
		{
			obj.xOpacity=.99; 
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
	function ci(img)
	{
    if (!img.complete) return false;
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false;
    return true;
	}
}

function getElementLeft(elem) 
{

	
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) 
  		{
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
}


function getElementTop(elem) 
{
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) 
	{
  		yPos += tempEl.offsetTop;
	 		tempEl = tempEl.offsetParent;
  }
	return yPos;
}
