    var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		    { 	string: navigator.userAgent,
			    subString: "OmniWeb",
			    versionSearch: "OmniWeb/",
			    identity: "OmniWeb"
		    },
		    {
			    string: navigator.vendor,
			    subString: "Apple",
			    identity: "Safari"
		    },
		    {
			    prop: window.opera,
			    identity: "Opera"
		    },
		    {
			    string: navigator.vendor,
			    subString: "iCab",
			    identity: "iCab"
		    },
		    {
			    string: navigator.vendor,
			    subString: "KDE",
			    identity: "Konqueror"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "Firefox",
			    identity: "Firefox"
		    },
		    {
			    string: navigator.vendor,
			    subString: "Camino",
			    identity: "Camino"
		    },
		    {		// for newer Netscapes (6+)
			    string: navigator.userAgent,
			    subString: "Netscape",
			    identity: "Netscape"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "MSIE",
			    identity: "Explorer",
			    versionSearch: "MSIE"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "Gecko",
			    identity: "Mozilla",
			    versionSearch: "rv"
		    },
		    { 		// for older Netscapes (4-)
			    string: navigator.userAgent,
			    subString: "Mozilla",
			    identity: "Netscape",
			    versionSearch: "Mozilla"
		    }
	    ],
	    dataOS : [
		    {
			    string: navigator.platform,
			    subString: "Win",
			    identity: "Windows"
		    },
		    {
			    string: navigator.platform,
			    subString: "Mac",
			    identity: "Mac"
		    },
		    {
			    string: navigator.platform,
			    subString: "Linux",
			    identity: "Linux"
		    }
	    ]

    };
    BrowserDetect.init();
    var browser=BrowserDetect.browser;



/* used to handle the enter key event for an element */
function fnEnterKey(e, target)
{
	if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
	{
		__doPostBack(target,'');
	}
}	

function IsEscKeyPressed(e)
{
	if ((e.which && e.which == 27) || (e.keyCode && e.keyCode == 27))
		return true;
}

function ApplySelectedTagToMyTagText(MyTagTextBoxId, TagText)
{
    if(document.getElementById(MyTagTextBoxId).value.indexOf(TagText) == -1)
    {
        document.getElementById(MyTagTextBoxId).value = trim(document.getElementById(MyTagTextBoxId).value)
        if(document.getElementById(MyTagTextBoxId).value == "")
        {
            document.getElementById(MyTagTextBoxId).value = TagText
        }
        else
        {
            document.getElementById(MyTagTextBoxId).value += " " + TagText
        }
    }
}        
// Removes leading whitespaces
function LTrim( value ) 
{
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) 
{
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value ) 
{	
    return LTrim(RTrim(value));	
}

/* used to handle the enter key event for an element */
function IsEnterKeyPressed(e)
{
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))	
        return true;
}        

/* text counter */
function textCounter(field,cntfield,maxlimit)
{
    var newlineOffset = 0;
    var findThem = /\n/g;    // Look for new lines
    results = field.value.match(findThem);
    if (results != null)
        newlineOffset = results.length;

    if ((field.value.length + newlineOffset) > maxlimit) // if too long...trim it!	
        field.value = field.value.substring(0, (maxlimit - newlineOffset));	
    else // otherwise, update 'characters left' counter
        cntfield.innerHTML = maxlimit - (field.value.length + newlineOffset);
}        

