//preload theimages
image_object = new Image()

img_url = new Array()
img_url[0] = "images/tab_orange.gif"
img_url[1] = "images/tab_blue.gif"
img_url[2] = "images/tab_green.gif"
img_url[3] = "images/tab_red.gif"
img_url[4] = "images/tab_purple.gif"
img_url[5] = "images/tab_yellow.gif"
img_url[6] = "images/redconb.gif"
img_url[7] = "images/orangeconb.gif"
img_url[8] = "images/blueconb.gif"
img_url[9] = "images/greenconb.gif"
img_url[10] = "images/redconb.gif"
img_url[11] = "images/pinkconb.gif"
img_url[12] = "images/purpleconb.gif"
img_url[13] = "images/lightgreenconb.gif"
img_url[14] = "images/lightblueconb.gif"
img_url[15] = "images/redcont.gif"
img_url[16] = "images/orangecont.gif"
img_url[17] = "images/bluecont.gif"
img_url[18] = "images/greencont.gif"
img_url[19] = "images/redcont.gif"
img_url[20] = "images/pinkcont.gif"
img_url[21] = "images/purplecont.gif"
img_url[22] = "images/lightgreencont.gif"
img_url[23] = "images/lightbluecont.gif"
img_url[24] = "images/mainconb.gif"
img_url[25] = "images/maincont.gif"
img_url[26] = "images/reviewcon.gif"
img_url[27] = "images/tab_open_orange.gif"
img_url[28] = "images/tab_open_blue.gif"
img_url[29] = "images/tab_open_green.gif"
img_url[30] = "images/tab_open_red.gif"
img_url[31] = "images/tab_open_purple.gif"
img_url[32] = "images/tab_open_yellow.gif"
img_url[33] = "images/maincont_blue.gif"
img_url[34] = "images/mainconb_blue.gif"
img_url[35] = "images/close.gif"
img_url[36] = "images/close_hover.gif"
img_url[37] = "images/email.gif"
img_url[38] = "images/newscont.gif"
img_url[39] = "images/newsconb.gif"
img_url[40] = "images/single_title_top.gif"
img_url[41] = "images/half_star.gif"
img_url[42] = "images/half_star_blue.gif"
img_url[43] = "images/star_blue.gif"

for(x=0;x<img_url.length;x++) {
	image_object.src = img_url[x]
}



function init() {
	//this is supposed to be an all browser onmouseleave function. Can't get it to work though
	//var theElement = document.getElementById('review_content')
	//addEvent(theElement, 'mouseleave', leave, false)

}

function hideElement(elem) {
	elem.style.display='none'
}

function addEvent(a, b, c, d) {
alert("addEvent")
}

