﻿// JScript File

function rollover(obj, newImage) {
    obj.src = newImage;
  }

function noEnter(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	
	if(keynum == 13)
	{
		doSearch();
		return false;
	}
	else
	{
		return true;
	}
}

function doSearch()
{
	var txtSearch = document.getElementById("txtSearch");

	if(txtSearch.value=="")
		{
		window.alert("Please enter some text first!");
		txtSearch.focus();
		return true;
		}
		
	if(txtSearch.value=="Search using keywords")
		{
		window.alert("Please enter a valid search phrase first!");
		txtSearch.focus();
		return true;
		}

	window.location.href = "/default.aspx?appid=2768&q=" + txtSearch.value;
}

var strSearch = "";

function doFocus()
    {
    var txtSearch = document.getElementById("txtSearch");
    strSearch = txtSearch.value;
    if(strSearch == "Search...")
        {
        txtSearch.value = "";
        }
    }
    
function doBlur()
    {
    var txtSearch = document.getElementById("txtSearch");
    if(txtSearch.value == "")
        txtSearch.value = "Search...";
    }
    
var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos)
    {
    if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2-50:100;}
    else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win=window.open(mypage,myname,settings);
    }          
   
function NewImage(imageurl, w, h)   
    {
    var imageContainer = document.getElementById("imageContainer");
    if(imageContainer == null)
        {
        var imageContainer = document.createElement('div');
        imageContainer.style.position = "absolute";
        imageContainer.id = "imageContainer";
        document.body.appendChild(imageContainer);
        }
    
    imageContainer.innerHTML = "<img alt=\"Click to close!\" onClick=\"CloseImage()\" class=\"ImagePopup\" src=\"" + imageurl + "\"></a>";
    imageContainer.style.display = "block";
    
    //imageContainer.style.top = ((screen.height)?(screen.height-h)/2-150:100) + "px";
    //imageContainer.style.left = ((screen.width)?(screen.width-w)/2:100) + "px";
    
    var myWidth = 0, myHeight = 0;
    var scrOfX = 0, scrOfY = 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;
        }
        
    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;
        }
        
    var xX = ((myHeight -h)/2 + scrOfY);
    var yY = ((myWidth - w)/2 + scrOfX);    
    
    xX = (xX > 150)?(xX-100):xX;
    
    imageContainer.style.top = xX + "px";
    imageContainer.style.left = yY + "px";
    }
    
function CloseImage()
    {
    var imageContainer = document.getElementById("imageContainer");
    imageContainer.style.display = "none";
    }     