//

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

//	changes the visible status of an element
function hideMe(element) {
	document.getElementById(element).style.visibility="hidden";
}

// Functions for mouseover effects

function v_rollOn(element) {  
	document.getElementById(element).style.visibility="visible";
}

function v_rollOff(element) {
	document.getElementById(element).style.visibility="hidden";
}

// image swap 
function swapImage(name,image) {
//	alert("being asked to swap " + image + " into " + name);
    if (document.images)
    document.images[name].src = image;
}

function stripChar(element,remove) {
  var num = element.length;
  for(var i = 1; i<num; ++i){
  element = element.replace(remove, "");   
 }
 return element;
}

//	Validate callme form
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

function checkLength(checkStr,length,strText,verbose) {
	if(checkStr.length<length) {
		if(verbose) {
			alert("Please enter a valid " + strText);
		}
		return false;
	}
	else {
		return true;
	}
}
function checkTel(checkStr,verbose) {
	var rgxp=/[^0-9]/g;
	result =  rgxp.test(checkStr);
	if (result) {
		if(verbose) {
		alert("Phone number not numeric " + checkStr + "\n");
		}
	return false;
	} else {
		return true;
	}
}

function checkCallme(thisform) {
	blnError = false;
	strAlert = "To receive a callback you need to enter the following:\n";
		//title
		if(thisform.name.value == 'Your Name' || !checkLength(thisform.name.value,1,false)) {
			strAlert+=" - Your name\n";
			blnError=true;
		}

		//telephone
	phone = stripChar(thisform.phone.value,' ');
	phone = stripChar(phone,'-');
//	alert("Phone num is now " + phone);
	if(!checkLength(phone,11,false) || !checkTel(phone,false)) {
		strAlert+=" - Valid Telephone/Mobile No\n";
		blnError=true;
	}
/*	if(!checkTel(phone,true)) {
		strAlert+=" - Numeric Telephone/Mobile No\n";
		blnError=true;
	}
*/
	if(blnError) {
		alert(strAlert);
		return false;
	}
	else {
		return true;
	}
}


// other functions
function mailStr() {
  var contact = "info";
  var email = "info";
  var eHost = "hartwrightcommercials.co.uk";
  return(contact + "&#064;" + eHost);
}

//	Change the CSS class of an item
function classChange(styleChange,item) {
	item.className = styleChange;
}

//	Change the CSS class of an item given its ID
function classChangeID(styleChange,item) {
	var itm = document.getElementById(item);
	itm.className = styleChange;
}

//  clears a text field in a form if the value is == orig 
function doClear(inputname, orig) {
  if (inputname.value == orig) {
  inputname.value = ""
  }
}
//	toggles collapsible sections (e.g. accessories)
function toggleCS(sDivId, tDivId) {
	var oDiv = document.getElementById(sDivId);
	var tDiv = document.getElementById(tDivId);
	oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";
	tDiv.innerHTML = (tDiv.innerHTML == 'More&gt;&gt;') ? "&lt;&lt;Less" : "More&gt;&gt;";
}

function loadPopunder(){
win2=window.open('index.php',"home","width=1024,height=580,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0")
win2.blur()
window.focus()
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * enables highlight and marking of rows in data tables
 *
 */
function PMA_markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}
window.onload=PMA_markRowsInit;
