// JavaScript Document

function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}

function emailCheck(s1) {
emailStr=s1;

		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) 
		{

			alert("Email address seems incorrect (check @ and .'s)")
			return false
		}
return true;
}
function emailInvalid(s)
{
	if(!(s.match(/^[\w]+([_|\.-][\w]{1,})*@[\w]{2,}([_|\.-][\w]{1,})*\.([a-z]{2,4})$/i) ))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ImageValidation(filename)
{	
	if(document.getElementById(filename).value!='')
	{	
		var x;
		x=document.getElementById(filename).value;
		var y;
		var z;
		z="no";
		y=x.split(".");
		var Ext = y.length-1;
		if(y[Ext]=="jpeg")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="JPEG")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="jpg")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="JPG")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="gif")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="GIF")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="png")
		{ 
			z='yes'; 
		}
		else if(y[Ext]=="PNG")
		{ 
			z='yes'; 
		}
		else
		{
			z='no';
		}
		
		if(z=='no')
		{ 
			alert("Attach only .JPG, .JPEG, .GIF or .PNG Image");
			document.getElementById(filename).value='';
			document.getElementById(filename).focus();
			return false; 
		}		
		
	}
}
function deleteconfirm(str,strurl)
{
	if (confirm(str)) 
	{
		this.location=strurl;
	}
}	
function in_ext_lib(str)
{
	var x;
	var flag = 0;
	var myext = new Array();
	myext[0] = ".jpg";
	myext[1] = ".jpeg";
	myext[2] = ".png";
	myext[3] = ".gif";
	/*myext[4] = ".pdf";
	myext[5] = ".PDF";
	myext[6] = ".txt"; */
	
	for (x in myext)
	{
		if(str.substr(str.lastIndexOf(".",str)).toLowerCase() == myext[x])
		{
			flag = 1;
			break;
		}
	}
	if(flag == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function openWin(pageToLoad, winName, width, height, center,scrollbar){
	
	  if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		        xposition = (screen.width - width) / 2;
		        yposition = (screen.height - height - 100) / 2;
	args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=no," + "scrollbars=" + scrollbar + "," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
	newWindow = window.open(pageToLoad,winName,args);	
	window.focus;
	}
}