//Rating box related functions
function mOverR(id,img,count)
{
    var myover = SetArrayMouseOver(id);
    for(i=0;i<count;i++){
        $("#"+img+i).attr("src",myover[i]);
    }
}
function mOutR(id,img,array)
{
    var myout = SetArrayMouseOut(id,array);
    for(i=0;i<5;i++){
        $("#"+img+i).attr("src",myout[i]);
    }
}
function clickR(array,position,el)
{
    for(i=0;i<5;i++){
        $("#"+el+i).removeAttr("onclick");
        $("#"+el+i).removeAttr("onmouseover");
        $("#"+el+i).removeAttr("onmouseout");
    }
    for(i=0;i<position;i++){
        array[i] = 2;
    }    
}
function SetArrayMouseOver(id)
{
    if(id=="I")
    {return new Array("/images/darkbluestar2.gif","/images/darkbluestar2.gif","/images/darkbluestar2.gif","/images/darkbluestar2.gif","/images/darkbluestar2.gif");}
    if(id=="N")
    {return new Array("/images/bluestar2.gif","/images/bluestar2.gif","/images/bluestar2.gif","/images/bluestar2.gif","/images/bluestar2.gif");}
    if(id=="Q")
    {return new Array("/images/lightbluestar2.gif","/images/lightbluestar2.gif","/images/lightbluestar2.gif","/images/lightbluestar2.gif","/images/lightbluestar2.gif");}
    if(id=="C")
    {return new Array("/images/claritystar2.gif","/images/claritystar2.gif","/images/claritystar2.gif","/images/claritystar2.gif","/images/claritystar2.gif");}
    if(id=="R")
    {return new Array("/images/respectstar2.gif","/images/respectstar2.gif","/images/respectstar2.gif","/images/respectstar2.gif","/images/respectstar2.gif");}
}
function SetArrayMouseOut(id,array)
{
    if(id=="I")
    {return new Array("/images/darkbluestar"+array[0]+".gif","/images/darkbluestar"+array[1]+".gif","/images/darkbluestar"+array[2]+".gif","/images/darkbluestar"+array[3]+".gif","/images/darkbluestar"+array[4]+".gif");}
    if(id=="N")
    {return new Array("/images/bluestar"+array[0]+".gif","/images/bluestar"+array[1]+".gif","/images/bluestar"+array[2]+".gif","/images/bluestar"+array[3]+".gif","/images/bluestar"+array[4]+".gif");}
    if(id=="Q")
    {return new Array("/images/lightbluestar"+array[0]+".gif","/images/lightbluestar"+array[1]+".gif","/images/lightbluestar"+array[2]+".gif","/images/lightbluestar"+array[3]+".gif","/images/lightbluestar"+array[4]+".gif");}
    if(id=="C")
    {return new Array("/images/claritystar"+array[0]+".gif","/images/claritystar"+array[1]+".gif","/images/claritystar"+array[2]+".gif","/images/claritystar"+array[3]+".gif","/images/claritystar"+array[4]+".gif");}
    if(id=="R")
    {return new Array("/images/respectstar"+array[0]+".gif","/images/respectstar"+array[1]+".gif","/images/respectstar"+array[2]+".gif","/images/respectstar"+array[3]+".gif","/images/respectstar"+array[4]+".gif");}
}
function HBMOver(el)
{
    var ie = (document.all && !window.opera);
    var ie6 = (ie && document.createAttribute && !window.XMLHttpRequest) ? true : false;
    if(ie6){$(el).css("position","relative");}
}
function HBMOut(el)
{
    var ie = (document.all && !window.opera);
    var ie6 = (ie && document.createAttribute && !window.XMLHttpRequest) ? true : false;
    if(ie6){$(el).css("position","static");}
}

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 var 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;
}

function eraseCookie(name) { createCookie(name,"",-1); }

/*
 * Thickbox 2.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2006 cody lindley
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 * Thickbox is built on top of the very light weight jQuery library.
 */
