function addClass(element, value) {
    if (element !== null)
    {
	    if (!element.className) {
		    element.className = value;
	    } else {
		    var newClassName = element.className;
		    newClassName += " ";
		    newClassName += value;
		    element.className = newClassName;
	    }
    }
}
/*
function autoIframe(frameId) {
	try {
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
	} catch(err) {
		window.status = err.message;
	}
}
*/

function newfoldername() {
	if(document.forms['saveall'].folder_id.options[document.forms['saveall'].folder_id.selectedIndex].value == '[NEW]') {
		document.getElementById('new_folder_div').style.visibility = 'visible';
	} else {
		document.getElementById('new_folder_div').style.visibility = 'hidden';
	};
}


function autoIframe(iframeID) {
	if(self==parent) return false; /* Checks that page is in iframe. */
	else if(document.getElementById&&document.all) /* Sniffs for IE5+.*/

	var FramePageHeight = framePage.scrollHeight + 10; 

	parent.document.getElementById(iframeID).style.height=FramePageHeight;

} 

function closeBrWindow() { 
	top.close();
}

function changeCase(frmObj) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			} else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
         		}
      		}
   		}
	}
	frmObj.value = tmpStr;
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type == "password") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

function popUp(url){
	PopUpWin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=750,height=505');
}

function popUpSize(url, width, height){
	PopUpWin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+width+',height='+height);
}

//window.POPURL = "http://www.nichebot.com/";
var POPURL = "http://www.nichebot.com/";
function closePopUp () {
  if (window.opener && window.opener.location) {
    window.opener.location.href = POPURL;
    window.close();
  } else {
    newWin = window.open('', 'NewWin', 'width=100%,height=100%');
    newWin.location = POPURL;
  }
}

function go() { 
	x=document.theform.NICHEBOT.value;
    if (x.length<1){alert('Please enter your Wordtracker Affiliate ID.'); return 0;}
    javastr="http://www.nichebot.com/?i="+x+"\n";
    document.theform.thelink1.value=javastr;
}

function winPrint(){
	if (window.print) {
	  window.print();
	} else {
	  alert("Your Web Browser DOES NOT support this print method. Please close this window and select File > Print from your Web Browser Menu.");
	}
}

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}


var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;

document.onmousemove = getMouseXY; // update(event) implied on NS, update(null) implied on IE

function getMouseXY(e){ // works on IE6,FF,Moz,Opera7
	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

	if (e) {
	    if (e.pageX || e.pageY) { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			mousex = e.pageX;
			mousey = e.pageY;
			algor = '[e.pageX]';
			if (e.clientX || e.clientY) algor += ' [e.clientX] '
	    } else if (e.clientX || e.clientY) { // works on IE6,FF,Moz,Opera7
			mousex = e.clientX + document.body.scrollLeft;
			mousey = e.clientY + document.body.scrollTop;
			algor = '[e.clientX]';
			if (e.pageX || e.pageY) algor += ' [e.pageX] '
		}
	}
}


function showquickgrab() {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('quickgrab').style.visibility = 'visible';
		document.getElementById('quickgrab').style.top = mousey + 'px';
		document.getElementById('quickgrab').style.left = mousex + 'px';
	} else {
		if (document.layers) { // Netscape 4
			document.quickgrab.visibility = 'visible';
			document.quickgrab.top = mousey;
			document.quickgrab.left = mousex;
		} else { // IE 4
			document.all.quickgrab.style.visibility = 'visible';
			document.all.quickgrab.style.top = mousey;
			document.all.quickgrab.style.left = mousex;
		}
	}
	document.quickform.quicktextarea.focus();
	document.quickform.quicktextarea.select();
} 

function showquickgrab2() {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('quickgrab').style.visibility = 'visible';
		document.getElementById('quickgrab').style.top = (mousey + 20) + 'px';
		document.getElementById('quickgrab').style.left = (mousex - 200) + 'px';
	} else {
		if (document.layers) { // Netscape 4
			document.quickgrab.visibility = 'visible';
			document.quickgrab.top = mousey;
			document.quickgrab.left = mousex;
		} else { // IE 4
			document.all.quickgrab.style.visibility = 'visible';
			document.all.quickgrab.style.top = mousey;
			document.all.quickgrab.style.left = mousex;
		}
	}
	document.quickform.quicktextarea.focus();
	document.quickform.quicktextarea.select();
} 

function showquickgrabbyname(divname, showall) {
	var mx = mousex;
	var my = mousey;
		
	if (showall == true)
	{
		mx = 18;
		my = 390;
	}
	else
	{
		mx = mousex - 420;
		my = mousey - 170;
	}
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divname).style.display = 'block';
		document.getElementById(divname).style.top = my + 'px';
		document.getElementById(divname).style.left = mx + 'px';
	} else {
		if (document.layers) { // Netscape 4
			document.quickgrab.display = 'block';
			document.quickgrab.top = my;
			document.quickgrab.left = mx;
		} else { // IE 4
			document.all.quickgrab.style.display = 'block';
			document.all.quickgrab.style.top = my;
			document.all.quickgrab.style.left = mx;
		}
	}
	document.quickform.quicktextarea.focus();
	document.quickform.quicktextarea.select();
} 


