var imagesDir = 'http://static.tutorials-expert.com/skins/default/images/';

function topTabHover(num){
	document.getElementById('ttl' + num).style.backgroundPosition = "bottom";
	document.getElementById('ttr' + num).style.backgroundPosition = "bottom";
	document.getElementById('ttb' + num).style.backgroundPosition = "bottom";
}

function topTab(num){
	document.getElementById('ttl' + num).style.backgroundPosition = "top";
	document.getElementById('ttr' + num).style.backgroundPosition = "top";
	document.getElementById('ttb' + num).style.backgroundPosition = "top";
}

function tabHover(num){
	document.getElementById('ht' + num).style.backgroundPosition = "bottom";
}

function tab(num){
	document.getElementById('ht' + num).style.backgroundPosition = "top";
}

function showLogin(){
	usrField = document.getElementById('usrField');
	el = document.getElementById('loginWindow');
	el.style.display = "block";
	usrField.focus();
}

function hideLogin(){
	el = document.getElementById('loginWindow');
	el.style.display = "none";
}

function bookMark(title,url){
    if (window.sidebar){
        window.sidebar.addPanel(title, url,"");
    }else if( window.opera && window.print ){
    alert("Opera users: By Default this link will open in your Sidebar\nrather than the main page!\nTo prevent this please uncheck the box marked\n'Show in Panel' that appears on the Add Bookmark window\n\nSorry about this, but it is currently unavoidable with Opera");
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }else if( document.all ){
    window.external.AddFavorite( url, title);
    }
}

function checkEmail(emailAddr) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr)){
return (true)
}
return (false)
}

function searchOtherField(){
	field = document.getElementById("searchKeywords");
	if(field.value == ""){
		field.value = "Keywords";
	}
}

function checkSearchField(){
	field = document.getElementById("searchKeywords");
	if(field.value == "Keywords"){
		field.value="";
	}
}

function searchForm(oForm){
	field = document.getElementById("searchKeywords");
	if(field.value == "" || field.value == "Keywords"){
		alert("Please Enter Keywords To Search");
		return false;
	}else{
		oForm.submit();
		return true;
	}
}

function checkLoginFields(){
	usrField = document.getElementById('usrField');
	passField = document.getElementById('passField');
	if(usrField.value == null || usrField.value == ''){
		alert("Please Enter A Username");
		usrField.focus();
		return false;
	}else if(passField.value == null || passField.value == ''){
		alert("Please Enter A Password");
		passField.focus();
		return false;
	}else{
		return true;
	}
}

function checkTellFriendsFields(){
	f1 = document.getElementById('myName');
	f2 = document.getElementById('friendEmls');
	if(f1.value == null || f1.value == ''){
		alert("Please Enter Your Name");
		f1.focus();
		return false;
	}else if(f2.value == null || f2.value == ''){
		alert("Please Enter At Least 1 Email");
		f2.focus();
		return false;
	}else{
		return true;
	}
}

function reportBtn(el, myId){
	//reportTutorial function is in ajax.js
	var myRoot = el.parentNode.parentNode;
	var myDiv = document.createElement('div');
	myDiv.className = "reportDiv";
	myDiv.innerHTML = '<div class="reportTransparentLayer" style="margin:auto;margin-top:'+ Math.abs(((myRoot.offsetHeight/2) - (56/2))) + 'px;"><form onsubmit="setVal(this);reportTutorial(this);return false;" method="post"><input type="radio" name="report" value="broken" />Broken&nbsp;&nbsp;<input type="radio" name="report" value="abusive" />Abusive&nbsp;&nbsp;<input type="radio" name="report" value="wrong placement" />Wrong Placement<br/><center><input type="hidden" name="tutId" value="' + myId + '" /><input type="hidden" name="reportVal" value="" /><input type="button" value="Cancel" onclick="hideReport(this);" /> <input type="submit" value="Report" /></center></form></div>';
	myDiv.style.height = myRoot.offsetHeight + "px";
	myDiv.style.width = myRoot.offsetWidth + "px";
	myDiv.style.marginTop = "-" + myRoot.offsetHeight + "px";
	myRoot.appendChild(myDiv);
}

function setVal(oForm){
	var inpArr = new Array();
	var selVal;
	inpArr = oForm.getElementsByTagName('input');
	for(var i = 0; i < 3; i++){
		if(inpArr[i].checked == true){selVal = inpArr[i].value;}
	}
	inpArr[4].value = selVal;
}

function hideReport(el){
	var myRoot = el.parentNode.parentNode.parentNode.parentNode.parentNode;
	myRoot.removeChild(myRoot.childNodes[myRoot.childNodes.length-1]);
}

function depressBtn(ele, algn){
	if(algn == 'right'){
		ele.style.marginRight = '0px';
		ele.style.marginBottom = '0px';
	}else{
		ele.style.paddingLeft = '0px';
		ele.style.paddingTop = '0px';	
	}
}

function undepressBtn(ele, algn){
	if(algn == 'right'){
		ele.style.marginRight = '1px';
		ele.style.marginBottom = '1px';
	}else{
		ele.style.paddingLeft = '1px';
		ele.style.paddingTop = '1px';	
	}
}

function installSearchEngine() {
	if(window.external && ("AddSearchProvider" in window.external)){
		// Firefox 2 and IE 7, OpenSearch
		window.external.AddSearchProvider("http://www.tutorials-expert.com/plugins/search-plugin.xml");
	}else{
		// No search engine support (IE 6, Opera, etc).
		alert("No search engine support");
	}
}
