// JavaScript Document
//Functions used in ArtSmart website


///Get the xmlHttp object for AJAX:
function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}


//AJAX function for getting gallery images...
function AjaxRequest(URL,divID)
{
	var theURL = URL;
	var theDiv = divID;
	var xmlHttp = getXMLHttp();
 	
	//if there's a div called 'ajaxWorking', put the spinner there. If not, put it in the ajax target div.
	var ajaxWorkingDiv = document.getElementById("ajaxWorking");
	
	if(ajaxWorkingDiv){
		ajaxWorkingDiv.innerHTML = "<img src='/web_images/spinner.gif' />";
	} else {
		document.getElementById(theDiv).innerHTML = "<img src='/web_images/spinner.gif' />";
	}
 
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			HandleResponse(xmlHttp.responseText,theDiv);
			if(ajaxWorkingDiv){
				ajaxWorkingDiv.innerHTML = "";
			}
		}
	}

	xmlHttp.open("GET", theURL, true);
	xmlHttp.send(null);
}


function HandleResponse(response,divID)
{
	document.getElementById(divID).innerHTML = response;
}



// open popup window
function openPopup(URL, name, ww, hh) {
	var xcoord, ycoord, popWidth, popHeight, popName;
	
	xcoord = 0;
	ycoord = 0;
	
	if(name != null) {
		popName = name;
	}
	else {
		popName = "popup";
	}
	
	if(ww != null) {
		popWidth = ww;
	}
	else {
		popWidth = 460;
	}
	
	if(hh != null) {
		popHeight = hh;
	}
	else {
		popHeight = 580;
	}
	
	if(document.getElementById) {
		xcoord = Math.round((screen.availWidth - popWidth) / 2);
		ycoord = Math.round((screen.availHeight - popHeight) / 2);
	}
	
  myPopup = window.open(URL,popName,'width=' + popWidth + ',height=' + popHeight + ',left=' + xcoord + ',top=' + ycoord + ',directories=no,menubar=yesn,status=no,resizable=1,scrollbars=yes');
  if (!myPopup.opener) {
		myPopup.opener = self;
	}
	
	myPopup.focus();
}


// The following function is used to create mailto links in an effort to thwart 
//email harvesting spam-bots.

function generate_mailto_link( username, domain ) {
	var atsign = "&#64;";
	var addr = username + atsign + domain;
	document.write( 
		"<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
		addr +
		"<\/a>");
}


// used to snap window to image size
function PopupPic(sPicURL) {
     window.open( "/snaptoimage.html?"+sPicURL, "",  
     "resizable=1,HEIGHT=200,WIDTH=200");
   } 
	 

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}
