///\\\\\/////////////////////////////////\\\\//////\\\\////////
////\\\\\///////////////////////////////\\\\\\////\\\\\\//////
/////\\\the shine_lib.js constructed by Chris Santala 2008
//////\\\\\///
///////\\\\\/
////// csantala@gmail.com/
////// 
////// 





function add_category(record, container)
{
	var new_cat = prompt("Add new Catagory");
	
	if (new_cat != null && new_cat != "")
	{
		blogformAjax('username'+record, 'email'+record, 'website'+record, 'blog'+record, new_cat, record, container, 'shine/blog_system/blog_db.php', 'new_cat');
		return;
	}

}

function remove_category(record, container, category)
{
	formname = "blogform"+record; 
	var w = document.getElementById(category).selectedIndex;  
	var cat = document.getElementById(category).options[w].text;
	if (cat == "") return;
	var remove = confirm('Remove '+cat+' category?');
	if (remove==true) 
	{
		blogformAjax('username'+record, 'email'+record, 'website'+record, 'blog'+record, category, record, container, 'shine/blog_system/blog_db.php?cat='+cat, 'rem_cat');
		return
	}
	else return;

}




// onkeypress="return captureKeys(event);"
function captureKeys (evt)
{
	var keyCode = evt.keyCode ? evt.keyCode :
	evt.charCode ? evt.charCode : evt.which;

	alert(keyCode);
	
	if (keyCode == 'duh')
	{
	// cancel key:
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
return true;
}


function wordCount(record)
{
	wordcounter = 0;
	text = document.getElementById(record).value;
	
//	words=text.split(" ").length;
	for (x=0;x<text.length;x++)
	{ 
		if (text.charAt(x) == " " && text.charAt(x-1)!= " ") {wordcounter++} // Counts the spaces while ignoring double spaces, usually one in between each word.
	}
	alert(wordcounter);
}
	

function popin(element)
{

//	alert(element);
// document.getElementById(element).style.backgroundColor="green";	
document.getElementById(element).style.visibility="visible";
document.getElementById(element).style.position="relative";
}

function makeactive(tab, cells, tcontainer)
{
	// alert(tab);
	for (i = 1; i <= cells; i++)
	{
		erase = tcontainer+i; // alert(erase);
		document.getElementById(erase).className = ""; 
	}

document.getElementById(tab).className = "active";
} 



function test()
{
	alert('hello there');
}


function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
  	// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
		return xmlHttp;
}


function stateChanged()
{ 
	if (xmlHttp.readyState==4)
	{  
		result = xmlHttp.responseText;

		char = String.fromCharCode(0); 
		if (result.substring(0, 1) == char) window.location = "index.php";
		document.getElementById(kontainer).innerHTML=result;
		
	}
}

function doAjax(url, container, data)
{ 
// 	loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"?container="+container+"&data="+data+"&sid="+Math.random();
// alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	// loading_off('notifier');
}

function doCleanAjax(url, container)
{ 
// 	loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"&sid="+Math.random();
 // alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	// loading_off('notifier');
}

// his.parentNode, \'shine_name\', \'shine_type\', \'shine_rating\', \'shine_home\', \'shine_notes\', \''.$container.'\', \'shine/download_system/download_db.php\');" />

function DELETE_downloadAjax(name, type, rating, shome, notes, container, record)
{
// 	loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"?profile_person="+profile_person+"&record="+record+"&container="+container+"&sid="+Math.random();
// alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}




function profileAjax(profile_person, record, url, container)
{
// 	loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"?profile_person="+profile_person+"&record="+record+"&container="+container+"&sid="+Math.random();
// alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



function label(container, content)
{
	document.getElementById(container).innerHTML = content;
}



// form ajax (logon, register, profile, comments)
var http_request = false;

function makeRequest(url, parameters, container) {
	   
	kontainer = container;
	http_request = false;
    if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
    	http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{ 
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
		}
    }
	else if (window.ActiveXObject)
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
				catch (e) {}
		}
	}
	      if (!http_request)
		  {
			alert('Cannot create XMLHTTP instance');
			return false;
    	  }
	
	http_request.onreadystatechange = alertContents;
	
	http_request.open('GET', url + parameters, true);

	http_request.send(null);

}

function makeRequestb(url, parameters, container) {
 
	kontainer = container;
	http_request = false;
    if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
    	http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{ 
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
		}
    }
	else if (window.ActiveXObject)
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
				catch (e) {}
		}
	}
	      if (!http_request)
		  {
			alert('Cannot create XMLHTTP instance');
			return false;
    	  }

	http_request.onreadystatechange = alertContents;
	
	http_request.open('POST', url, true);	
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close")
	http_request.send(parameters);
}


