// Defining any constants here
var U_PLAYER = 1;
var U_CPROD = 2;
var U_SCOUT = 3;
var U_FAN = 4;
var U_TEAM_MGMT = 5;
var U_SUPER_ADMIN = 7;

function obj(name)
{
	return document.getElementById(name);
}

var stType = "Asset";
function AddToStarCard(MediaAssetID, Season, Type, AddTo, TeamID)
{
		stType = Type;
		if(Type == "Asset")
		{
			var params = "&TeamID=" + TeamID + "&MediaAssetID=" + MediaAssetID + "&Type=" + Type + "&SeasonID=" + Season + "&AddTo=" + AddTo;
			
		}
		else
		{
			var params = "&TeamID=" + TeamID + "&BuddyValue=" + MediaAssetID + "&Type=" + Type + "&SeasonID=" + Season + "&AddTo=" + AddTo;
			
		}
		
		//alert(params);
		var url = "/ajax/ajx_addtostarcard.php";
		xmlHttp = GetXmlHttpObject(DisplayAddToStarCardResult);
		xmlHttp.open("POST", url , true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.send(params);
}

function AddToTeamToFavorites(MediaAssetID, Season, Type, AddTo, TeamID)
{
	var subscribed = (document.getElementById("subscribed").checked) ? 1 : 0;
	var params = "&TeamID=" + TeamID + "&BuddyValue=" + MediaAssetID + "&Type=" + Type + "&SeasonID=" + Season + "&AddTo=" + AddTo+ "&Subscribed=" + subscribed;
	var url = "/ajax/ajx_addtostarcard.php";
	xmlHttp = GetXmlHttpObject(DisplayAddToTeamFavResult);
	xmlHttp.open("POST", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);
}


function DisplayAddToTeamFavResult()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
			obj("AddToPanel").innerHTML = xmlHttp.responseText;
			//obj("AddToPanel").style.marginLeft = "80px";
			obj("AddToPanel").style.display = "block";
	}
}

function DisplayAddToStarCardResult()
{
		
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		if(stType == "Asset")
		{
			obj("AddToPanel").innerHTML = xmlHttp.responseText;
			//obj("AddToPanel").style.marginLeft = "80px";
			obj("AddToPanel").style.display = "block";
		}
		else
		{		
			obj("AddToPanel_Team").innerHTML = xmlHttp.responseText;
			//obj("AddToPanel_Team").style.marginLeft = "80px";
			obj("AddToPanel_Team").style.visibility = "visible";
		}
	}
}

function AddDropOption(val,text)
{
	
}


function OpenVideoUpload(url)
{
	LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0
	var videowin = window.open(url,"videowin","width=600,height=450,top=" + TopPosition + ",left=" + LeftPosition + ",status=1");
	videowin.focus();
}
function OpenChannelVideoUpload(url)
{
	LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0
	var videowin = window.open(url,"videowin","width=600,height=590,top=" + TopPosition + ",left=" + LeftPosition + ",status=1,scrollbars=1,");
	videowin.focus();
}


function UpdateAvatar(url)
{
	LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0
	var photowin = window.open(url,"photowin","width=800,height=580,top=" + 50 + ",left=" + 100 + ",status=1,scrollbars=1,resizable=1");
	photowin.focus();
}

function UpdatePhoto(url)
{
	LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0
	var photowin = window.open(url,"photowin","width=900,height=580,top=" + 50 + ",left=" + 100 + ",status=1,scrollbars=1,resizable=1");
	photowin.focus();
}


function LoadFlashItem(src,ht,wd)
{
       document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="' + ht + '" width="' + wd +'">');
       document.write('<param name="movie" value="' + src + '">');
       document.write('<param name="quality" value="best">');
       document.write('<param name="play" value="true">');
       document.write('<PARAM NAME="wmode" VALUE="opaque">');
       document.write('<embed height="' + ht + '"  pluginspage="http://www.macromedia.com/go/getflashplayer" src="' + src  + '" type="application/x-shockwave-flash" wmode="opaque" width="' + wd + '"  quality="best" play="true"></object>');
}

	function openPhoto(url)
	{
	LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
		
		var w = window.open(url, "wwin" ,"width=620,height=640,scrollbars=1,top="+0+",left="+LeftPosition);
		w.focus();
	}
	
function checkMail(email)
{
	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x);
}



var f_EmailExists = false;
function emailExists(email)
{
	f_EmailExists = false;
	var params = "email=" + email;
	var url = "/ajax/ajx_emailexists.php";
	xmlHttp = GetXmlHttpObject(ShowEmailExists);
	xmlHttp.open("POST", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);
}

function ShowEmailExists()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		if(xmlHttp.responseText == "1")
		{
			alert("The Email address already exsts under a different LocalReplay account. Please use a unique email address.");
			f_EmailExists = true;
		}
		
	}
}

var f_UserExists = false;
function userExists(username)
{
	f_UserExists = false;
	var params = "username=" + username;
	var url = "/ajax/ajx_userexists.php";
	xmlHttp = GetXmlHttpObject(ShowUserExists);
	xmlHttp.open("POST", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);
}

