/*

www.owensoft.net 
the scripts used my website are compiled from different sources.  some scripts are customised, so it is best to get the original from the linked location

*/



var d = document;

/*

adapted from http://www.donotremove.co.uk/ which took it from somewhere else which I can't remember

*/
function externalLinks() { 
	if (!d.getElementsByTagName) return; 
	var anchors = d.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	} 
} 

//window.onload = externalLinks;

/*

adapted from http://www.donotremove.co.uk/ and zebra tables

*/
function zebrastuff() { 
	if (!d.getElementsByTagName) return; 
	var stuff = d.getElementsByTagName("div"); 
    var even = false;
	
	for (var i=0; i<stuff.length; i++) { 
		var item = stuff[i]; 
		
		if( even & (hasClass(item) == 'sec') ) hasClass(item, 'sec2' );
		//if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 

		even = !even;
	} 
} 

//window.onload = zebrastuff;

  function hasClass(obj, newval) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
		 if(newval != undefined ) { obj.getAttributeNode("class").value = newval; }
     }
     return result;
  }   
/*

adapted from	

*/

function sh(id1) {
	  if (id1 != '') expMenu(id1);
	}
function sh2(id1,id2) {
	  if (id1 != '') expMenu(id1);
	  if (id2 != '') expMenu(id2);
	}
	
function expMenu(id) {
	  var itm = null;
	  if (d.getElementById) {
		itm = d.getElementById(id);
	  } else if (d.all){
		itm = d.all[id];
	  } else if (d.layers){
		itm = d.layers[id];
	  }
	
	  if (!itm) {
	   return false;
	  }	  else if (itm.style) {
		if (itm.style.display == "none") { itm.style.display = ""; }
		else { itm.style.display = "none"; }
	  } else { itm.visibility = "show"; }
	  	   return true;
}


	
function insertAtCursor(myField, myValue) {
	if (document.selection) { // IE
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	} else if (myField.selectionStart || myField.selectionStart == 0) {//MOZILLA/NETSCAPE support
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
	return false;
}


function xmlhttpPost(strURL, querystring, dn, smart) {
    var xmlHttpReq = false;
    var self = this;
	this.dnn=dn;
	if(smart==undefined) smart=true;

	if( smart & document.getElementById(dn).innerHTML != '' & dn!='sidebar') {

		if(navigator.vendor=='Netscape') {
			document.getElementById(dn).innerHTML=""; 
		} else {
			$("#"+dn).hide("slow", function () { //jquery mod 11/3/2007 9:50 AM
				document.getElementById(dn).innerHTML=""; //old
		    }  );  //jquery mod 11/3/2007 9:50 AM
		}

		return false;
	}

    document.getElementById(dn).innerHTML = "<center><img src='/v4/image/loading.gif' /></center>"; //""; //old

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, self.dnn);
        }
    }
    self.xmlHttpReq.send(querystring);
}

function updatepage(str, dn){

	if(navigator.vendor=='Netscape') {
			document.getElementById(dn).innerHTML = str;
	} else {
			$("#"+dn).hide();  //jquery mod 11/3/2007 9:50 AM
			document.getElementById(dn).innerHTML = str;
			$("#"+dn).show("slow");  //jquery mod 11/3/2007 9:50 AM
	}

}

function replybutton(type, record, num, author) {
	document.write(', <a href="#" class=rlink onclick="return doreply(\''+type+'\', \''+record+'\', '+num+', \''+author+'\');">reply</a>');
	document.write('<div id="comr'+num+'"></div>');
}

function combutton(type, record, num, author, caption) {
	document.write('<a href="#" class=clink onclick="return doreply(\''+type+'\', \''+record+'\', '+num+', \''+author+'\');">'+caption+'</a>');
	document.write('<div id="comr'+num+'"></div>');
}

function quickcom(num, author, verb_comment) {
	document.write(' or <strong><a href="#" onclick="return doquicky('+num+', \''+author+'\');">'+verb_comment+'</a></strong>');
	document.write('<div id="qc'+num+'"></div>');
}

function comoptbutton(num, author) {
	document.write('<a href="#" class=clink onclick="return docomopt(\''+num+'\', \''+author+'\');">attach a picture, and other options</a>');
	document.write('<div id="'+num+'"></div>');
}

function smileybutton(num) {
	document.write('<a href="#" onclick="dosm('+num+');return false;" title="Show Smilies"><img src="/v4/wikipedia_smilies/19px-SConfident.gif" border=0></a>');
	document.write('<div id="sm'+num+'"></div>');
}

function doreply(type, record, num, author){
	urlp="/v4/ajax.php";
	q="wtd=commentreply&type="+type+"&record=" + record +"&parent=" + num +"&author="+author;
	xmlhttpPost(urlp, q, 'comr'+num);
	return false;
}

function doquicky(num, author){
	urlp="/v4/ajax.php";
	q="wtd=commentquicky&type=item&record=" + num +"&author="+author;
	xmlhttpPost(urlp, q, 'qc'+num);
	return false;
}


function doquicky2(form, num){
	urlp="/v4/ajax.php";
	q="wtd=new_comment&type=item&record=" + num +"" + getFormStr(form);
	xmlhttpPost(urlp, q, 'qc'+num, false);
	return false;
}

function doquicky_reply(form, type, record, num){
	urlp="/v4/ajax.php";
	q="wtd=new_comment&type="+type+"&record="+record+"" + getFormStr(form);
	xmlhttpPost(urlp, q, 'comr'+num, false);
	return false;
}

function docomopt(num, author){
	urlp="/v4/ajax.php";
	q="wtd=commentoptions&id=" + num +"&author="+author;
	xmlhttpPost(urlp, q, num);
	return false;
}

function dosm(num){
	urlp="/v4/ajax.php";
	q="wtd=smilie&id=" + num;
	xmlhttpPost(urlp, q, 'sm'+num);
	return false;
}

function sidebar(num){
	urlp="/v4/ajax.php";
	q="wtd=sidebar&menu=" + num;
	xmlhttpPost(urlp, q, 'sidebar');
	return false;
}

function forum(num){
	urlp="/v4/ajax.php";
	q="wtd=forum&item=" + num;
	xmlhttpPost(urlp, q, 'forum' + num);
	return false;
}