var w = 0; // width
var h = 0; // height
var FullPath =''; // Path to file 

// My temp Image , so I can test height and width due to tainting on input file upload properties.
var  NEW_Image = new Image();                 // Create an Image object
     NEW_Image.onload = SIZE_Image;           // assign the event handler

// Image format allowed in the upload & NEW_Image thingy as a regular Expression
var re = /gif|jpeg|jpg|bmp$/i; // case insensitive regular Expression


// Get and test the temp image properties.
function SIZE_Image() {

      h = NEW_Image.height;
      w = NEW_Image.width;
      window.status = 'New Image : Height = ' + h +' Width = ' + w;
      
 }

// TEST Image before onSubmit , return false if image is too big
function Test_Image() {
  // My random Test of sizes to be under
  if ( h > 120 ) { alert('Image is greater in height than allowed 120 pixels'); return false; }
  if ( w > 120 ) { alert('Image is greater in width  than allowed 120 pixels'); return false; }

// Only allow submit if it is an image file allowed 

  if (FullPath.match(re)) {  
	return true;	
  }
  else if(FullPath == ''){
    return true;
  }
  else {
    alert('This is not a valid image file for uploading,\n Select another image please.');
	window.status = ' This is not a valid image format';
    return false;

  }

}

function checksize(N) {
  FullPath = N;
  if (FullPath.match(re)) {
      NEW_Image.src = FullPath; // Assign the value of the upload image to our test image.
	  return true;
  }
  else if(FullPath == ''){
    return true;
  }
  else {
    alert('This is not a valid image file for uploading,\n Select another image please.');
	window.status = ' This is not a valid image format';
	return false;
  }
}

/*** Check Length of Field Entry ***/
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	
	// otherwise, update characters left counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function ktalkpopup(url) {
	window.open(url, 'ktalk', 'status=1,scrollbars=0,height=600,width=700');
	return false;
}