function ShowUserExists()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		if(xmlHttp.responseText == "1")
		{
			alert("The Username you entered already exsts under a different LocalReplay account. Please use a unique username.");
			f_UserExists = true;
		}
	}
}

var f_OfAge = false;
function isOfAge(bDate)
{
	f_OfAge = false;
	var params = "bdate=" + bDate;
	var url = "/ajax/ajx_isofage.php";
	xmlHttp = GetXmlHttpObject(ShowIsOfAge);
	xmlHttp.open("POST", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);
}

function ShowIsOfAge()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		if(xmlHttp.responseText == "1")
		{
			alert("You must be at least 13 years old to register for LocalReplay.com. Please contact your parent or guardian to assist you in registering.");
			f_OfAge = true;
		}
	}
}


function SendToAFriend(base, url, teamid,assetid,season)
{
	
	var sUrl = "";
	var winSize = "width=550,height=550";
	sUrl = base + "sendtofriend/send.php?assetid=" + assetid + "&teamid=" + teamid + "&season=" +  season + "&url="+ escape(url);
	
	var stfwin = window.open(sUrl, "stfwin", winSize);
	stfwin.focus();
}
	
function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
	

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function AddProfileToFriends()
{
	//grayOut(true, {'zindex':'50', 'bgcolor':'#04234a', 'opacity':'70'});
	document.getElementById("AddToFriendsPanel_BG").style.visibility = "visible";
	document.getElementById("AddToFriendsPanel").style.visibility = "visible";
}
function CancelAddToFriend()
{
	document.getElementById("AddToFriendsPanel_BG").style.visibility = "hidden";
	document.getElementById("AddToFriendsPanel").style.visibility = "hidden";
}

function AddToFriends(player,user)
{
	var params = "?player=" + player + "&user=" + user;
	
	var url = "../ajax/ajx_addtofriends.php" + params;
	xmlHttp = GetXmlHttpObject(AddToFriendsResult);
	xmlHttp.open("GET", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);	
}

function AddToFriendsResult()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		
			if(xmlHttp.responseText == "Request Sent")
			{
				document.getElementById('AddToFriendsPanel').innerHTML  = '<div style="padding:12px;text-align:center;">An email had been sent to the user with your request.<br/><br/><a href="javascript:CancelAddToFriend()" style="color:blue;"><strong>Close</strong></a></div>';
			}	
	}
}


function SetPhotoRating(PlayerId,rating,AssetID)
{
	var params = "?PlayerId=" + PlayerId + "&Rating=" + rating + "&AssetID=" + AssetID;
	var url = "../ajax/ajx_ratephoto.php" + params;
	//alert(params);
	xmlHttp = GetXmlHttpObject(GetPhotoRatingResult);
	xmlHttp.open("GET", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);	
}


function GetPhotoRatingResult()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		
			if(xmlHttp.responseText == "Accepted")
			{
				document.getElementById('RatingPanel').innerHTML  = '<img src="../images/common/rating_p_6.gif" name="rateImg"/>';
			}
			
		
	}
}


function SetRating(rdid,rating,key)
{
	var params = "?RDID=" + rdid + "&Rating=" + rating + "&Key=" + key;
	var url = "ajax/ajx_ratevideo.php" + params;
	//alert(params);
	xmlHttp = GetXmlHttpObject(GetRatingResult);
	xmlHttp.open("GET", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);	
}


function GetRatingResult()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		
			if(xmlHttp.responseText == "Accepted")
			{
				document.getElementById('RatingPanel').innerHTML  = '<img src="images/common/rating6.gif" name="rateImg"/>';
			}
			
		
	}
}

function GetPhotoStats(assetid)
{
	var params = "?MediaAssetID=" + assetid;;
	var url = "ajax/ajx_getphotostats.php" + params;
	//alert(params);
	xmlHttp = GetXmlHttpObject(GetStatsResult);
	xmlHttp.open("GET", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.send(params);	
}

function GetStatsResult()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		
			if(xmlHttp.responseText.length > 0)
			{
				xDoc = loadXML(xmlHttp.responseText);		
				root = xDoc.documentElement;
				var rStr = "";
				if(root.childNodes.length > 0)
				{
					rStr += "Recent Views: " + root.childNodes[0].getAttribute("NumViews") + "<br/>";
					rStr += "Avg Rating: " + root.childNodes[0].getAttribute("AvgRating") + "<br/>";
					rStr += "Collections: " + root.childNodes[0].getAttribute("UsersLinked");
					document.getElementById('PhotoStatsPanel').innerHTML  = rStr;
				}
				
			}
			
		
	}
}

function getPageCtrWdth() {

	// Get pagewidth to center layer 
	if (self.innerWidth) {
		pageWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		pageWidth = document.documentElement.clientWidth;
	}
	else if (document.body) {
		pageWidth = document.body.clientWidth;
	}

	return pageWidth;
}

function getPageCtrHght() {

	// Get pageheight to center layer 
	if (self.innerWidth) {
		pageHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		pageHeight = document.documentElement.clientHeight;
	}
	else if (document.body) {
		pageHeight = document.body.clientHeight;
	}
	
	return pageHeight;
}

