function confirmLink(theLink, msg) { //v1.0
	cmsg = 'Do you want to ' + msg;
  	var is_confirmed = confirm(cmsg);
   	if (is_confirmed) {
   		theLink.href += '&confirmed=1';
   	}
   	return is_confirmed;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function contact() {
	w=500;
	h=666;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';
	contactInfoWindow=window.open('/contact.php','contact',settings);
	contactInfoWindow.focus();
	
}
function pageInfo(id) {
	var path;
	path='/admin/page.php?ID=' + id;
	pageInfoWindow=window.open(path,'pageInfo','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=630,height=800');
	pageInfoWindow.focus();
}

function uploadImage(dir) {
	w=584;
	h=130;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';
	var path;
	path='/admin/upload.php?dir=' + dir;
	uploadImageWindow=window.open(path,'uploadImage',settings);
	uploadImageWindow.focus();
}
function showInterests(int) {
	var path;
	path='/admin/interests_window.php?int=' + int;
	interestsInfoWindow=window.open(path,'interestsInfo','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=645,height=250');
	interestsInfoWindow.focus();
}
function shareThis(thelink){
	//var url=location.href.replace("&", "-amp-");
	//url=location.href.replace("?", "-que-");
	var url=location.href;
	var title=document.title;
	switch(thelink.title){
		case 'Digg':
			thelink.href='http:/link.php?url=http://digg.com/submit?url='+url+'&title='+title;
			break;
		case 'Delicious':
			thelink.href='http:/link.php?url=http://del.icio.us/post?url='+url+'&title='+title;
			break;
		case 'Facebook':
			thelink.href='http:/link.php?url=http://www.facebook.com/sharer.php?u='+url+'&utm_source=facebook_1&t='+title;
			break;
		case 'ReddIt':
			thelink.href='http:/link.php?url=http://reddit.com/submit?url='+url+'&title='+title;
			break;
		case 'StumbleUpon':
			thelink.href='http:/link.php?url=http://www.stumbleupon.com/submit?url='+url+'&title='+title;
			break;
	}
	thelink.target='_blank';
	return;
}
function emailThis(thelink){
	var url=location.href.replace("&", "-amp-");
	url=location.href.replace("?", "-que-");
	var title=document.title;
	thelink.href='/popups.php?action=emailthis&url='+url+'&title='+title+'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=140&width=550&modal=false';
	return;
}
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			CMS CUSTOMIZATION
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function saveInterfaceCookie (id,state) {
	var $c= readCookie('PointBlankCMSInterface');
	$cookieValue='';
	var $found = false;
	if ($c) {
		$cookieBits=$c.split(':::');
		for (var $i=0; $i<$cookieBits.length-1; $i++) {
			var bitBits=$cookieBits[$i].split('=');
			$key=bitBits[0];
			$val=bitBits[1];
			if (id==$key) {
				$cookieValue=$cookieValue+$key+'='+state+':::';
				$found=true;
			} else {
				$cookieValue= $cookieValue+$key+'='+$val+':::';
			}
		}
	}
	if (!$found) {
		$cookieValue=$cookieValue+id+'='+state+':::';
	}
	//eraseCookie('PointBlankCMSInterface');
	createCookie('PointBlankCMSInterface',$cookieValue,365);
}

function hideContentBoxesOnLoad () {
	var $c= readCookie('PointBlankCMSInterface');
	//alert($c);
	if ($c) {
		$cookieBits=$c.split(':::');
		var $found = false;
		for (var $i=0; $i<$cookieBits.length-1; $i++) {
			var bitBits=$cookieBits[$i].split('=');
			$key=bitBits[0];
			$val=bitBits[1];
			var id=document.getElementById($key);
			if (id && $val=='false') {
				contentShowHide($key);
			}
		}
	}
}

function contentShowHide(id){
	contentDiv=document.getElementById(id);
	linkDiv=document.getElementById(id+'SH');
	//alert(contentDiv.style.display);
	if (contentDiv.style.display == 'none'){
		contentDiv.style.display = '';
		linkDiv.innerHTML='hide';
		saveInterfaceCookie(id,'true');
	} else {
		contentDiv.style.display = 'none';
		linkDiv.innerHTML='show';
		saveInterfaceCookie(id,'false');
	}
}
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			COOKIES
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	//return null;
	return '';
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			CLEAR FORMS
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function clearForm(formIdent) 
{ 
  var form, elements, i, elm; 
  form = document.getElementById 
    ? document.getElementById(formIdent) 
    : document.forms[formIdent]; 

	if (document.getElementsByTagName)
	{
		elements = form.getElementsByTagName('input');
		for( i=0, elm; elm=elements.item(i++); ) 	{
			if (elm.getAttribute('type') == "text")	{
				elm.value = '';
			}
			if (elm.getAttribute('type') == "checkbox")	{
				elm.checked=false;
			}
		}
		elements = form.getElementsByTagName('select');
		for( i=0, elm; elm=elements.item(i++); )	{
			elm.options.selectedIndex=0;
		}
	}

	// Actually looking through more elements here
	// but the result is the same.
	else
	{
		elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.type == "text")	{
				elm.value ='';
			}
			if (elm.type == "select")		{
				elm.options.selectedIndex=0;
			}
			if (elm.type == "checkbox") 	{
				elm.checked=false;
			}
		}
	}
}


// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			CHECKING EMAIL
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function checkIdentifier(ID,identifier) {
	getpost = "POST";
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	var message = document.getElementById('identifierMessage');
	
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			// got response
			message.innerHTML='';
			if (http_request.responseText=='found') {
				message.innerHTML='<span style="color:#FF0000">Error: identifier must be unique.</span>';
			}
		} else {
			message.innerHTML='<span style="color:#FFCC00">Checking identifier. Please wait...</span>';
		}
	};
	http_request.open(getpost, 'process.php?from=checkIdentifier&ID='+ID+'&identifier='+identifier, true);
	if(getpost == "POST") {
		http_request.send('');
	} else {
		http_request.send(null);
	}
	//http_request.open("POST","test_get_values.php",true);
	//http_request.send('topic=mp');
}


// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			CURSORS
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function cursor_hand() {
document.body.style.cursor = 'wait';
}

// Returns the cursor to the default pointer
function cursor_clear() {
document.body.style.cursor = 'default';
}

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			DREAMWEAVER
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			TINY EDITOR
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function callMceEditor(type, dir) {
	if (type=='full') {
		//imagelist="/include/image_list.php?browse="+dir;
		tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			skin : "o2k7",
			skin_variant : "silver",
			editor_selector : "mceEditor",
			width : "100%",
			content_css : "/include/mce_editor.css",
			extended_valid_elements : "a[href|target|name|class|title]",
			theme_advanced_styles : "Header 13=header13;Orange Bold=header2;Table Body=tableBody;Table Header=tableHeader;Table Background=tableBack;Image Caption=imageCaption;Image Border=imageBorder;Image on left=imageLeft;Image on right=imageRight;Image on left with border=imageLeftBorder;Image on right with border=imageRightBorder; ThickBox=thickbox", // Theme specific setting CSS classes
			plugins : "table,save,preview,advimage,zoom,contextmenu,paste,media,tinybrowser,contentelements,spellchecker",
			spellchecker_languages : "+English=en",
			theme_advanced_buttons1 : "save,separator,undo,redo,separator,pastetext,pasteword,separator,bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,styleselect,separator,outdent,indent,sub,sup",
			theme_advanced_buttons2 : "tablecontrols,separator,image,media,InsertContentElements,separator,browseimages,browsemultimedia,browse,separator,link,unlink,separator,hr,separator,removeformat,cleanup,code,spellchecker",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			//external_image_list_url : imagelist,
			paste_use_dialog : false,
			paste_auto_cleanup_on_paste : true,
			paste_force_cleanup_wordpaste : true,
			paste_strip_class_attributes : "all",
			paste_create_linebreaks : false,
			paste_remove_spans : true,
			paste_remove_styles : true,
			//paste_insert_word_content_callback : "convertWord",
			paste_preprocess : function(pl, o) {
				// Content string containing the HTML from the clipboard
				//alert(o.content);
			},
			paste_postprocess : function(pl, o) {
				// Content DOM node containing the DOM structure of the clipboard
				//alert(o.node.innerHTML);
			},
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,
			paste_auto_cleanup_on_paste : true,
			force_br_newlines : false,
			auto_resize : false,
			relative_urls : false,
			file_browser_callback : "tinyBrowser",
			// file manage buttons
			setup : function(ed) {
				// Add a custom button
				ed.addButton('browseimages', {
					title : 'Image manager',
					image : '/tinymce/jscripts/tiny_mce/themes/advanced/img/browseimages.gif',
					onclick : function() {
						// Add you own code to execute something on click
						tinyBrowserPopUp('image','');
						//ed.selection.setContent('<strong>Hello world!</strong>');
					}
				});
				ed.addButton('browsemultimedia', {
					title : 'Media manager',
					image : '/tinymce/jscripts/tiny_mce/themes/advanced/img/browsemultimedia.gif',
					onclick : function() {
						// Add you own code to execute something on click
						tinyBrowserPopUp('media','');
						//ed.selection.setContent('<strong>Hello world!</strong>');
					}
				});
				ed.addButton('browse', {
					title : 'File manager',
					image : '/tinymce/jscripts/tiny_mce/themes/advanced/img/browse.gif',
					onclick : function() {
						// Add you own code to execute something on click
						tinyBrowserPopUp('file','');
						//ed.selection.setContent('<strong>Hello world!</strong>');
					}
				});
			}
		
		});
	}
}

function convertWord (type, content) {
    switch (type) {
        // Gets executed before the built in logic performs it's cleanups
        case "before":
            //content = content.toLowerCase(); // Some dummy logic
           // alert(content);
            break;
        // Gets executed after the built in logic performs it's cleanups
        case "after":
            //alert(content);
            content = content.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/g,'');
			//alert(content);
            //content = content.toLowerCase(); // Some dummy logic
            //alert(content);
            break;
    }
    return content;
}

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			HIGHLIGHTING ROWS
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function highlight_rows_init() {
var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( rows[i].className.substr(0,7) == 'listRow' ) {
			// ... 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 += 'IEhover';
				}
				rows[i].onmouseout = function() {
					this.className = this.className.replace( 'IEhover', '' );
				}
			}
        }
	}
}
window.onload=highlight_rows_init;

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//																			TRAIL IMAGE
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 60;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimageid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimageid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(content){

	document.onmousemove=followmouse;
	//cursor_hand();

	newHTML = '<div style="padding: 5px; background-color: #252525; border: 1px solid #888; font-size:10px">';
	newHTML = newHTML + content;
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
	gettrailobj().position="absolute";
	currentimageheight = $('trailInnerDiv').offsetHeight;
}

function hidetrail(){
	//cursor_clear();
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}
