// JavaScript Document

/**
 * YUI version 2.8
 * @package		### red-cherry ###
 * @author 		sony
 * @copyright	Copyright (c) 2009 {@link http://www.red-cherry.com }
 * @license		http://www.red-cherry.com 
 * @since 		2010-03-07
 */
 
function getJSon(dbdata){
	try { 
		jsondata = YAHOO.lang.JSON.parse(dbdata);
		return jsondata;
	} 
	catch (x) { 
		var err = "JSON Parse failed!"; 
		return err; 
	} 
}

/*== CUY BY WORD ==*/
function cutWord(words,nwords){
	var cutword = '';
	r = words.split(' ');
	len = r.length;
	
	if(len < nwords){
		nwords = len;	
	}
	
	for (var i = 0; i < nwords; ++i) { 
		cutword += ' '+r[i];
	}
	return cutword + ' ...';
}

function redirect(url){
	window.location = url;	
}

//Mouse click events TO KNOW WHICK CLICK EVENT FIRED; onmouseup='return buttonalert(event);'
function buttonalert(event)
{
	 var button;
	 if (event.which == null)
	 button= (event.button < 2) ? "LEFT" :
	 ((event.button == 4) ? "MIDDLE" : "RIGHT");
	 else
	 button= (event.which < 2) ? "LEFT" :
	 ((event.which == 2) ? "MIDDLE" : "RIGHT");
	 alert(button);
	 dont(event);
}
function dont(event)
{
	 if (event.preventDefault)
	 	event.preventDefault();
	 else
	 	event.returnValue= false;
	 return false;
} 

function  getAllRecevedData(DataArray)
	{	
				var query="receviedData";
				var var_query_total='s_total';
				var receviedDatasTotal=DataArray[query +  var_query_total];
				for (i=1;i<=receviedDatasTotal;i++)
				{
					var selected_item=query+i+"_";
					var lsRegExp = /\+/g;
					var lsRegExp2 = /\\'/g;
					var lsRegExp3 = /\\"/g;
					var contentReceived=unescape(decodeURIComponent(DataArray[selected_item + "Text"]));
					contentReceived=contentReceived.replace(lsRegExp, " ");
					contentReceived=contentReceived.replace(lsRegExp2, "'");
					contentReceived=contentReceived.replace(lsRegExp3, '"');
					return contentReceived;
				}
	}

function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

function capsFLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}
