/* General Functions */
/* ©2007 Nitin Gupta */

// 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 Trailing whitespaces
function trim( value ) 
{
	return LTrim(RTrim(value));
}

// Return string after removing "%" spacial character
function removePercentage(value)
{
    return value.replace(/%/g,'');
}

// Return Object with properties url, protocol,host,path,file,hash of any Object
function parseEmeddedUrl(url) 
{
    var e = /((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?/
    if (url.match(e)) 
        return  {url: RegExp['$&'], protocol: RegExp.$2,host:RegExp.$3, path:RegExp.$4,file:RegExp.$6,hash:RegExp.$7};
    else 
        return null;
}

//Validation Function return boolean
function isEmail(data) 
{
    return /^([\w]+)(\.[\w]+)*@([\w\-]+)(\.[\w]{2,4})(\.[a-z]{2})?$/i.test(data);
}

function isString(data) 
{
    // use if first char must between a to z;
    return /^[a-z$_][\w$]*$/i.test(data);
    //return /^[\w$]*$/i.test(data);
}

function isPassword(data) 
{
    // use any charecter without spaces;
    return /^[\W$]*[\w$]*$/i.test(data);
}

function uInteger(str) {
    /* Verify unsigned integer
     *        ignoring leading and trailing spaces
     * Return boolean
     */
    str = str.replace(/^\s+|\s+$/g, '');
    return /^[0-9]+$/.test(str);
}//eof - uInteger


function ButtonClick(event, button)
{
	if(event.keyCode == 13)
	{
		button.click();
		return false;
	}
}

function isURL(str)
{
    //  var exp=/(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]));
    var exp=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    //var exp = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
    return  exp.test(str);
    //return  /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/.test(str);
}

function Upadate(Elements,DropDwn,SelectID)
{
    DropDwn.options.length = 1
    for(var i=0;i<Elements.length;i++)
    {
        
        var addOption = new Option();
        addOption.value = Elements[i].getAttribute("id");
        addOption.innerHTML = Elements[i].getAttribute("text");
        if(addOption.value == SelectID)addOption.selected = true;
        DropDwn.appendChild(addOption);
    }
}


function getFileName(FilePath)
{
        FilePath = FilePath.split("\\");
        FilePath = FilePath[FilePath.length-1].split(".");
        return {file: FilePath[0].toLowerCase(), ext: FilePath[1].toLowerCase()};
} 