// JavaScript Document
function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



function check_url(address) 
{
	if (address == "")
	return false;
	else 
	{
	 var http=address.indexOf ('http://');
	 var www=address.indexOf ('www.');
	 var https=address.indexOf ('https://');
	 if(http==0 || www==0 || https==0)
	 return true;
	 else
 	 return false;
	 }

}
function getUrlAddress(address)
{
	if (address != "")
	{   
		if(address.indexOf ('http')==0)
		return address;
		else
		return "http://"+address;
	}	
	else
	return address;
}

function isInteger(s)
{
   var i;
  			for (i = 0; i < s.length; i++)
   			{   
       		// Check that current character is number.
       		var c = s.charAt(i);
       		if (((c < "0") || (c > "9"))) return false;
   			}
    			// All characters are numbers.
return true;
}

function isImage(url)//validate the type of the file 
{	
	if (trim(url)=="")
	return true;

    url=url.toLowerCase();//convert to lowercase
	var i;
	
	//if the url contains any of the following extension return true
	if(url.indexOf ('.gif')!=-1 || 	url.indexOf ('.jpg')!=-1  || 	url.indexOf ('.jpeg')!=-1 || 	url.indexOf ('.bmp')!=-1 || url.indexOf ('.tif')!=-1 )
	return true;
	
	return false;
}
function overMouse(obj)
{
obj.style.color="blue";
//obj.style.backgroundColor="#e0ffff";
}

function outMouse(obj)
{
obj.style.color="#000e66";
//obj.style.backgroundColor="#b0c4de";
}
//Extract the file name from the given absolute path
function extractFileName(abspath)
{
	return abspath.substr(parseInt(abspath.lastIndexOf("\\"))+1,abspath.length);
}
//Extract the extension including "." from the given file name
function extractExtension(filename)
{

	return filename.substr(filename.lastIndexOf("."),filename.length);

}
//Validate the email id
function validate_email(obj)
{
			 if(obj.value!="")
			 {  
				  var email=obj.value;
				  var emailPattern=/^(.+)@(.+)$/
				  var specChars="\\(\\)<>@;\?{}'\\|/\\\\\\\"\\.\\[\\]"
				  var validCharsUser="\[^\\s" + specChars + "\]"
				  var validCharsDomain="\[^\\s" + specChars + "\[^_" + "\]"
				  var atomUser=validCharsUser + '+'
				  var atomDomain=validCharsDomain + '+'
				  var word="(" + atomUser + ")"
				  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				  var domainPat=new RegExp("^" + atomDomain + "(\\." + atomDomain+")*$")
				  var matchArray=email.match(emailPattern)

				  if (matchArray==null)
				  {	
				   obj.focus();
				   return false;
				  }
 
				 var user=matchArray[1]
				 var domain=matchArray[2]
				 if(user.match(userPat)==null) 
				 {
				 obj.focus();
				 return false;
				 }
 
				 var domainArray=domain.match(domainPat)
				 if (domainArray==null) 
				 {
				 obj.focus();
				 return false;
				 }
 
				 var atomPat=new RegExp(atomDomain,"g")
				 var domArr=domain.match(atomPat)
				 var len=domArr.length
				 if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
				 {
				 obj.focus();
				 return false;
				 }

				 var endWord="\[^0123456789\]+"
				 var endPattern=new RegExp("^(" + endWord + ")+$","g")
				 var endDom = domArr[domArr.length-1].match(endPattern)
				  if (endDom==null) 
				  {
				  obj.focus();
				   return false;
				  }
				 if (len<2) 
				 {
				 obj.focus();
				 return false;
				 }
	 		 return true;
			 }
			 else
			 {
			 obj.focus();
			 return false;
			 }
}
//set maxlength for any field - attributes (field name,max charcaters)
function checkMax(obj,maxlimit)
{		
		if (obj.value.length > maxlimit) // if too long...trim it!
		obj.value = obj.value.substring(0,maxlimit);
}

function spanMouseOver(obj)
{
obj.style.cursor="Hand";
obj.style.color="blue";
obj.style.textDecoration="underline";
}

function spanMouseOut(obj)
{
obj.style.color="blue";
obj.style.textDecoration="none";
obj.style.cursor="normal";
}