function isAlphaNumeric(str) {
	
	// Pull the regex out of the function and use test()
	//  instead of match() so that the regex is only
	//  compiled once, not on each call.
	var regExpr = /[^a-zA-Z0-9]/;

    return !regExpr.test(str);
}

function isNumeric(str) {
	
	// Pull the regex out of the function and use test()
	//  instead of match() so that the regex is only
	//  compiled once, not on each call.
	var regExpr = /[^0-9]/;

    return !regExpr.test(str);
}

function URLDecode(psEncodeString) {
	
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
	} 
	from.selectedIndex = -1; 
} 

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
}

function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
	}
}

function capitalizeMe(s){

    if(void(0)==s||null==s) return "";
	
    if("object"==typeof(s)) s = s.nextNode.text;

    if(void(0)==s||""==s) return "";

    var result = "";
    var words = s.split(" ");
    var count = words.length;

    for(var i=0;i<count;i++) {
		
		var badchars = '.-"([';
		var newWordResult = "";
		chgWord = false;
		for (j = 0; j < badchars.length; j++) {
			lsRegExpr = new RegExp("\\" + badchars[j], "g");
			newWord = words[i].replace(lsRegExpr, badchars[j] + " ");
			if (words[i] != newWord) {
				specialWords = newWord.split(" ");
				spWordResult = "";
				for (k = 0; k < specialWords.length; k++) {
					spWordResult += parse(specialWords[k]);
				}

				if (specialWords.length = 0) {
					spWordResult = parse(newWord);
				}

				newWordResult += spWordResult;
				chgWord = true;
			}
		}

		if (chgWord) {
			result += newWordResult + " ";
		}
		else {
			result += parse(words[i]) + " ";
		}

    }

    return result;

    ////////////////////////////////////////
    //internal method
    function parse(s){
       if(void(0)==s||""==s) return "";
       if(isNaN(parseInt(s))) {

			return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();
       }
       else {
          return s;
       }
    }
	
}


function SetLink(instance)
{
	document.body.style.cursor = 'pointer';
	instance.style.textDecoration = 'underline';
	return true;
}

function UnSetLink(instance)
{
	document.body.style.cursor = 'default';
	instance.style.textDecoration = 'none';
	return true;
}

function sleep(sec)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < (sec*1000));
} 

function CheckAllEmails(instance)
{
	if(instance.value == "")
	{
		alert("Please enter at least one email address.");
		return false;
	}

	tmpInstance = instance.value.replace(/\n/g, ",");
	tmpInstance = tmpInstance.replace(/\r/g, ",");
	if(tmpInstance.indexOf(",") > -1)
	{

		var email = tmpInstance.split(",");
		for(i=0; i < email.length; i++)
		{
			if(email[i].length > 0)
			{
				if(!checkMail(email[i].replace(/^\s+|\s+$/g, '')))
				{
					alert("In-valid email address (" + email[i] + ") entered. Please enter valid email addresses (ie name@server.com)");
					return false;
				}
				
			}
		}
	}
	else
	{
		if(!checkMail(tmpInstance.replace(/^\s+|\s+$/g, '')))
		{
			alert("In-valid email address (" + instance.value + ") entered. Please enter valid email addresses (ie name@server.com)");
			return false;
		}
	}
	
	// Looks like we passed our tests so submit the form
	return true;
}

function trimZipCode(zipCode)
{
	return zipCode.substr(zipCode.length - 5, 5);
}

// Flicker fix on IE6
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

// Get browser stats
var browserName = navigator.appName;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirefox     = (ua.indexOf('firefox/') != -1 || ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

document.onmousemove = getMousePosition;
var curMouseX = 0;
var curMouseY = 0;
function getMousePosition(e) {
  var _x;
  var _y;
  if (!browser.isIE) {
    _x = e.pageX;
    _y = e.pageY;
  }
  if (browser.isIE) {
    _x = event.clientX + document.body.scrollLeft;
    _y = event.clientY + document.body.scrollTop;
  }
  curMouseX = _x;
  curMouseY = _y;
  //document.exf1.x.value=_x;
 // document.exf1.y.value=_y;
  return true;
}


function displayMainHelp(instance, value, e, x, y)
{
	getMousePosition(e);
	
	if (value == 1) {
		
		//if (browser.isSafari)
			//instance.style.top = y - 35;
		//else
			instance.style.top = y + "px";
			
		instance.style.left = x + "px";
		instance.style.display = 'block';
		
		if (browserName == "Microsoft Internet Explorer" && IE6) {
			var helpMainPopupFrame = obj("HelpMainPopupFrame");
			helpMainPopupFrame.style.display = 'block';
		}		
		
	}
	else {
		instance.style.display = 'none';

		if (browserName == "Microsoft Internet Explorer" && IE6) {
			var helpMainPopupFrame = obj("HelpMainPopupFrame");
			helpMainPopupFrame.style.display = 'none';
		}		
		
	}
	return true;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}