//on page load call TB_init
//$(document).ready(TB_init);
var assetid = "0";
//var webserverurl = "http://www.givecents.com/gmi20/";
function SetAssetID()
{
 try{
    assetid = $("#assetid").val();
    //webserverurl = $("#webserverurl").val();
 }catch(err){}
}
//add thickbox to href elements that have a class of .thickbox
function TB_init(){
    
	$("a.thickbox").click(function(){
	var t = this.title || this.name || null;
	var g = this.rel || false;
	TB_show(t,this.href,g,0);
	this.blur();
	return false;
	});
}
function TB_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
	    $("#TB_overlay").css({display:"block"});
	    $("#TB_HideSelect").css({display:"block"});
		if (document.getElementById("TB_HideSelect") == null) {
		//$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		$("#TB_overlay").click(TB_remove);
		}
		
		if(caption==null){caption=""};
		
		try{
        $(window).scroll(TB_position);
        } catch(err){
        //alert(err );
        }
 		
		TB_overlaySize();
		
		$("body").append("<div id='TB_load'><img src='"+webserverurl+"images/loadingAnimation.gif' /></div>");
		TB_load_position();
		
		
		
	   if(url.indexOf("?")!==-1){ //If there is a query string involved
			var baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		var baseURL = url;
	   }
	   var urlString = /\.jpg|\.jpeg|\.png|\.gif|\.bmp/g;
	   var urlType = baseURL.toLowerCase().match(urlString);
		
		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML == "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = TB_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div>"); 		
			
			$("#TB_closeWindowButton").click(TB_remove);
			
			if (!(TB_PrevHTML == "")) {
				function goPrev(){
					if($(document).unbind("click", goPrev)){$(document).unbind("click", goPrev)};
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					TB_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML == "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					TB_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}
			
			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					TB_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
					document.onkeydown = "";
					goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
					document.onkeydown = "";
					goPrev();
					}
				}	
			}
				
			TB_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(TB_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			}
	  
			imgPreloader.src = url;
		}else{//code to show html pages
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = TB_parseQuery( queryString );
			
			TB_WIDTH = (params['width']*1) + 30;
			TB_HEIGHT = (params['height']*1) + 40;
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){				
					urlNoQuery = url.split('TB_');		
					$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' onload='TB_showIframe()'> </iframe>");
				}else{
					$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
			}
					
			$("#TB_closeWindowButton").click(TB_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").html($('#' + params['inlineId']).html());
					TB_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					TB_position();
					if(frames['TB_iframeContent'] == undefined){//be nice to safari
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
						$(document).keyup( function(e){ var key = e.keyCode; if(key == 27){TB_remove()} });
					}
				}else{
					$("#TB_ajaxContent").load(url, function(){
						TB_position();
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"}); 
					});
				}
			
		}
		
		try{
        $(window).resize(TB_position);
        } catch(err){
        //alert(err );
        }
		
		document.onkeyup = function(e){ 	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				TB_remove();
			}	
		}
		
	} catch(e) {
		//alert( e );
	}
}
function TB_show_flickr(caption, url, imageGroup, photoid, controlindex) {
	try {	
	    $("#TB_overlay").css({display:"block"});
	    $("#TB_HideSelect").css({display:"block"});
	    //var inspired = callWebServiceToSeeInspired(photoid);
	    //var flaged = callWebServiceToSeeFlag(photoid);
	   	SetAssetID();
	   	
		if (document.getElementById("TB_HideSelect") == null) {
		    //$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		    $("#TB_overlay").click(TB_remove);
		}	
		    
		if(caption==null){caption=""};
		try{ $(window).scroll(TB_position); } catch(err){ } 		
		TB_overlaySize();
		
		$("body").append("<div id='TB_load'><img src='"+webserverurl+"images/progressbar.gif' /></div>");
		TB_load_position();	    	
			TB_WIDTH = 540;
			TB_HEIGHT = 480;
			ajaxContentW = TB_WIDTH;
			ajaxContentH = TB_HEIGHT - 45;
			
			$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div>"+
			    "<iframe frameborder='0' hspace='0' src='"+webserverurl+"controls/flickr.aspx?assetid="+assetid+"&photoid="+photoid+"&controlindex="+controlindex+"&url="+url+"' id='TB_iframeContent' name='TB_iframeContent' style='width:540px;height:490px;' onload='TB_showIframe()'> </iframe>");
				
			$("#TB_closeWindowButton").click(TB_remove);			
			TB_position();
			$("#TB_load").remove();
			$("#TB_window").css({display:"block"}); 
			
		try{ $(window).resize(TB_position); } catch(err){}
		
		document.onkeyup = function(e){ 	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				TB_remove();
			}	
		}		    
	} catch(e) {}
}
function TB_show_youtube(caption, url, imageGroup, photoid, controlindex) {
	try {	
	    $("#TB_overlay").css({display:"block"});
	    $("#TB_HideSelect").css({display:"block"});
	    //var inspired = callWebServiceToSeeInspired(photoid);
	    //var flaged = callWebServiceToSeeFlag(photoid);
	   	SetAssetID();
	   	
		if (document.getElementById("TB_HideSelect") == null) {
		    //$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		    $("#TB_overlay").click(TB_remove);
		}	
		    
		if(caption==null){caption=""};
		try{ $(window).scroll(TB_position); } catch(err){ } 		
		TB_overlaySize();
		
		$("body").append("<div id='TB_load'><img src='"+webserverurl+"images/progressbar.gif' /></div>");
		TB_load_position();	    	
			TB_WIDTH = 470;
			TB_HEIGHT = 480;
			ajaxContentW = TB_WIDTH;
			ajaxContentH = TB_HEIGHT - 45;
			
			$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div>"+
			    "<iframe frameborder='0' hspace='0' src='"+webserverurl+"controls/youtube.aspx?assetid="+assetid+"&photoid="+photoid+"&controlindex="+controlindex+"&url="+url+"' id='TB_iframeContent' name='TB_iframeContent' style='width:470px;height:480px;' onload='TB_showIframe()'> </iframe>");
				
			$("#TB_closeWindowButton").click(TB_remove);			
			TB_position();
			$("#TB_load").remove();
			$("#TB_window").css({display:"block"}); 
			
		try{ $(window).resize(TB_position); } catch(err){}
		
		document.onkeyup = function(e){ 	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				TB_remove();
			}	
		}		    
	} catch(e) {	}
}
function callWebServiceToSeeInspired(photoid)
{
    SetAssetID();
    var output = "<table cellpadding=0 cellspacing=0><tr><td align='right'><b>Inspired?</b></td><td align='left' width='22' id='imageinspired'>"+
        "<a href='' onclick=\"$('#imageinspired').html('<img src="+webserverurl+"images/star-disabled.jpg border=0 />');Set_Cookie( 'inspired-p"+photoid+"-a"+assetid+"', '1', '30', '/', '', '' );getAXAH('"+webserverurl+"websvcs/givemeaningflag.asmx/AddImageInspired?photoid="+
        photoid+"&assetid="+assetid+"','inspiredcount','count');return false;\" title='Inspired'>"+
        "<span id='inspiredimage'><img src="+webserverurl+"images/star-enabled.jpg border=0 /></span></a></td><td>&nbsp;&nbsp;<b>Inspires:</b></td>"+
        "<td><b><font color='#ff7200'><span id='inspiredcount'>0</span></font></b>&nbsp;&nbsp;</td></tr></table>";
    return output;
}
function CheckCookieAndSetInspiredImage(cookiename)
{
    if ( Get_Cookie( cookiename ))
    {
        $('#imageinspired').html("<img src="+webserverurl+"images/star-disabled.jpg border=0 />");
        }
    else
    {
        $('#inspiredimage').html("<img src="+webserverurl+"images/star-enabled.jpg border=0 />");
        }
}
function CheckCookieAndSetFlagedImage(cookiename)
{
    if ( Get_Cookie( cookiename ))
    {
        $('#imgflaged').html("<img src="+webserverurl+"images/flag-disabled.jpg border=0 />");
    }
    if ( !Get_Cookie( "user_id") )
    {
        $('#imgflaged').html("<table cellpadding=0 cellspacing=0><tr><td align=left><img src="+webserverurl+"images/flag-disabled.jpg border=0 /></td><td>(Please,&nbsp;<a href='#' onclick='ShowDialog(); ShowSignInTab();return false;'>login</a>&nbsp;first)");
        }
}
function LoginRedirect()
{
    $("#TB_window").remove();
    $("#TB_load").remove();
    window.location = webserverurl+"login.aspx?ret_link="+window.location.href+"%26m=11";
}
function callWebServiceToSeeFlag(photoid)
{
    SetAssetID();
    return "<table cellpadding=0 cellspacing=0><tr><td align='right'>&nbsp;<b>Flag:</b></td><td align='top' width='22' id='imgflaged'>"+
        "<a href='' onclick=\"$('#imgflaged').html('<img src="+webserverurl+"images/flag-disabled.jpg border=0 />');"+"Set_Cookie( 'flaged-p"+photoid+"-a"+assetid+"', '1', '30', '/', '', '' );"+"getAXAH('"+webserverurl+"websvcs/givemeaningflag.asmx/FlagImage?photoid="+photoid+"&assetid="+assetid+"','imagewasflaged','msg');return false;\" title='Flag'>"+
        "<img id='imageflaged' src="+webserverurl+"images/flag-enabled.jpg align=left border=0 /></a></div></td></tr></table><div id='imagewasflaged' stype='display:none;'>";
}
//helper functions below
function TB_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}
function TB_remove() {
    try{  
 	$("#TB_imageOff").unbind("click");
	$("#TB_overlay").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
	$("#TB_window").css({display:"none"});
	$("#TB_overlay").css({display:"none"});
	$("#TB_HideSelect").css({display:"none"});
	$("#TB_window").html(""); 
	$("#TB_overlay").html(""); 
	$("#TB_HideSelect").html(""); 
	//$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').remove();});
	$("#TB_load").remove();
	} catch(err){}
	return false;
}
function TB_position() {
	var pagesize = TB_getPageSize();	
	var arrayPageScroll = TB_getPageScrollTop();	
	$("#TB_window").css({width:TB_WIDTH+"px",left: (arrayPageScroll[0] + (pagesize[0] - TB_WIDTH)/2)+"px", top: (arrayPageScroll[1] + (pagesize[1]-TB_HEIGHT)/2)+"px" });
}
function TB_overlaySize(){
	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {	
		yScroll = window.innerHeight + window.scrollMaxY;
		xScroll = window.innerWidth + window.scrollMaxX;
		var deff = document.documentElement;
		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
		xScroll -= (window.innerWidth - wff);
		yScroll -= (window.innerHeight - hff);
	} else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
		xScroll = document.body.scrollWidth;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
		xScroll = document.body.offsetWidth;
  	}
	$("#TB_overlay").css({"height":yScroll +"px", "width":xScroll +"px"});
	$("#TB_HideSelect").css({"height":yScroll +"px","width":xScroll +"px"});
}
function TB_load_position() {
	var pagesize = TB_getPageSize();
	var arrayPageScroll = TB_getPageScrollTop();
	$("#TB_load")
	.css({left: (arrayPageScroll[0] + (pagesize[0] - 100)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-100)/2))+"px" })
	.css({display:"block"});
}
function TB_parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}
function TB_getPageScrollTop(){
	var yScrolltop;
	var xScrollleft;
	if (self.pageYOffset || self.pageXOffset) {
		yScrolltop = self.pageYOffset;
		xScrollleft = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
		xScrollleft = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
		xScrollleft = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScrollleft,yScrolltop) 
	return arrayPageScroll;
}
function TB_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}
//object detection to return the correct object depending upon broswer type. Used by the getAXHA(); function.
function getNewHttpObject() {
    var objType = false;
    try {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            objType = new XMLHttpRequest();
        }
    }
    return objType;
}
//Function used to update page content with new xhtml fragments by using a javascript object, the dom, and http.
function getAXAH(url,elementContainer,node){
	//document.getElementById(elementContainer).innerHTML = '<blink class="redtxt">*<\/blink>';
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() {processAXAH(elementContainer);};
	theHttpRequest.open("GET", url);
	theHttpRequest.send(false);

		function processAXAH(elementContainer){
		   if (theHttpRequest.readyState == 4) {
			   if (theHttpRequest.status == 200) {
			   
			    var myXML = ExtractXmlFromTheWebService(theHttpRequest);                                                         
		        for (var i = 0; i<myXML.length; i++) 
		        {
		          var t = myXML[i];
		          var result= ExtractValueFromNode(t, node);
		          document.getElementById(elementContainer).innerHTML = result;
        		}	
				   
			   } else {
				   document.getElementById(elementContainer).innerHTML="<p><span class='redtxt'>Error!<\/span> HTTP request return the following status message:&nbsp;" + theHttpRequest.statusText +"<\/p>";
			   }
		   }
		}
}
//This helper function extracts the pertinent XML from a CDO Web Service
//Normally you would call this function within your AJAX callback function, passing in the original http request
function ExtractXmlFromTheWebService(httpRequest)
{
    var xmlDoc = httpRequest.responseXML;//responseText;            
    if(xmlDoc != null)
        return xmlDoc.getElementsByTagName("Table");
    else
        return "";
}
//This helper function extracts the pertinent XML from a Web Service at a designated parent node.
//The starting node is comprised of one or more nodes with the same name that serve as the basis of the collection.
//Normally you would call this function within your AJAX callback function, passing in the original http request
function ExtractXmlFromWebService(httpRequest, startNodeName)
{
    var xmlDoc = httpRequest.responseXML;            
   
    if(xmlDoc != null)
      return xmlDoc.getElementsByTagName(startNodeName);
    else
      return "";
}
//Helper function that extracts value for a given XML node. Assumes node is one level deep, e.g. <Name>John Smith</Name>
function ExtractValueFromNode(xmlString, node)
{
  return (xmlString.getElementsByTagName(node)[0].firstChild != null ? xmlString.getElementsByTagName(node)[0].firstChild.nodeValue : "");
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}
// this function gets the cookie, if it exists
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 ToggleRBText(elm, mode, state)
{
    var pr = document.getElementById(elm + 'pr1');
    var pv = document.getElementById(elm + 'preview1');
    if (state == 1)
    {
        switch (mode)
        {
            case 'I':
                $("#" + elm + "pr1").html("How much does this inspire you to DO something about the issue?");
                break;
                
            case 'N':
                $("#" + elm + "pr1").html("How much useful information is there in this for you?");
                break;
            
            case 'Q':
                $("#" + elm + "pr1").html("How much does the presentation (layout, writing) contribute to the overall effect?");
                break;
            
            case 'C':
                $("#" + elm + "pr1").html("How well does this Comment succeed in presenting its main points?");
                break;
            
            case 'R':
                $("#" + elm + "pr1").html("Whether or not you agree, how relevant and valid is this comment?");
                break;
        }  
        $("#" + elm + "preview1").css("height","130px");      
    }
    else
    {
        $("#" + elm + "pr1").html("");
        $("#" + elm + "preview1").css("height","75px");
    }    
}