function alertContents()
{ 
//	alert(kontainer); 

	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{ 
			result = http_request.responseText; // alert(result);
//			char = String.fromCharCode(0); 
			if (result.substring(0, 3) == "...") window.location = "index.php";
//			if (result.substring(0, 3) == "...") alert('do ajax!');
			document.getElementById(kontainer).innerHTML = result; 
		}
			else
		{
			alert('There was a problem with the request.');
		}
	}
}

function logonAjax(email, password, remember, container, page)
{

	var getstr = "";

	email = document.getElementById(email).value;	// get email field text

	password = document.getElementById(password).value;	// get password
	
	remember = document.getElementById(remember).checked;	// remember checkbox value

	getstr += "email="+email+"&password="+password+"&remember="+remember+"&container="+container;

	makeRequestb(page, getstr, container);	
	
}


function registerAjax(obj, username, password, password2, email, container, page)
{
//alert('register ajax');
	var getstr = "?";

	username = document.getElementById(username).value;	// get username field text

	password = document.getElementById(password).value;	// get password field text
	
	password2 = document.getElementById(password2).value;	// get password field text
	
	email = document.getElementById(email).value;	// get email field text

//	var test = String.fromCharCode(13);

	getstr += "username="+username+"&password="+password+"&password2="+password2+"&email="+email+"&container="+container+"&sid="+Math.random();

	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	
	
}



function emailformAjax(obj, email, password, container, page, action, record)
{
// alert(record);

	var getstr = "?";

	email = document.getElementById(email).value;	// get username field text

	password = document.getElementById(password).value;	// get comment field text

//	var test = String.fromCharCode(13);

	getstr += "email="+email+"&password="+password+"&container="+container+"&action="+action+"&record="+record+"&sid="+Math.random();
//alert(getstr);
	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	
	
}


function downloadAjax(obj, name, type, rating, shome, notes, container, id, record, page, action)
{
// alert(record);

	var getstr = "?";

	name = document.getElementById(name).value;

	type = document.getElementById(type).value;
	
	rating = document.getElementById(rating).value;

	shome = document.getElementById(shome).value;	
	
	notes = document.getElementById(notes).value;
	
	
//	var test = String.fromCharCode(13);

	getstr += "action="+action+"&name="+name+"&type="+type+"&rating="+rating+"&shome="+shome+"&notes="+notes+"&id="+id+"&record="+record+"&container="+container+"&sid="+Math.random();
//alert(getstr);
	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	

}



function loading_on(container)
{ 
//	document.getElementById(container).innerHTML=Image1;
	document.getElementById(container).innerHTML='<img src="shine/images/one_moment_please.gif">';
}


function loading_off(container)
{
	document.getElementById(container).innerHTML='';
}


function test()
{
	alert('hello there - comment_lib.js');
}

function label(container, content)
{
	document.getElementById(container).innerHTML = content;
}


