/* ********************
//	file: v4.js
//	note: global v4 js file
// ******************** */


// #############################################
// returns the object baring the id
// #############################################
function getObjectID (id)
{
	if (document.all) 
		return document.all[id];
	return document.getElementById (id);
}

// #############################################
// show or hide the layer, from given ID and toggle
// #############################################
function showHideLayer (id,isVisible)
{
	if(getObjectID(id) != null) getObjectID(id).style.display = (isVisible)? 'block' : 'none';
}
// #############################################
// BEG: invisible "mask layer" code
// #############################################

// write out mask HTML code
function drawMask()
{
	// double check for browser compatibility.. 
	if (is_ie6up && is_win)
	{
		maskContent = '<div id="maskOverlay" class="maskOverlay"></div>';
	}
	else
	{
		maskContent = '';
	}	
	// ==== output HTML code ====
	document.write(maskContent);
}

// show/hide mask layer
function toggleMask(isEnabled)
{	
	var maskOverlayLayer = document.getElementById("maskOverlay");	
	if (maskOverlayLayer) maskOverlayLayer.style.display = (isEnabled)? 'block' : 'none';	
	
}


// #############################################
// BEG: browser window functions 
// #############################################

// =============================================
// pop up new window ===========================
function open_window(winurl,winname,winfeatures)
{
	newwin = window.open(winurl,winname,winfeatures);
}


// =============================================
// resize window ===============================
function resizeWindow(isCenter,w,h)
{		
	var height = screen.availHeight;
	var width = screen.availWidth;	
	var sHeight = screen.height;
	var sWidth = screen.width;
	
	// defaults to fullscreen if no dimensions were passed in
	var w_height = (h == null)? height : h; 
	var w_width = (w == null)? width : w;		
	
	// get cookie values
	var cookScreen_w = getCookie('SC_screen_w');
	var cookScreen_h = getCookie('SC_screen_h');
	var cookBrowser_w = getCookie('SC_browser_w');
	var cookBrowser_h = getCookie('SC_browser_h');
	
	// if cookies exist.. resize using those values
	if (cookScreen_w != null || cookScreen_w != '')
	{
		// if still same screen res.  resize to cookie dimensions
		if (sHeight == cookScreen_h && sWidth == cookScreen_w)
		{
			top.resizeTo(cookBrowser_w, cookBrowser_h);
			if (isCenter == true) centerWindow(cookBrowser_w,cookBrowser_h);
		}
		// else ... maximize window
		else
		{
			top.resizeTo(w_width, w_height);
			if(isCenter == true) centerWindow(w_width,w_height);
		}		
	}
	// else ... maximize window
	else
	{
		top.resizeTo(w_width, w_height);
		if(isCenter == true) centerWindow(w_width,w_height);
	}
}
// =============================================
// center window ===============================
function centerWindow(w,h)
{
	top.moveTo((screen.availWidth - w)/2  ,(screen.availHeight - h)/2);
}


// #############################################
// BEG: xmlHttp code 
// #############################################

// ========== create new http object ===
function getNewHTTPObject()
{
        var xmlhttp;
        /** Special IE only code ... */
        /*@cc_on
          @if (@_jscript_version >= 5)
              try
              {
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				  //alert('using: 2.0');
              }
              catch (e)
              {
                  try
                  {
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					   //alert('using: 1.0');
                  }
                  catch (E)
                  {
                      xmlhttp = false;
                  }
             }
          @else
             xmlhttp = false;
        @end @*/

        /** Every other browser on the planet */
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e)
            {
                xmlhttp = false;
            }
        }
        return xmlhttp;
}
// ====================================
// BEG: Load external file into div
// =====
// NOTE:   pass params without the "?" like   (param1=foo&param2=bar&param3=foobar). we will add the "?" ourselves
function grabFile(url, target, jsPath, params) 
{
  document.getElementById(target).innerHTML = ' <p><br>Loading data...</p>';
  
  // get http object  <== old style
  /*
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
  	//alert('ax 1');
    req = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  */
  
  // use new getHTTP oject code up top.
  req = getNewHTTPObject();
  
  
  // join url + params
  var newUrl = (params)? url + "?" + params : url + "?" ;
  
  // add a random number param  to prevent caching in IE  
  /*
  var myRand = Math.random();
  var myRandStr = (params)? "&Rand=" + myRand : "Rand=" + myRand;
  
	newURL = newUrl + myRandStr;
  */
  //alert("test: " + newURL);
  
  if (req != undefined) {
    req.onreadystatechange = function() {grabFileDone(newUrl, target, jsPath);};
	req.open("GET", newUrl, true);
	
	// set header to prevent caching:  use this while dev.. 
	// 		but go back to normal cache once live for performance gains.
	req.setRequestHeader("If-Modified-Since", "Wed, 15 Nov 1995 04:58:08 GMT");
    
	//send request
	req.send("");
  }
}  

// callback function when http request is done.
function grabFileDone(url, target, jsPath) 
{
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      	document.getElementById(target).innerHTML = req.responseText;
	  	// load js file
	  	if(jsPath) { loadJS(jsPath);	}
	  
    } else {
      document.getElementById(target).innerHTML="<div align='center'> Error:\n"+ req.status + "\n" +req.statusText +"... Please try again.</div>";
    }
  }
}

// simplified call a page function.
function loadXML(name, div, jsPath) 
{
	// original xml grab
	grabFile(name,div,jsPath);
	
	return false;
}
// dynamically load a js file
function loadJS(path) {
  var oScript = document.createElement("script");
  oScript.src = path;
  document.body.appendChild(oScript);
}