function showlinks(getlinks, gettab, getcolour) {
	//hide the other link divs
	document.getElementById('links1').style.visibility = 'hidden'
	document.getElementById('links2').style.visibility = 'hidden'
	document.getElementById('links3').style.visibility = 'hidden'
	document.getElementById('links4').style.visibility = 'hidden'
	document.getElementById('links5').style.visibility = 'hidden'
	
	//show the right link div
	document.getElementById(getlinks).style.visibility = 'visible';
	
	//change the background image
	
	document.getElementById('tab1').style.backgroundImage = 'url(images/tab_orange.gif)'
	document.getElementById('tab2').style.backgroundImage = 'url(images/tab_blue.gif)'
	document.getElementById('tab3').style.backgroundImage = 'url(images/tab_green.gif)'
	document.getElementById('tab4').style.backgroundImage = 'url(images/tab_red.gif)'
	document.getElementById('tab5').style.backgroundImage = 'url(images/tab_purple.gif)'

	tabstring = "url(images/tab_open_" + getcolour + ".gif)"
	document.getElementById(gettab).style.backgroundImage = tabstring	
	
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function stateChanged(getreview) 
{ 
	if (xmlHttp.readyState==4)
	{ 
		reviewid = "review_content_" + getreview
		document.getElementById(reviewid).innerHTML=xmlHttp.responseText;
		document.getElementById(reviewid).style.visibility = "visible";
	}
}


function showReview(getreview, obj)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="reviewwindow.asp";
url=url+"?getreview="+getreview;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function()				//stateChanged(getreview);
{
      if(xmlHttp.readyState==4)
        {
        reviewid = "review_content" //+ getreview
        strReview = xmlHttp.responseText
        strReview.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
		document.getElementById("review_content_middle").innerHTML=strReview;
		//need to position review_content box based on position of the cursor
		

		//get left and top value	
		p = getPos(obj)
		gety = p.y + "px"
		getx = p.x + "px"
		document.getElementById(reviewid).style.top = gety;
		document.getElementById(reviewid).style.left = '120px'; //getx;
		if(navigator.userAgent.indexOf("Firefox")!=-1){
			gety = p.y + 50 + "px"
			document.getElementById(reviewid).style.top = p.y + 20
			document.getElementById(reviewid).style.left ="232px"
        }
		//document.getElementById(reviewid).style.visibility = "visible";
		document.getElementById(reviewid).style.display = "block";
		document.getElementById(reviewid).style.zIndex = "99";


        }

}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function getPos(obj) {
var pos = {x: obj.offsetLeft||0, y: obj.offsetTop||0};
while(obj = obj.offsetParent) {
pos.x += obj.offsetLeft||0;
pos.y += obj.offsetTop||0;
}
return pos;
}

function addEvent(_elem, _evtName, _fn, _useCapture)
{
alert("addEvent start")
   if (typeof _elem.addEventListener != 'undefined')
   {
      if (_evtName === 'mouseenter')
         { _elem.addEventListener('mouseover', mouseEnter(_fn), _useCapture); }
      else if (_evtName === 'mouseleave')
         { _elem.addEventListener('mouseout', mouseEnter(_fn), _useCapture); }
      else
         { _elem.addEventListener(_evtName, _fn, _useCapture); }
   }
   else if (typeof _elem.attachEvent != 'undefined')
   {
      _elem.attachEvent('on' + _evtName, _fn); //changed f to _fn
   }
   else
   {
      _elem['on' + _evtName] = _fn;  //changed f to _fn
   }
 alert("addEvent end")
}

function mouseEnter(_fn)
{
   return function(_evt)
   {
      var relTarget = _evt.relatedTarget;    
      if (this === relTarget || isAChildOf(this, relTarget))
         { return; }

      _pFn.call(this, _evt);      
   }
};

function isAChildOf(_parent, _child)
{
   if (_parent === _child) { return false; }
      while (_child && _child !== _parent)
   { _child = _child.parentNode; }

   return _child === parent;
}


function checksearchform() {
    if (document.searchform.searchstring.value.length == 0) {
    	return false
    }
    else {
    	return true
    }
}

function validate() {

  if (document.forms.form1.name.value=="") {
    alert("Name field not completed")
    document.forms.form1.name.focus()
    return false
  }
  
  if (document.forms.form1.theiremail.value=="") {
    alert("Email field not completed")
    document.forms.form1.theiremail.focus()
    return false
  }
  
  if (document.forms.form1.sitename.value=="") {
    alert("Site Name field not completed")
    document.forms.form1.sitename.focus()
    return false
  }
  if (document.forms.form1.siteurl.value=="") { 
    alert("URL field not completed")
    document.forms.form1.siteurl.focus()
    return false
  }
  if (document.forms.form1.description.value=="") {
    alert("Description field not completed")
    document.forms.form1.description.focus()
    return false
  }
  if (document.forms.form1.reciplink.value=="") {
    alert("Reciprocal Link field not completed")
    document.forms.form1.reciplink.focus()
    return false
  }

}

var testresults
function checkemail(){
var str=document.newsletterform.getemail.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}



/*Example message arrays for the two demo scrollers*/

var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'

var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.news.com">News.com: Technology and business reports</a>'
pausecontent2[1]='<a href="http://www.cnn.com">CNN: Headline and breaking news 24/7</a>'
pausecontent2[2]='<a href="http://news.bbc.co.uk">BBC News: UK and international news</a>'



/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