function ResetJSToRun()
{
    try{document.getElementById('ctl00_hdnJS').value = ''; } catch(err){}
}

function ShowDialog(url, sJSToRun)
{
    ResetJSToRun();
    //alert('url:' + url);
    //alert('sJSToRun:' + sJSToRun);
    //alert('typeof sJSToRun: ' + typeof sJSToRun);
    if (url != "undefined") { document.getElementById('ctl00_hdnUrl').value = url; }
    if (typeof sJSToRun != "undefined")
    {
        document.getElementById('ctl00_hdnJS').value = sJSToRun;
    }
    
    document.getElementById('OverlayDiv').style.display = 'inline';
    document.getElementById('DialogDiv').style.display = 'inline';

    SetWindowPosition()
    
    window.onscroll = SetWindowPosition;
    window.resize = SetWindowPosition;
}

function SetWindowPosition()    
{
    try
    {
        document.getElementById('OverlayDiv').style.width = getSize()[0] + 'px';
        document.getElementById('OverlayDiv').style.height = getSize()[1] + 'px';
        document.getElementById('OverlayDiv').style.left = getScrollXY()[0] + 'px';
        document.getElementById('OverlayDiv').style.top = getScrollXY()[1] + 'px';
    }
    catch(event)
    {
    }
    
    try
    {
        var top 
        top = (getSize()[1]/2) + getScrollXY()[1] - 125
        document.getElementById('DialogDiv').style.top =  top + 'px';

        var left
        left = (getSize()[0]/2) + getScrollXY()[0] - 125
        document.getElementById('DialogDiv').style.left = left + 'px';
    }
    catch(event)
    {
    }
}

