﻿
// Commonly-used functions
function d(s) {return document.getElementById(s);}
function dE(o,s) {return o.getElementsByTagName(s);}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "IE"
else if (checkIt('firefox')) browser = "FireFox"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function NavigatePage(url)
{
	window.location.href=url;
}

function openChild(file,window,arguments) 
{

    childWindow=open(file,window,arguments);
    if (childWindow.opener == null) childWindow.opener = self;
}

function openIframe(id,src,parent)
{
	var o=getElement(id);	
	parent.opener=parent;
	o.src=src;
}

function toggleDisplay(o)
{  
  var display = getStyle(o, "display"); 
  
  if (o.style)
    o.style.display =
      (display != "none") ? "none" : getDisplayStyleByTagName(o);
}

function toggleDisplayByID(id)
{  

  var o= getElement(id);
  
  var display = getStyle(o, "display"); 
  
  if (o.style)
    o.style.display =
      (display != "none") ? "none" : getDisplayStyleByTagName(o);
}



function getDisplayStyleByTagName(o)
{
  n = o.nodeName.toLowerCase(); 
  return (
          n == "span"
          || n == "img"
          || n == "a"
          ) ? "inline" : "block";
}



function hideElement(o)
{
  if (o && o.style)	o.style.display = "none";
	 
}




function showElement(o)
{
  
  if (o && o.style) o.style.display = getDisplayStyleByTagName(o);  
  o.style.zIndex=5000;  
}

function elementExists(id)
{
  var e = d(id);
  if (!e) {
    return false;
  }
  return true;
}

function getElement(id) {
  var e = d(id);
  //if (!e) {
     //alert("Cannot get element: " + id);
  //}
  return e;
}


function setInnerHTML(id, html) {
  try {
    getElement(id).innerHTML = html;
  } catch (ex) {
    alert("Cannot set inner HTML: " + id);
  }
}



function setCssStyle(id, name, value) {
  try {
    getElement(id).style[name] = value;
  } catch (ex) {
    alert("Cannot set style: " + id);
  }
}



function getStyle(el, style) {
  if (!document.getElementById || !el) return;
  
  if (document.defaultView
      && document.defaultView.getComputedStyle) {
      return document.defaultView.
        getComputedStyle(el, "").getPropertyValue(style);
  }  
  else if (el.currentStyle) {
    return el.currentStyle[style];
  }  
  else { 
    return el.style.display;
  }
}

function getStyleAttribute(node) {
  if (Detect.IE()) {
    return node.getAttribute('style').value;
  }else {
    return node.getAttribute('style');
  }
}



function showProps(o) {
	s=""; for (p in o) {
		s+=p+": "+o[p]+"\n<br />";
	}
	document.write(s);
}



function setIFrameEvent(iframe, eventName, func)
{
  if (document.all) {
    eval('getIFrameDocument(iframe).on' + eventName + ' = func;');
  } else {
    iframe.contentWindow.addEventListener(eventName, func, true);
  }
}

function setIFrameBody(iframe, strStyle, innerHtml) 
{
  if (!innerHtml) innerHtml = '';
  if (innerHtml == '' && Detect.IE()) {
    innerHtml = '<div></div>';
  }
  var doc = getIFrameDocument(iframe);
  doc.open();
  doc.write('<body style="' + strStyle + '">' 
    + innerHtml + '</body>');
  doc.close();
}


function getIFrameDocument(iframe)
{
  if (Detect.IE()) {
    return iframe.document;
  } else {
    return iframe.contentDocument;
  }
}

function getIFrame(strId)
{
  if (Detect.IE()) {
    return document.frames[strId];
  } else {
    return document.getElementById(strId);
  }
}


function createElementandAppend(nodeName, strId, appendTo) {
  var el = document.createElement(nodeName);
  el.setAttribute("id", strId);
  if (appendTo) {
    appendTo.appendChild(el);
  } else {
    document.body.appendChild(el); 
  }
  return el; 
}

function createElementandInsertBefore(nodeName, strId, appendTo, sibling) {
  var el = document.createElement(nodeName);
  el.setAttribute("id", strId);
  if (appendTo) {
    appendTo.insertBefore(el, sibling); 
  } else {
    document.body.insertBefore(el, sibling); 
  }
  return el; 
}


/**
* getXY()
 *
 * Returns the position of any element as an object.
 *
 * Typical usage:
 * var pos = getXY(object);
 * alert(pos.x + " " +pos.y);
 */
function getXY(el) {
  var x = el.offsetLeft;
  var y = el.offsetTop;
  if (el.offsetParent != null) {
    var pos = getXY(el.offsetParent);
    x += pos.x;
    y += pos.y;
  }
  return {x: x, y: y}
}

/* Constants for node types, since IE doesn't support Node.TEXT_NODE */
var TEXT_NODE = 3;
var ELEMENT_NODE = 1;


function absX (elm) 
{
	var x = 0;
	if (elm && typeof elm.offsetParent != "undefined") {
	while (elm && typeof elm.offsetLeft == "number") {
	x += elm.offsetLeft;
	elm = elm.offsetParent;
	}
	}
	return x;
}

function absY(elm)
{
	var y = 0;
	if (elm && typeof elm.offsetParent != "undefined") {
	while (elm && typeof elm.offsetTop == "number") {
	y += elm.offsetTop;
	elm = elm.offsetParent;
	}
	}
	return y;
}