function hidequickgrab() {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('quickgrab').style.visibility = 'hidden';
	} else {
		if (document.layers) { // Netscape 4
			document.quickgrab.visibility = 'hidden';
		} else { // IE 4
			document.all.quickgrab.style.visibility = 'hidden';
		}
	}
} 

function showhide(div_name) {
	if(document.getElementById(div_name).style.visibility == 'hidden') {
		document.getElementById(div_name).style.visibility = 'visible';
		document.getElementById(div_name).style.overflow = 'visible';
		document.getElementById(div_name).style.height = 'auto';
	} else {
		document.getElementById(div_name).style.visibility = 'hidden';
		document.getElementById(div_name).style.overflow = 'hidden';
		document.getElementById(div_name).style.height = '1px';
	};
}

function show_div(div_name) {
	document.getElementById(div_name).style.visibility = 'visible';
	document.getElementById(div_name).style.overflow = 'visible';
	document.getElementById(div_name).style.height = 'auto';
}
function hide_div(div_name) {
	document.getElementById(div_name).style.visibility = 'hidden';
	document.getElementById(div_name).style.overflow = 'hidden';
	document.getElementById(div_name).style.height = '1px';
}
function show_div_outside(div_name) {
	parent.document.getElementById(div_name).style.visibility = 'visible';
	parent.document.getElementById(div_name).style.overflow = 'visible';
	parent.document.getElementById(div_name).style.height = 'auto';
}
function hide_div_outside(div_name) {
	parent.document.getElementById(div_name).style.visibility = 'hidden';
	parent.document.getElementById(div_name).style.overflow = 'hidden';
	parent.document.getElementById(div_name).style.height = '1px';
}

function checkAll() {
	count = document.saveall.elements.length;
    for (i=0; i < count; i++) 
    {
    if(document.saveall.elements[i].name.indexOf('savealldata') > -1 ) {
        if(document.saveall.elements[i].checked == 1) {
            document.saveall.elements[i].checked = 0; 
        } else {
            document.saveall.elements[i].checked = 1;}
        }
    };
}

function checkAllByName(searchstring) {
	count = document.form.elements.length;
    for (i=0; i < count; i++) 
    {
    if(document.form.elements[i].name.indexOf(searchstring) > -1 ) {
        if(document.form.elements[i].checked == 1) {
            document.form.elements[i].checked = 0; 
        } else {
            document.form.elements[i].checked = 1;}
        }
    };
}

function changeAllByName(searchstring, checked) {
	count = document.form.elements.length;
    for (i=0; i < count; i++) 
    {
    if(document.form.elements[i].name.indexOf(searchstring) > -1 ) {
		document.form.elements[i].checked = checked; 
    };
    };
}

function Question(msg, url) {
  if (confirm(msg)) {
    document.location = url
  } else {
    return;
  }
}

function newwindow(text) {
  window.open('newwindow.php?text='+text,"","width=400,height=338,");
}

function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}

function unSelectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = false;
		}
	}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

//  check for valid numeric strings	
function isNumeric(strString) {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (ii = 0; ii < strString.length && blnResult == true; ii++) {
      strChar = strString.charAt(ii);
      if (strValidChars.indexOf(strChar) == -1) {
         blnResult = false;
      }
   }
   return blnResult;
}


function getAllChecked(searchstring) {
	count = document.form.elements.length;
	var res = '';
    for (i=0; i < count; i++) {
    	if(document.form.elements[i].name.indexOf(searchstring) > -1 ) {
	        if(document.form.elements[i].checked == 1) {
    			res = res + document.form.elements[i].name + ",";
    		};
    	};
	}
	return res;
}

//Keyword Research Wizard Switcher
function tool(q1, q2) {
	tl = '' + q1 + q2;
	switch(tl) {
		case 'a1': window.location = '/x/wt/'; break;
		case 'a2': window.location = '/x/gcq/'; break;
		case 'b1': window.location = '/x/wt/'; break;
		case 'b2': window.location = '/x/lsi/'; break;
		case 'c1': window.location = '/x/wt-premium/'; break;
		case 'c2': window.location = '/x/gc/'; break;
		case 'd1': window.location = '/x/wt/'; break;
		case 'd2': window.location = '/x/gcq/'; break;
		case 'g1': window.location = '/x/wt-premium/'; break;
		case 'g2': window.location = '/x/gc/'; break;
		case 'k1': window.location = '/x/wt/'; break;
		case 'k2': window.location = '/x/gcq/'; break;
		case 'l1': window.location = '/x/live/'; break;
		case 'l2': window.location = '/ltpro/'; break;
		case 'n1': window.location = '/x/wt/'; break;
		case 'n2': window.location = '/x/gcq/'; break;
		case 'o1': window.location = '/x/wt/'; break;
		case 'o2': window.location = '/x/gcq/'; break;
		case 'v1': window.location = '/x/thesaurus/'; break;
		case 'v2': window.location = '/x/yahoorelated/'; break;
	}
} 