function getSize() 
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth, myHeight ];
}

function getScrollXY() 
{
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) 
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } 
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function HideDialog()
{
    document.getElementById('OverlayDiv').style.display = 'none'; 
    document.getElementById('DialogDiv').style.display = 'none';
}
function TempFunction()
{
    document.getElementById('divSignUp').style.display = 'inline'; 
    document.getElementById('divLogin').style.display = 'none'; 
    SetFocusCreateAccount()
}
function ShowSignUpTab()
{
    if(navigator.product == 'Gecko')
    {
        setTimeout("TempFunction();", 1000); 
    }
    else
    {
        TempFunction();
    }
    
}

function ShowSignInTab()
{
    document.getElementById('divLogin').style.display = 'inline'; 
    document.getElementById('divSignUp').style.display = 'none'; 
    try{popupLoginFocus()}catch(err){}
}

function LoginClickSetFocus(elm)
{
    try{document.getElementById(elm).focus()}catch(err){}
}

function checkEmail(elm)
{
    var un = document.getElementById(elm).value;        
    if (un.value != "")
    {
        var reEmail=/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/
        var reHandle=/^[a-zA-Z0-9]+$/
        
        if (un.search(reEmail) == -1 && un.search(reHandle) == -1) 
        {
            alert("Invalid Login format. Please enter a valid Email or a Handle.")
            return false;
        }
    }
    return true;
}

