function selectIt(id) 
{
	if (document.getElementById(id).style.display =='block')
     {
          document.getElementById(id).style.display = 'none';
     } else 
     {
          document.getElementById(id).style.display = 'block';
     }
}

// Function retrieved from: http://cass-hacks.com/articles/code/js_url_encode_decode/  
function URLEncode (clearString) {  
  var output = '';  
  var x = 0;  
  clearString = clearString.toString();  
  var regex = /(^[a-zA-Z0-9_.]*)/;  
  while (x < clearString.length) {  
    var match = regex.exec(clearString.substr(x));  
    if (match != null && match.length > 1 && match[1] != '') {  
        output += match[1];
        x += match[1].length;  
  }
    else {  
      if (clearString[x] == ' ')
          output += '+'; 
      else {  
        var charCode = clearString.charCodeAt(x);  
        var hexVal = charCode.toString(16);  
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();  
      }  
      x++;  
    }  
  }  
  return output;  
}  
// Retrieved from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html  
function SubmitOnEnter(myfield, e)  
{   
    var keycode;  
    if (window.event)  
        keycode = window.event.keyCode;  
    else if (e)  
        keycode = e.which;  
    else
        return true;

    if (keycode == 13 && myfield.value != "")
    {
	if (myfield.id == "q")
	  SearchSite();  
	else
	  SearchSite1();

        return false;  
    }
    else if (keycode == 13 && myfield.value == "")
    {
        return false;  
    }
     else
        return true;
}

//Left Trim
function ltrim(s) {
    return s.replace(/^\s*/, "");
}

function SearchSite(value) {

    var searchBox = ltrim(document.getElementById("q").value)

    if (searchBox != "") {
        document.location.href='http://dotnetslackers.com/info/SearchResult.aspx?cx=018002390954475216601%3Aly0yy-8egb8&cof=FORID%3A10&ie=UTF-8&q=' + URLEncode(document.getElementById('q').value) + '&sa=Search';
        return true;
    }
    else
        document.getElementById("q").focus();
    return false;
}

function SearchSite1(value) {

    var searchBox = ltrim(document.getElementById("q1").value)

    if (searchBox != "") {
        document.location.href='http://dotnetslackers.com/info/SearchResult.aspx?cx=018002390954475216601%3Aly0yy-8egb8&cof=FORID%3A10&ie=UTF-8&q=' + URLEncode(document.getElementById('q1').value) + '&sa=Search';
        return true;
    }
    else
        document.getElementById("q1").focus();
    return false;
}

function SetDisplayScreen()
{
	// get the reference to the element you want to position
   	var d = document.getElementById('divPleaseWait');

	// get screen width and height
   	var s_width = screen.width;
   	var s_height = screen.height;

	// get scroll positions for x and y
   	var scrollX, scrollY;

	if (document.all)
     	{
        	if (!document.documentElement.scrollLeft)
           		scrollX = document.body.scrollLeft;
        	else
           		scrollX = document.documentElement.scrollLeft;

		if (!document.documentElement.scrollTop)
           		scrollY = document.body.scrollTop;
        	else
           		scrollY = document.documentElement.scrollTop;
     	}
     	else
     	{
        	scrollX = window.pageXOffset;
        	scrollY = window.pageYOffset;
     	}

	// set top and left for the element
	// forumla = current scroll + (half of the screen width/height) - half of the elements (width/height)
	d.style.top = scrollY + (s_height / 2) - 50 + "px";
	d.style.left = scrollX + (s_width / 2) - 50 + "px";
}

function ShowTags(id) 
{
	
	if (id == "ListView")
	{
		document.getElementById('ListView').style.display = 'block';
		document.getElementById('CloudView').style.display = 'none';
	}
	if (id == "CloudView")
	{
		document.getElementById('ListView').style.display = 'none';
		document.getElementById('CloudView').style.display = 'block';
	}
}

function ShowTagList(id) 
{
	var d = document.getElementById('CommonTagInfoBox')
	if (d.style.display == 'block')
	{
		d.style.display = 'none';
	}
	else
	{
		d.style.display = 'block';
	}
}
function ValidateInput(sender)
{
  if (sender.value.indexOf("<") != -1) sender.value=sender.value.substring(0,sender.value.indexOf("<"));
}