//Hide the content and display it.
function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,status=1,menubar=0,resizable=0,width=230,height=500,left = 50,top = 50');");
}

function popUpcomment(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=0,width=400,height=200,left = 300,top = 50');");
}


var addcommentWindow=null;
function addcomment(mypage,myname,w,h,pos,infocus){

if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=yes,location=no,directories=no,status=yes,menubar=yes,toolbar=yes,resizable=no';addcommentWindow=window.open('',myname,settings);
if(infocus=='front'){addcommentWindow.focus();addcommentWindow.location=mypage;}
if(infocus=='back'){addcommentWindow.blur();addcommentWindow.location=mypage;addcommentWindow.blur();}

}

function gmshortcutkeys() {
	if ((parseInt(navigator.appVersion) >= 4) && (navigator.appName == "Microsoft Internet Explorer")) {
		if (event.ctrlKey != true) return;
		gmselection = document.selection.createRange().text;
		if (window.event.keyCode == 1) {
			gminsertlink = prompt("Web Address", "http://")
			if (gminsertlink == null) return;
			document.selection.createRange().text = '<a href="' + gminsertlink + '" target="_blank">' + gmselection + '</a>';
			return;
		}
		if (window.event.keyCode == 2) {
			document.selection.createRange().text = '<b>' + gmselection + '</b>';
			return;
		}
		if (window.event.keyCode == 9) {
			document.selection.createRange().text = '<i>' + gmselection + '</i>';
			return;
		}
		if (window.event.keyCode == 21) {
			document.selection.createRange().text = '<u>' + gmselection + '</u>';
			return;
		}
	}
}


var cleanWindow=null;
function clean(mypage,myname,w,h,pos,infocus){

if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';cleanWindow=window.open('',myname,settings);
if(infocus=='front'){cleanWindow.focus();cleanWindow.location=mypage;}
if(infocus=='back'){cleanWindow.blur();cleanWindow.location=mypage;cleanWindow.blur();}

}


//auth failed

var authWindow=null;
function auth(mypage,myname,w,h,pos,infocus){

if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';authWindow=window.open('',myname,settings);
if(infocus=='front'){authWindow.focus();authWindow.location=mypage;}
if(infocus=='back'){authWindow.blur();authWindow.location=mypage;authWindow.blur();}

}

////////////

//change case
var first_word;


var littleWords = new Array("to", "in", "the", "of", "from", "a", "as", "an", "for", "and", "but", "with", "vs.", "or", "by", "if", "on", "v", "at");

var allCaps = new Array("aba", "pdf", "html", "xml", "fcc", "nchica", "hipaa", "glb", "erisa", "ftc", "eeo", "edgar", "osha", "cobra", "eeoc", "irs", "lp", "sec", "u.s.", "uk", "ec", "cmbs", "epa");

function changeCase(textarea) {
	first_word = true;
	var s = textarea.value;

	var str = s.toLowerCase();
	var str_temp = new Array();
	str_temp = str.split(" ");
	
	for (var i = 0; i < str_temp.length; ++i) {
		var pattern = /(^[\'\"]?)(\w)([\w]*)([\.\',:;]?)(.*)/;
		var word = str_temp[i];
		var result = pattern.exec(word);
		if (result != null) {
			str_temp[i] = toTitleCase(result, littleWords, allCaps);
		}
		first_word = getFirstWord(str_temp[i]);
	}

	var currLength = 0;
	for (var i = 0; i < str_temp.length; i++) {
		currLength += str_temp[i].length;
	}
	currLength += str_temp.length - 1;
	
	s = str_temp.join(" ");
	textarea.value = s;
}

function getFirstWord(word) {
	var ret = ( word.charAt(word.length-1) == ":");
	return ret;
}

function isInGroup(word, groupOfWords) {
//	word = word.replace(/:/, "");
	for (var i = 0; i < groupOfWords.length; ++i) {
		if (groupOfWords[i] == word)
			return true;
	}
	return false;
}

function getCase(word, littleWords, allCaps) {
	if (isInGroup(word, littleWords)) {
		return 1;	//return 1 if it is a little word;
	}
	if (isInGroup(word, allCaps)) {
		return 2;	//return 2 if this is an allcaps word;
	}
	return 3;		//return 3 for all other words;
}

function toTitleCase(result, littleWords, allCaps) {
	var word_temp, word_result;
//	result[0] contains the entire match
//	result[1] contains the (leading) ["'] (if any)
//	result[2] contains the first letter
//	result[3] contains the rest of the letters
//	result[4] contains the trailing punctuation (if any)
//	result[5] conains the trailing stuff and junk (if any)

	word_temp = result[2] + result[3];
	var word_case = getCase(word_temp, littleWords, allCaps);

	switch (word_case) {
		case 1:
			if (first_word) {
				first_word = false;
				word_result = result[2].toUpperCase() + result[3];
			} else {
				word_result = word_temp;
			}
			break;
		case 2:
			word_result = word_temp.toUpperCase();
			break;
		case 3:
			word_result = result[2].toUpperCase() + result[3];
			break;
	}

	word_result = result[1] + word_result;
	for (var i = 4; i < result.length; i++) {
		word_result += result[i];
	}

	
	return word_result;
}

function toSpace(textarea) {
	var s = textarea.value;
	s = s.replace(/_/g, " ");
	textarea.value = s;
}


function toUnderScore(textarea) {
	var s = textarea.value;
	s = s.replace(/\s/g, "_");
	textarea.value = s;
}

function clearArea(textarea) {
	textarea.value = "";
}

function getLengthText(TextArea) {
	var len = TextArea.value.length;
	alert("Length in chars\n" + len);
}

function selectTextArea(textarea) {
//	if (textarea.value == "") return;
//	var clip = textarea.createTextRange();
//	clip.execCommand("Cut");
	textarea.select();
}

function copyToClipboard(textarea) {
	if (textarea.value == "") return;
	var clip = textarea.createTextRange();
	clip.execCommand("Copy");
}

function pasteFromClipboard(textarea) {
	textarea.value = "";
	var clip = textarea.createTextRange();
	clip.execCommand("Paste");
}


//////////

//divx search

//  End -->