function SetValues()
{
    var s = 'X=' + window.event.clientX +  ' Y=' + window.event.clientY ;
    document.getElementById('divCoord').innerText = s;
}  


function checkS(e){ 
// capture the mouse position 
    var posx = 0; 
    var posy = 0; 
    if (!e) var e = window.event; 
    if (e.pageX || e.pageY) 
    { 
        posx = e.pageX; 
        posy = e.pageY; 
    } 
    else if (e.clientX || e.clientY) 
    { 
        posx = e.clientX; 
        posy = e.clientY; 
    } 
document.getElementById('divCoord').innerHTML = 'Mouse position is: X='+posx+' Y='+posy; 
} 

function setFocusById(id)
{
    try{document.getElementById(id).focus()}catch(err){}
}

function setFocusByElement(elm)
{
    try{elm.focus()}catch(err){}
}

//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm
var dragapproved=false;
var minrestore=0;
var initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all; // note: dot-all is non-standard doc property
var lastClickedWindow;

function iecompattest()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function drag_drop(e)
{
	//alert(mywindow);
	if(ie5&&dragapproved&&event.button==1)
	{
		document.getElementById(lastClickedWindow + "_dwindow").style.left=tempx+event.clientX-offsetx+"px";
		document.getElementById(lastClickedWindow + "_dwindow").style.top=tempy+event.clientY-offsety+"px";
	}
	else if(ns6&&dragapproved)
	{
		document.getElementById(lastClickedWindow + "_dwindow").style.left=tempx+e.clientX-offsetx+"px";
		document.getElementById(lastClickedWindow + "_dwindow").style.top=tempy+e.clientY-offsety+"px";
	}
}

