/*******************************************************************************
*  mtstudios_utilities.js : 22.06.2005
* -----------------------------------------------------------------------------
*  A group of useful JavaScript utilities that can aid in the development
*  of webpages.
*******************************************************************************/

/*  Confirm Property Deletions */
function getconfirmProperty() { 
if (confirm("Are you sure you want to permanently delete the Property?")==true) 
return true; 
else 
return false; }

/*  Confirm Photo Deletions */
function getconfirmPhoto() { 
if (confirm("Are you sure you want to permanently delete this Photo?")==true) 
return true; 
else 
return false; }

/* Calendar Popup */

var popUp; 

function OpenCalendar(idname, postBack)
{
	popUp = window.open('Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=175,height=190,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}

/* Multi-File Upload  */
	
	function mysubmit(ID)
	{

			var Flash;
			if(document.embeds && document.embeds.length>=1)
				Flash = document.getElementById("EmbedFlashFilesUpload");
			else
				Flash = document.getElementById("FlashFilesUpload");		
				/* Flash.SetVariable("uploadUrl", "http://mtserver/mfv/Uploadfiles.aspx"); */ 
				Flash.SetVariable("uploadUrl", "FlashUpload.aspx?PropID=" + ID  ); 
				Flash.SetVariable("SubmitFlash", "");
	}



/* Google Map Functions  */

 function SetMapLatLon(formName, latid, lat, lonid, lon, postBack, zoomid, zoom)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	/* Load returned values into the saved HTML elements  */
	theform.elements[latid].value = lat;
	theform.elements[lonid].value = lon;
	theform.elements[zoomid].value = zoom;
	
}

/* Open the Map search page  */
 function OpenMapSearch(latidname, lonidname, zoomidname, postBack)
{
	popUp = window.open('MapSearch.aspx?formname=' + document.forms[0].name + 
		'&latid=' + latidname + '&lonid=' + lonidname + '&zoomid=' + zoomidname + '&curzoom=' + document.forms[0].elements[zoomidname].value + '&curlat=' + document.forms[0].elements[latidname].value + '&curlon=' + document.forms[0].elements[lonidname].value + '&postBack=' + postBack, 
		'popupGmap','width=420,height=430,left=100,top=100,scrollbars=0');
}

// returns a named value from the Querystring - equiv to FromQS

function querystring(name)  
{
   var tmp = ( location.search.substring(1) );
   var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

   if ( i >= 0 )
   {
      tmp = tmp.substring( name.length+i+1 );
      i = tmp.indexOf("&");
      return unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
   }

   return("");
}
 



/**** StyleSwitcher ****/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

/* Cookie stuff for remembering which stylesheet you last used >>

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 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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title); */

/**** End StyleSwitcher ****/