function PopCenter(popW,popH,url)
{
var w = 480, h = 340; 
if (document.all || document.layers) { 
w = screen.availWidth; 
h = screen.availHeight; 
} 
var leftPos = (w-popW)/2, topPos = ((h-popH)/2); 
window.open(url,null,'scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function TogFromParent(framename){
parent.currentobj=null;
parent.document.getElementById(framename).style.display="none";
}

function SwitchDisable(obj)
{
	obj.disabled = !obj.disabled;
}

// Dorcht's function
function createCookie(name, value, expires, path, domain, secure) {

	document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
  
}


function deleteCookie (name,path,domain) {

var expDate = new Date();
expDate.setTime (expDate.getTime());
if (GetCookie(name)) {
	document.cookie = name + "=" + escape(GetCookie(name)) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	"; expires="+ expDate.toGMTString();
}
}

function GetCookie(name)
{
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

//window.onload=movemouse();
var nn62=document.getElementById&&!document.all;

//document.onmousemove=ssmovemouse;

var lastbutton;
var lastcss;

function ssmovemouse(e)
{  
	var o  = nn62 ? e.target : event.srcElement;
	
	if (lastbutton==o)
	{
		return;
	}	
	else
	{
		if (lastbutton!=null)
		{
		lastbutton.className=lastcss;
		lastbutton=null;
		}
	}
/*
	if (o != null)
	{	
		if (o.className!=null)
		{
			if (o.className.length > 8)
			{
				if (o.className.substring(0,8)=='ssbutton')
				{
				
					lastbutton=o;
					lastcss=o.className;
					o.className=o.className	+ 'over';
					return;
				
					
				}			
			}	
			
			if (o.getAttribute('ssq')!=undefined)
			{			
				var oq=getElement(o.getAttribute('ssq'));			
				lastbutton=oq;			
				ShowQuote(oq);
			}
			else
			{ 
			
				if (o.className!='bottompop' && o.id!='ssquotetext' && o.className!='midpop')
				{
				HideQuote();
				
				}
				
			
			
			}
		
		}
		
		
	}
	*/
}


function xreplace(checkMe,toberep,repwith)
{ 
	var temp = checkMe; 
	var i = temp.indexOf(toberep); 
	while(i > -1){ 
	temp = temp.replace(toberep, repwith); 
	i = temp.indexOf(toberep); 
	} 
	return temp; 
}

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];
    }
  }  
}

function PlayItem(profilemoduleid , url) 
{	
	document.getElementById(profilemoduleid).url = url;
	//document.getElementById(profilemoduleid).Play();

}

var lastquote;




function ShowQuote(o3)
{ 

var quotetable=o3;

o3=getElement(xreplace(o3.id,'maintable','pquotediv'));

if (elementExists('ssquote')==false)
{
	return;
}


if (elementExists('ssquotetext')==false)
{
	return;
}

var o=getElement('ssquote');
var o2=getElement('ssquotetext');

var oquotebot =getElement('ssquotebottom');

if (o3.innerHTML=='')
{
	if (o.style.display != 'none')
	{
	hideElement(o);		
	}
	return false;
}
else
{
	if (o.style.display != 'none' && lastquote==o3.innerHTML)
	{
		return false;
	}
}

lastquote=o3.innerHTML;

var cloned1=o3.cloneNode(true);

if (o2.childNodes.length > 0)
{
	//var nc=0;
	//for (var nc=0;nc<o2.childNodes.length;nc++)
	//{
		o2.removeChild(o2.childNodes[0]);
		//o2.childNodes.clear();
	//}
	
}

if (o2.childNodes.length == 0)
{
	o2.insertBefore(cloned1,null);	
}
else
{
	o2.removeChild(o2.childNodes[0]);
	o2.insertBefore(cloned1,null);	
}

showElement(cloned1);

showElement(o);



if (browser=='FireFox')
{
	quotetable.style.position='absolute';
}	

var leftx=absX(quotetable)-170;

quotetable.style.position='';

if (leftx < 0)
{	
	oquotebot.className='bottompop2';
	//oquotebot.style.backgroundImage='url(http://www.supersociety.com/_images/Themes/SST0/bottompopup2.gif)';
	leftx= leftx + 250;
}
else
{
	oquotebot.className='bottompop';
	//oquotebot.style.backgroundImage='url(http://www.supersociety.com/_images/Themes/SST0/bottompopup.gif)';
}

o.style.left=leftx;

o.style.top=absY(quotetable) - (o2.offsetHeight + 20);


}

function HideQuote()
{

if (elementExists('ssquote')==false)
{
	return;
}


	var o=getElement('ssquote');
		
	hideElement(o);
		
}

function DisableButton(obj,msg)
{
if(bclicked==0){
	obj.value = msg
	bclicked = 1;
	//__doPostBack(obj.id);
}
else
	{
	obj.disabled = !obj.disabled;
	}
	
}

function DoEnter(obj)

{
if (event.keyCode == 13)
{event.cancelBubble = true;
event.returnValue = false;
getElement(obj).click();
}
}

ie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));

function toggle( targetId ){
  
  
		if (getElement(targetId).style.display=='')
		{
		 getElement(targetId).style.display = 'none';
		}
		else
		{
		 getElement(targetId).style.display = '';
		}

	
    	 
}