function initializedrag(e, mywindow)
{
    mywindow = mywindow.replace("_dwindow", "");
    //alert('initializedrag-mywindow: ' + mywindow);
	if(browser != "Safari")
	{
		lastClickedWindow = mywindow;
		//alert("lastClickedWindow: " + lastClickedWindow);
		offsetx=ie5? event.clientX : e.clientX;
		offsety=ie5? event.clientY : e.clientY;
		document.getElementById(mywindow + "_content").style.display="none"; //extra
		tempx=parseInt(document.getElementById(mywindow + "_dwindow").style.left);
		tempy=parseInt(document.getElementById(mywindow + "_dwindow").style.top);
		dragapproved=true;
		document.getElementById(mywindow + "_dwindow").onmousemove=drag_drop;
	}
}

function loadwindow(url,width,height,mywindow)
{
    mywindow = mywindow.replace("_dwindow", "");
    //alert('loadwindow-mywindow: ' + mywindow);
	if (!ie5&&!ns6)
		window.open(url,"","width=width,height=height,scrollbars=1");
	else
	{
		document.getElementById(mywindow + "_dwindow").style.display='';
		document.getElementById(mywindow + "_dwindow").style.width=initialwidth=width+"px";
		document.getElementById(mywindow + "_dwindow").style.height=initialheight=height+"px";
		document.getElementById(mywindow + "_dwindow").style.left="30px";
		document.getElementById(mywindow + "_dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px";
		document.getElementById(mywindow + "_cframe").src=url;
	}
}

function loadpopin(width,height,mywindow)
{
try
{
    mywindow = mywindow.replace("_dwindow", "");
    //alert('loadpopin-mywindow: ' + mywindow);
    document.getElementById(mywindow + "_dwindow").style.display='';
    document.getElementById(mywindow + "_dwindow").style.width=initialwidth=width+"px";
    document.getElementById(mywindow + "_dwindow").style.left="30px";
    document.getElementById(mywindow + "_dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px";   
}catch(err){}

}

function closeit(mywindow)
{
    mywindow = mywindow.replace("_dwindow", "");
    //alert('closeit-mywindow: ' + mywindow);
	document.getElementById(mywindow + "_dwindow").style.display="none";
}

function stopdrag(mywindow)
{
    mywindow = mywindow.replace("_dwindow", "");
    //alert('stopdrag-mywindow: ' + mywindow);
	dragapproved=false;
	document.getElementById(mywindow + "_dwindow").onmousemove=null;
	document.getElementById(mywindow + "_content").style.display=""; //extra
}

/* global vars */
var iTotalVisibleRows = 5;
var iMaxRows = 10;

function AddRow()
{		
	iTotalVisibleRows = iTotalVisibleRows + 1;
	ShowRow(iTotalVisibleRows);
	
	if(iTotalVisibleRows == iMaxRows)
		document.getElementById('lnkAddRow').style.visibility = 'hidden';
}
	
function HideRow(iRowNumber)
{
	document.getElementById('BudgetGrid_row' + iRowNumber).style.visibility = 'hidden';
	document.getElementById('BudgetGrid_row' + iRowNumber).style.display = 'none';
}

function ShowRow(iRowNumber)
{
	document.getElementById('BudgetGrid_row' + iRowNumber).style.visibility = 'visible';
	document.getElementById('BudgetGrid_row' + iRowNumber).style.display = '';
}
	
function SaveProfile(ProfileTextControlId, ProfileFrameId)
{
	x = document.getElementById(ProfileFrameId + "_frProfileEditor");
	
	if(x != null)
	{
		try
		{
			document.getElementById(ProfileTextControlId).value = x.contentWindow.GetProfileValue();
			if(document.getElementById(ProfileTextControlId).value.length > 4000)
			{
				txt="Error saving the Profile information.\n\n";
				txt+="Length of the Profile(including the length for the html tags) cannot be greater than 4000 "+ "\n\n";
				alert(txt);
				return false;
			}
		}
		catch(err)
		{
			txt="Error saving the Profile information.\n\n";
			txt+="Error description: " + err.description + "\n\n";
			alert(txt);
			return false;
		}
	}	
	return true;
}

function doLoginRedirect()
{
    if (document.getElementById('ctl00_hdnJS').value == '')
    {    
        if (document.getElementById('ctl00_hdnUrl').value != '' && document.getElementById('ctl00_hdnUrl').value != "undefined")
        {
            window.location.href = document.getElementById('ctl00_hdnUrl').value;
        }
        else
        {
            window.location.reload();
        }
    }
}
function refreshImage(cntrl){try{document.getElementById(cntrl).click();} catch(err){}}
function TB_iframe(caption, url, width, height) {
try {$("#TB_overlay").css({display:"block"});
$("#TB_HideSelect").css({display:"block"});
if (document.getElementById("TB_HideSelect") == null) {$("#TB_overlay").click(TB_remove);		}	
if(caption==null){caption=""};try{ $(window).scroll(TB_position); } catch(err){ } 		
TB_overlaySize();
$("body").append("<div id='TB_load'><img src='"+webserverurl+"images/progressbar.gif' /></div>");TB_load_position();	    	
TB_WIDTH = width;TB_HEIGHT = height;ajaxContentW = TB_WIDTH;ajaxContentH = TB_HEIGHT - 45;
$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div>"+
			    "<iframe frameborder='0' hspace='0' src='"+url+"' id='TB_iframeContent' name='TB_iframeContent' style='width:"+TB_WIDTH+"px;height:"+TB_HEIGHT+"px;' onload='TB_showIframe()'> </iframe>");
$("#TB_closeWindowButton").click(TB_remove);TB_position();$("#TB_load").remove();$("#TB_window").css({display:"block"}); 
try{ $(window).resize(TB_position); } catch(err){}
document.onkeyup = function(e){ 	
if (e == null) { // ie
keycode = event.keyCode;} else { // mozilla
keycode = e.which;}
if(keycode == 27){ // close
TB_remove();}}		    
} catch(e) {}
}


function CheckMaxLength(Object, MaxLen, msg)
{
	if(Object.value.length > MaxLen)
	{     
		if(msg =='Y' && Object.value.length > MaxLen)
		{
			alert('Only ' + MaxLen + ' characters are allowed in this field');
		}
		Object.value = Object.value.substring(0, MaxLen);
	}
}

function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode!=8)
	{ 	//if the key isn't the backspace key (which we should allow)
		if(unicode<48||unicode>57) //if not a number
			return false; //disable key press
	}
}

function ValidateNumber(sInput)
{
	if(sInput == '')
		return true;
	
	var regex=/^\d+$/;

	if(regex.test(sInput))return true;
	else alert('Please enter a numbers only.');
	      	
	return false ;
}



