function trim(str)
{
	var i=0,p = str.length-1;
	while(str.charAt(i)==' ') i++;
	while(str.charAt(p)==' ') p--;
	if(i>p) return '';
	return str.substring(i,p+1);
}
function checkEmail(strng)
{
	var error = "";
	if (strng == "")
		{
		error = "You did not enter an email-address.\n";
		}
	var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (!(emailFilter.test(strng))) 
		{ 
		error = "Please enter a valid email address.\n";
		}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if(strng.match(illegalChars))
		{
		error = "The email address contains illegal characters.\n";
		}
	return error;
}
function checkFileName(strng)
{
	var error = "";
	if (strng == "")
		{
		error = "You did not enter a file name.\n";
		}
	var fileNameFilter=/^[a-zA-Z0-9-_]*$/;
	if (!(fileNameFilter.test(strng))) 
		{ 
		error = "Please enter a valid file name.\n ** File name can contain 'alphabets','numbers', 'underscore' or 'hyphen'. \n \n";
		}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if(strng.match(illegalChars))
		{
		error = "The file name contains illegal characters.\n ** File name can contain 'alphabets','numbers', 'underscore' or 'hyphen'. \n \n";
		}
	return error;
}
function RemoveSpecialCharactersForFileName(strng)
{
	var temp = "";
	var myRegExp = new RegExp("|'|\\\\|\"","g");  
	temp = strng.replace(myRegExp, "-");

	//temp =  strng.replace(/^[a-zA-Z0-9-_]*$/,'_');
	return temp;

}
function checkalphanumeric(alphane)
{
	var str = alphane;
	for(var j=0; j<str.length; j++)
	{
		var alphaa = str.charAt(j);
		var chrcode = alphaa.charCodeAt(0);
		if((chrcode > 47 && chrcode<59) || (chrcode > 64 && chrcode<91) || (chrcode > 96 && chrcode<123) || chrcode==95)
		{
		}
		else
		{
			return false;
		}
	}
	return true;
}
function checkNumeric(strng,errmsgfield) {
	var error = "";
	var illegalChars = /\D/;
	if (illegalChars.test(strng)) {
	   	error = errmsgfield+" is invalid.\n";
	}
	return error;
}
function checkEmailAddress(emailval) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailval)){ return true; }
	return false;
}
function checkDateFormat(strngDate)
{
	/* This function will check the date format is (dd/mm/yyyy). If format is not this then it will show error message*/
	// regular expression to match required date format
    
	
	var error = "";
	if (strngDate == "")
	{
		error = "You did not enter date.\n";
	}
	var re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
	if(!strngDate.match(re))
	{
		error += "The date format is not accepted. Please use the format (dd/mm/yyyy)\n";
	}
    if(strngDate != '')
	{
		if(regs = strngDate.match(re)) 
		{
			if(regs[1] < 1 || regs[1] > 31) 
			{
			  error += "Invalid value for day: " + regs[1] + ".\r\n";
			}
			if(regs[2] < 1 || regs[2] > 12) 
			{
			  error += "Invalid value for month: " + regs[2] + ".\r\n";
			}
			if(regs[3] < 1902 || regs[3] > (new Date()).getFullYear()) 
			{
			  error += "Invalid value for year: " + regs[3] + " - must be between 1902 and " + (new Date()).getFullYear() + ".\r\n";
			}
		} 
    }
	return error;
}
function checkArray(form, arrayName) 
{ 
	var retval = new Array(); 
	for(var i=0; i < form.elements.length; i++) 
	{ 
		var el = form.elements[i]; 
		if(el.type == "checkbox" && el.name == arrayName && el.checked) 
		{
			retval.push(el.value); 
		} 
	} 
	return retval;
}
function sortby(sortname)
{
	var frm = document.formmain;
	if(frm.sortby.value==sortname)
	{
		if(frm.sorttype.value=="ASC")
		{
			frm.sorttype.value="DESC";
		}
		else
		{
			frm.sorttype.value="ASC";
		}
	}
	else
	{
		frm.sortby.value=sortname;
		frm.sorttype.value="ASC";
	}
	frm.submit();
}
function openWin(URL){aWindow=window.open(URL,"theWindow","height=380,width=585,left=200,top=100,scrollbars=no");}
function openWin_EmailFriend(URL){aWindow=window.open(URL,"theWindow","height=580,width=525,left=200,top=100,scrollbars=yes");}
function openWin_PrintPage(URL){aWindow=window.open(URL,"theWindow","height=580,width=525,left=200,top=100,scrollbars=yes");}
function openWin_PhotoLarge(URL){aWindow=window.open(URL,"theWindow","height=600,width=600,left=200,top=100,scrollbars=yes");}
function openWin_EditGallery(URL){aWindow=window.open(URL,"theWindow","height=600,width=600,left=200,top=100,scrollbars=yes");}
