/**
 * @description: Remove all extra whitespaces and remove spaces at the beginning and ending of a string
 * @params: string 
 * @return: string
 */
function trimAll (str){
	return str.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
}

/**
 * @description: Checks if the param string or array is empty
 * @params: string / array
 * @return: true or false
 */
function isEmail (str) {
	return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(trimAll(str));
}

/**
 * @description: Detect mobile devices
 * @params: string 
 * @return: boolean
 */
function isMobileClient(userAgent) {
	var mobileClients = [
		"midp",
		"240x320",
		"blackberry",
		"netfront",
		"nokia",
		"panasonic",
		"portalmmm",
		"sharp",
		"sie-",
		"sonyericsson",
		"symbian",
		"windows ce",
		"benq",
		"mda",
		"mot-",
		"opera mini",
		"philips",
		"pocket pc",
		"sagem",
		"samsung",
		"sda",
		"sgh-",
		"vodafone",
		"xda",
		"iphone",
		"android",
		"ipad"
	];
	userAgent = userAgent.toLowerCase();
	for (var i in mobileClients) {
		if (userAgent.indexOf(mobileClients[i]) != -1) {
			return true;
		}
	}
    return false;
};

/**
 * @description: Gets the ipod/iphone/ipad window orientation
 * @params: none 
 * @return: string
 */
function getWindowOrientation() {
	var orientation = 'landscape';
	var supportsOrientation = (typeof window.orientation == 'number' && typeof window.onorientationchange == 'object');
	if(supportsOrientation) {
		orientation = window.orientation;
		switch(orientation) {
			case 90: case -90:
				orientation = "landscape";
			break;
			default:
				orientation = "portrait";
			break;
		}
	}
	return orientation;
};