function commentAjax(url, container)
{ 
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject(); 
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"&container="+container+"&sid="+Math.random();
// alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function editorAjax(url, container)
{ 	
	//loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"&container="+container+"&sid="+Math.random();
//alert(url);

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function editprofileAjax(url, container)
{ //	alert(container);
	loading_on(container);
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"&action=edit"+"&container="+container+"&sid="+Math.random();
//alert(url); 
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}




function commentformAjax(obj, username, email, website, commenttxt, record, container, page)
{ //alert(zomment);
	var getstr = "?";

	username = document.getElementById(username).value;	// get username field text

//	email = document.getElementById(email).value;	// get email field text
	
	website = document.getElementById(website).value;

	comment = document.getElementById(commenttxt).value;	// get password field text

	comment = comment.replace(/#/g, "moneeba" );
	comment = comment.replace(/&/g, "zoneeba" );
	comment = encodeURI( comment );

	getstr += "username="+username+"&email="+email+"&website="+website+"&comment="+comment+"&record="+record+"&container="+container;
	getstr = getstr.replace(/%0A/g, 'mon33ba');
	getstr = getstr.replace(/%0D/g, '');
//alert(getstr);	
	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	
	
}

function commentformAjax_b(obj, username, email, website, comment, record, container, page)
{	
// alert(record);
	var getstr = "?";

//	username = document.getElementById(username).innerHTML;

//	email = document.getElementById(email).value;	// get email field text
	
//	website = document.getElementById(website).innerHTML;	

	comment = document.getElementById(comment).value;	// get password field text

	comment = comment.replace(/#/g, "moneeba" );
	comment = comment.replace(/&/g, "zoneeba" );
	
	comment = encodeURI( comment );

	getstr += "username="+username+"&email="+email+"&website="+website+"&comment="+comment+"&record="+record+"&container="+container;
	getstr = getstr.replace(/%0A/g, 'mon33ba');
	getstr = getstr.replace(/%0D/g, '');

//alert(getstr);
	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	
	
}

function blogformAjax(username, email, website, commenttxt, category, record, container, page, action)
{
	var getstr = "";

	username = document.getElementById(username).value;	// get username field text 

	comment = document.getElementById(commenttxt).value;	// get blog text area text
	
	if (action != 'new_cat')
	{
		var w = document.getElementById(category).selectedIndex;  
		var cat = document.getElementById(category).options[w].text;
	}
	
	if (action != 'new_cat') category = document.getElementById(category).value;  // when adding a new category from a blog, action = "new_cat"	

	comment = comment.replace(/#/g, "moneeba" ); 
	comment = comment.replace(/&/g, "zoneeba" );
	comment = comment.replace(/\\/g, "zaneeba" );	
	comment = encodeURI( comment );

	getstr += "username="+username+"&email="+email+"&website="+website+"&category="+category+"&comment="+comment+"&record="+record+"&container="+container+"&action="+action+"&cattext="+cat;
	getstr = getstr.replace(/%0A/g, 'mon33ba');
	getstr = getstr.replace(/%0D/g, '');

	makeRequestb(page, getstr, container);	
	
}


function editorformAjax(obj, title, text, category, table, record, container, action, page)
{	
// alert(record);
	var getstr = "";

	title = document.getElementById(title).value;	// get email field text
//	alert(container);
	text = document.getElementById(text).value;	// get email field text
// alert(title); alert(text);

	if (action != 'new_cat')
	{
		var w = document.getElementById(category).selectedIndex;  
		var cat = document.getElementById(category).options[w].text;
	}
	
	if (action != 'new_cat') category = document.getElementById(category).value;

	title = title.replace(/#/g, "moneeba" );	
	text = text.replace(/#/g, "moneeba" );
	title = title.replace(/&/g, "zoneeba" );
	text = text.replace(/&/g, "zoneeba" );
	text = encodeURI( text );

	var test = String.fromCharCode(13);

	getstr += "container="+container+"&table="+table+"&record="+record+"&title="+title+"&text="+text+"&action="+action+"&cattext="+cat+"&category="+category;
	getstr = getstr.replace(/%0A/g, 'mon33ba');
	getstr = getstr.replace(/%0D/g, '');

	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequestb(page, getstr, container);	
	
}

function profileformAjax(obj, record, url, caption, password1, password2, free, container, action, page)
{	
// alert(record);
//	alert(container);
	
	var getstr = "?";
	
	if (action != 'edit')
	{
		url = document.getElementById(url).value;
		caption = document.getElementById(caption).value;
		// email = document.getElementById(email).value;
		password1 = document.getElementById(password1).value;	
		password2 = document.getElementById(password2).value;
		free = document.getElementById(free).value;
	
// alert(title); alert(text);

		url = url.replace(/#/g, "moneeba" );	
		caption = caption.replace(/#/g, "moneeba" );
		// email = email.replace(/#/g, "moneeba" );
		password1 = password1.replace(/#/g, "moneeba" );
		password2 = password2.replace(/#/g, "moneeba" );
		free = free.replace(/#/g, "moneeba" );
		free = encodeURI( free );
	}
//	else {url = null; caption = null; email = null; password1 = null; password2 = null; free = null; }

	getstr += "&container="+container+"&record="+record+"&url="+url+"&caption="+caption+"&password1="+password1+"&password2="+password2+"&free="+free+"&action="+action+"&sid="+Math.random();
	getstr = getstr.replace(/%0A/g, 'mon33ba');
	
	for (i=0; i<obj.childNodes.length; i++)
	{
		if (obj.childNodes[i].type == "hidden")
		{
        	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
        }
	}
	
	makeRequest(page, getstr, container);	
	
}


function alertComment(comment, record, container)
{ 
// 	loading_on(container);

	url = "shine/comment_system/report_comment.php";
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url=url+"?comment="+comment+"&record_id="+record+"&container="+container+"&sid="+Math.random();
// alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


// pagination system Ajax
// augmented by Chris Santala 2008

function paginatorAjax(url, container, record)
{
	kontainer = container; // global variable hack to allow dynamic container names
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
//	url=url+"&container="+container+"&sid="+Math.random();
	url=url+"&container="+container+"&record="+record+"&sid="+Math.random();
//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



// buffering
Image1 = new Image(93,10);
Image1.src = "images/one_moment_please.gif";



