//var imagecreationpath='../../tutorials/createweb20word';
var imagecreationpath='image_creations';
loaderimage="<img style='display: inline;' src='images/pink_loader.gif' alt='' border=''>";

function loginask() {
	Modalbox.show("loginask.php", {title: "Login or Register?", width: 400});
}

function saveCreation(fuid,cidtxt,cid)
{
	uname=$('userloggedon').innerHTML;
	if (uname=='') { loginask(); }
	else {
		//construct the ajax request
		//$F() gets the field with the given id's value
		var opt = {
		method:'post', 
		postBody:'m=save&fuid=' + fuid + '&uname=' + uname,
		onSuccess: function(t) { $(cid).innerHTML = "Saved!"; $('change_password').disabled = false; },
		onFailure: function() { $(cidtxt).innerHTML = 'Un-Saved/Save Again'; $('change_password').disabled = true; },
		onLoading: function() { $(cidtxt).innerHTML = 'Saving...'; $('change_password').disabled = true; }
		}
		//send request to the ajax.php
		new Ajax.Request('ajax.php', opt);
//old
//		postBody:'m=save&fuid=' + fuid + '&id=' + useridno,

	}
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function saveMyC(fuid,thisObj,optPPG)
{
	uname=$('userloggedon').innerHTML;
	uname=trim(uname);
	if (uname=='') { loginask(); thisObj.value = "Un-Saved! Save Again?"; }
	else {
		//construct the ajax request
		//$F() gets the field with the given id's value
		var opt = {
		method:'post', 
		postBody:'m=save&fuid=' + fuid + '&uname=' + uname + '&optPPG=' + optPPG,
		onSuccess: function(t) { thisObj.value = "Saved it!"; thisObj.disabled = true; },
		onFailure: function() { thisObj.value = 'Un-Saved! Try Saving Again'; thisObj.disabled = false; },
		onLoading: function() { thisObj.value = 'Saving...'; thisObj.disabled = true; }
		}
		//send request to the ajax.php
		new Ajax.Request('ajax.php', opt);
	}
}

function styleAvail(sid_c,avail_c)
{
	var opt = {
	method:'post', 
	postBody:'m=stylechg&sid=' + sid_c + '&avail=' + avail_c,
	onFailure: function(t) { alert(t.responseText); }
	}
	//send request to the ajax.php
	new Ajax.Request('ajax.php', opt);
	return true;
}

function imageGallery(c_id,c_yn)
{
	var opt = {
	method:'post', 
	postBody:'m=gallery&cid=' + c_id + '&opt=' + c_yn,
	onFailure: function(t) { alert(t.responseText); }
	}
	//send request to the ajax.php
	new Ajax.Request('ajax.php', opt);
	return true;
}

function getUserIDNow(cidtxt,cid)
{
	alert($('userloggedon').innerHTML);
}

function getImage(fromID,toID)
{
//	Modalbox.show("showcreation.php", {title: 'my newest creation!!! muhahahaa!', width: 700, height: 200});
//	toID="showcreation";

	//construct the ajax request
	//$F() gets the field with the given id's value
	var opt = {
	method:'post', 
	postBody:'path='+imagecreationpath+'&othervars=' + '&' + Form.serialize('imageinput'),
	onSuccess: function(t) { $(toID).innerHTML = t.responseText; },
	onFailure: function() { $(toID).innerHTML = 'Un-Saved!'; },
	onLoading: function() { $(toID).innerHTML=$(fromID).innerHTML;}
	}
	//send request to the ajax.php
	new Ajax.Request('IM_functions/createword.php', opt);
}

function Html2Html(fromID,toID)
{
	$(toID).innerHTML=$(fromID).innerHTML;
}

function diggit(ru_id,scid,uid,dtype)
{
	if (dtype=="style") {
		var opt = {
			method:'post', 
			postBody:'m=diggit&sid=' + scid + '&uidno=' + uid + '&dtype=' + dtype,
			onSuccess: function(t) { $(ru_id).innerHTML = t.responseText;},
			onFailure: function() { $(ru_id).innerHTML = 'Error!' },
			onLoading: function() { $(ru_id).innerHTML = loaderimage+' Got it!'}
		}
		new Ajax.Request('ajax.php', opt);
	}
	else if (dtype=="creation") {
		var opt = {
			method:'post', 
			postBody:'m=diggit&cid=' + scid + '&uidno=' + uid + '&dtype=' + dtype,
			onSuccess: function(t) { $(ru_id).innerHTML = t.responseText;},
			onFailure: function() { $(ru_id).innerHTML = 'Error!' },
			onLoading: function() { $(ru_id).innerHTML = loaderimage+' Got it!'}
		}
		new Ajax.Request('ajax.php', opt);
	}	
}



