/**************************************
'File Name		:	i_js.js
'Purpose		:	The JS File
'Issues			:
'Version		:	1.0.0
'*************************************/

/*Function to return string by removing initial and trailing spaces*/

function trim(pstrString)
{	var intLoop = 0;
	
	for(intLoop = 0; intLoop < pstrString.length;intLoop = intLoop + 1 )
	{	
		if(pstrString.charAt(intLoop) == " ")
			pstrString = pstrString.substring(intLoop + 1, pstrString.length);
		else
			break;
	}
	
	for(intLoop = pstrString.length - 1; intLoop >= 0; intLoop = pstrString.length - 1)
	{	
		if(pstrString.charAt(intLoop) == " ")
			pstrString = pstrString.substring(0,intLoop);
		else
			break;
	}
	
	return pstrString;
}

// Function to display error message and set focus to supplied object
 function AbortEntry(sMsg, Obj)
 {
	alert(sMsg);
	Obj.focus();
	return false;
 }
 
 //Function to Validate Email address entered by user in Obj
 function validate_email(Obj) 
  {
    if(Obj.value.length == 0) { 
      return AbortEntry("Please enter Email address",Obj); 
      }
    if(-1 == Obj.value.indexOf("@")) { 
       return AbortEntry("Your email must have a '@'",Obj); 
       }
    if(-1 != Obj.value.indexOf(",")) { 
       return AbortEntry("Your email must not have a ',' in it",Obj);
       }
    if(-1 != Obj.value.indexOf("#")) { 
       return AbortEntry("Your email must not have an '#' in it.",Obj); 
       }
    if(-1 != Obj.value.indexOf("!")) { 
       return AbortEntry("Your email must not have a '!' in it.",Obj); 
       }
    if(-1 != Obj.value.indexOf(" ")) { 
       return AbortEntry("Your email must not have a space in it.",Obj); 
       }
    if(Obj.value.length == (Obj.value.indexOf("@")+1) ) {
       return AbortEntry("Your email must have a domain name after the '@'.",Obj); 
       }
    if(-1 == Obj.value.indexOf(".")) { 
       return AbortEntry("Your email must have a '.'.",Obj); 
       }
    if(Obj.value.length == 0) { 
      return AbortEntry("Please enter your email.",Obj); 
      }
    return true;
  }

var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
	function previewImage(pathField, previewName)
	{ 
		var path = pathField.value;
		if (path.search(imgRe) != -1)
		{ 
			document[previewName].src = 'file://'+path;
			{
				var img = new Image();
					img.src = 'file://'+path;
					//document.write(img.width + ' pixels wide x ' + img.height +' pixels high<br>'+ '<img src=' + img.src + '><br>');
					if(img.width >= 1024)
					 {
						alert('Image dimensions too big');
					 }	
					else
					 { 
						alert('image dimensions:'+ img.width + ' x ' + img.height );
					 }	
			}
			
			{

				var size = (document.fileSize)*1;
				var y = document.images;
				var imglength = 0;
				for (i=0;i<y.length;i++)
				{
					imglength += (y[i].fileSize)*1/1024;
				}
				var total = size + parseInt(imglength)/1024;
		
				var writestring = 'Image file size: ' + parseInt(imglength) + ' KB' ;
		
		
				if (parseInt(imglength) > 1024) writestring += "\nFile too large!";

					alert(writestring);
			}

		} 
		else 
		{ 
			alert("JPG, PNG, and GIFs only!");
		} 
	}
  

	


	
	
	
	
