// place Functions here 

if (navigator.userAgent.indexOf('MSIE')==-1){
	var bIsIE = 0;
} else {
  var bIsIE = 1;
}	 
//--------------------------------------------------------------
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
//--------------------------------------------------------------
function IE7Add2SP(strAddURI) {

try{ window.external.AddSearchProvider(strAddURI); }
catch(eX){ 		if (70 == (eX.number & 0xFFFF)){
    alert("Click OK and then use the mouse\n or the Enter key to click the install button."); 
  } else {
    alert("Unable to add search provider. This feature requires MS Internet Explorer 7.   [" + (eX.number & 0xFFFF) + "]");
  }
}
return false;				       

}

//--------------------------------------------------------------
function ShowID(sObjID) {
   if (document.getElementById(sObjID)) {
    obj = document.getElementById(sObjID);
		obj.style.display="block";
		}
}		

function HideID(sObjID) {
    if (document.getElementById(sObjID)) {
      obj = document.getElementById(sObjID);
	  	obj.style.display="none";
		}
}		

function loader() {
  HideID("about");
  HideID("widgets");
  HideID("banners");	
}


function show(subpage) {
  if (document.getElementById(subpage)) {
    obj = document.getElementById(subpage);
  	obj.style.top = "30";
		changeOpac(0,subpage);
    obj.style.display="block";
  	HideID("sitefooter");
		opacity(subpage,0,100,500);		
	}
}
function closesub(subpage) {
  HideID(subpage);
  ShowID("sitefooter");
}


function installSearchEngine() {
try{ window.external.AddSearchProvider("http://www.sqlhunt.com/plugins/sqlhuntopensearch.xml"); }
catch(eX){ 		if (70 == (eX.number & 0xFFFF)){
    alert("Click OK and then use the mouse\n or the Enter key to click the install button."); 
  } else {
			 try{ window.sidebar.addSearchEngine("http://www.sqlhunt.com/plugins/sqlhuntsearchplugin.src","http://www.sqlhunt.com/plugins/sqlhuntico.gif","Search Plugin", "");}
			 catch(eZ){ 		if (70 == (eZ.number & 0xFFFF)){
			} else {
			     alert("Unable to add search provider.  Error Code [" + (eZ.number & 0xFFFF) + "]");				
			} //End if 
	 	} //End Catch
  }//End If		 
}//End Catch
return false;

}

/*function installSearchEngine() {
 if (window.external && ('AddSearchProvider' in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider('http://www.sqlhunt.com/plugins/sqlhuntopensearch.xml');
 } else if (window.sidebar && ('addSearchEngine' in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine('http://www.sqlhunt.com/plugins/sqlhuntsearchplugin.src',
                                  'http://www.sqlhunt.com/plugins/sqlhuntico.gif',
                                  'Search Plugin', '');
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("No search engine support");
 }
}
*/
function copyclipbandhl(d)
{
//var doc = eval("document.contentform."+d);
var doc = eval(d);
cp = doc.createTextRange();
doc.focus();
doc.select();
cp.execCommand("Copy");
}


//now create the event handler function to process the event
function alertkey(e) {
  if( !e ) {
    //if the browser did not pass the event information to the
    //function, we will have to obtain it from the event register
    if( window.event ) {
      //Internet Explorer
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
      return;
    }
  }
  if( typeof( e.keyCode ) == 'number'  ) {
    //DOM
    e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    //NS 4 compatible
    e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    //also NS 6+, Mozilla 0.9+
    e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
 // window.alert('The key pressed has keycode ' + e +
 //   ' and is key ' + String.fromCharCode( e ) );
   if (e==27) {
// ------------- Escape pressed
          if (document.getElementById("about")) {
            if (document.getElementById("about").style.display=="block") {
              closesub("about");
            }
          }
          if (document.getElementById("widgets")) {
            if (document.getElementById("widgets").style.display=="block") {
              closesub("widgets");
            }
          }
          if (document.getElementById("banners")) {
            if (document.getElementById("banners").style.display=="block") {
              closesub("banners");
            }
          }
// ----------- End of Escape pressed		   
   }
 
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