//==========================  test area
var http_request = false;
function makeRequest(url, parameters) {
   http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
      	// set type accordingly to anticipated content type
         //http_request.overrideMimeType('text/xml');
         http_request.overrideMimeType('text/html');
      }
   } else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }
   http_request.onreadystatechange = alertContents;
   http_request.open('GET', url + parameters, true);
   http_request.send(null);
}

function alertContents() {
   if (http_request.readyState == 4) {
      if (http_request.status == 200) {
         //alert(http_request.responseText);
         result = http_request.responseText;
         document.getElementById('xmlContentTD').innerHTML = result;            
      } else {
         alert('There was a problem with the request.');
      }
   }
}


// process form dynamically   obj= formID, actionFile = form target page
function doXMLForm(obj,actionFile) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      makeRequest(actionFile, getstr);
	  //alert('form params: '+ getstr);
	  //grabFile(actionFile, contentArea, null, getstr) ;
}
// ======================= END: test area

// #############################################
// draw invisible "about smc" box  
// NOTE: drawing flash needs the  swfobject.js
// #############################################
function drawVerInfo(isGay)
{
	// ===== options ====
	swfWidth 	= 685;						// width of SWF file
	swfHeight 	= 460;						// height of SWF file
	swfURL 		= (isGay)? '/images/aboutus_gay.swf' : '/images/aboutus2.swf';		// set to URL of file
	swfWmode	= 'transparent';			// set to: 'transparent' or 'opaque'
	swfID		= 'swfVersionInfo';			// ID name used to reference in js code
	
	// ==== detect code ====
	// if IE & Flash Detection is successful... draw "invisible" version info box
	//alert('hasRver: ' + hasRightFlashVersion);
	
	if(is_ie && hasRightFlashVersion && is_winxp)
	{
		detectContent = '<div id="verInfoDIV" name="verInfoDIV" style="position: absolute; z-index: 10; left: expression((document.body.offsetWidth -'+ swfWidth +')/2 ); top: expression((document.body.offsetHeight-'+ swfHeight +')/2 - 50 ); display: none;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width='+ swfWidth + ' height='+ swfHeight +' id='+ swfID +'>'
			+ '<param name=movie value="' + swfURL +'"> <param name="wmode" value="'+ swfWmode +'"> <param name=quality value=high> <param name=bgcolor value=#FFFFFF> <param name=menu value=false> <embed src="' + swfURL +'" quality=high bgcolor=#FFFFFF  width='+ swfWidth + ' height='+ swfHeight + ' wmode="'+ swfWmode +'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'
			+'</object></div>';
			
		// ==== output HTML code ====
		//drawMask();
		document.write(detectContent);
		
		// make draggable
		makeDraggable('verInfoDIV');
		
		// set ok to use flash about us popup. set to true to show cool flash version.
		coolAboutFlag = false; // set to false if you want to always use normal text "about us" version
	}	
	else {
		// goto aboutus text page
		coolAboutFlag = false;
	}
	
}
// #############################################
// enable/show version info box
// #############################################
function showAboutUs(isVisible) {
	
	// if ok to use flash aboutus
	if (coolAboutFlag) 
	{
		if (isVisible) {
			document.getElementById('flashcontent').style.visibility = 'hidden';
			
			toggleMask(true);
			showHideLayer ('verInfoDIV',isVisible);
			// play flash effect within swf file
			
			var swfVerFile = document.getElementById("swfVersionInfo");
			swfVerFile.play();
			
			//document.getElementById('contentIFRAME').style.display = 'block';
		}	
		else 
		{
			
			toggleMask(false);
			
			document.getElementById('flashcontent').style.visibility = 'visible';
			showHideLayer ('verInfoDIV',isVisible);
			//document.getElementById('contentIFRAME').style.display = 'block';
		}
	}
	else 
	{
		jumpToURL('/aboutus/','xmlContentTD');
	}	
}


// #############################################
// make version info box draggable
// #############################################
function makeDraggable(handleID,objectID) 
{
	
	var dragHandle = document.getElementById(handleID);
	if(objectID) var dragBox = document.getElementById(objectID);
	else var dragBox = null;
	
	//alert(screen.availWidth + ' h:' + screen.availHeight);
	
	//alert(dragBox.offsetWidth);
	minX = 0;
	maxX = (dragBox == null)? screen.availWidth - dragHandle.offsetWidth : screen.availWidth - dragBox.offsetWidth; //document.body.offsetWidth - 452;
	minY = 0;
	maxY = (dragBox == null)? screen.availHeight - dragHandle.offsetHeight : screen.availHeight - dragBox.offsetHeight; //document.body.offsetHeight - 322;
	Drag.init( dragHandle, dragBox, minX, maxX, minY, maxY); // item, null, minX, maxX, minY, maxY
}
// #############################################
// special signup jump   and  smc popup
// #############################################
function getSignUp() {
	open_window('http://smc.silvercash.com/signup/' , 'smcWin', 'status=1,scrollbars=1,resizable=1,width=950,height=650'); 
}
function doLoginPopup(href)
{	
	open_window(href, 'smcWin', 'status=1,scrollbars=1,resizable=1,width=950,height=650'); 
	//top.location = '/splash/';
	return false;
}
// #############################################
// show/hide function  w/ plus/minus imgs
// #############################################

function showHide(obj) {
	var theImg = 'img_' + obj;
	getObjectID(theImg).src = '/images/btn_minus.gif';
	
	// if item is currently visible.. hide it
	if (getObjectID(obj).style.display == 'block') {
		// hide section
		getObjectID(obj).style.display = 'none';
		
		// toggle to img +
		getObjectID(theImg).src = '/images/btn_plus.gif';
	}
	else {
		// show section
		getObjectID(obj).style.display = 'block';
		
		// toggle to img -
		getObjectID(theImg).src = '/images/btn_minus.gif';
	}
	
	
	
	
}
