
function executeOnSubmit(Message) {

var res = confirm(Message);

if(res)
return true;
else
return false;
}


function clickclear(thisfield, defaulttext, newtext) {
if (thisfield.value == defaulttext) {
	if(newtext == undefined) {
		newtext = '';
	}	
	
	thisfield.value = newtext;
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == '') { 
thisfield.value = defaulttext;
}
}

function checkall(theElement) {	 
	 i=1;
	 a = theElement + i;
	 if(document.getElementById(theElement).checked == true) {
		 do {
			 a = theElement + i;
			 var b = document.getElementById(a);
			 if(document.getElementById(a)) {
			 	b.checked = true;
			 }
			 i++;
		 } while(document.getElementById(a))
	 }
	 else {
		  do {
			 a = theElement + i;
			 var b = document.getElementById(a);
			 if(document.getElementById(a)) {
				 b.checked = false;
			 }
			 i++;
		 } while(document.getElementById(a))		 
	 } 
}
	
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}
	
function cleartext(Field) {
	Field.value = '';
}

function bg(fieldname) {	
		fieldname.className = "Active_Cell";
}

function back(fieldname) {
	fieldname.className = "Center_Text";

}

var baseText = null; 
function showPopup(){   
	var popUp = document.getElementById("popupcontent");
	if (baseText == null) baseText = popUp.innerHTML;  
		popUp.innerHTML = baseText +       "<p><div align='center' id=\"statusbar\"><button onclick=\"hidePopup();\">Close window</button></div></p>";   
		var sbar = document.getElementById("statusbar");
		popUp.style.visibility = "visible";
}

function hidePopup(){   
	var popUp = document.getElementById("popupcontent");   
	popUp.style.visibility = "hidden";
}

function setOpacity() {
	body.style.filter = 'alpha(opacity=33)';
}

function hide(itemID) {
	var x = document.getElementById(itemID);
	x.style.visibility = "hidden";
}

function colapse(itemID) {
	var x = document.getElementById(itemID);
	x.style.display = "none";
	x.style.visibility = "hidden";
}

function uncolapse(itemID) {
	var x = document.getElementById(itemID);
	x.style.display = "inline";
	x.style.visibility = "visible";
}

function show(itemID) {
	var x = document.getElementById(itemID);
	x.style.visibility = "visible";
}

function center(object)
 {
	 
  document.getElementById(object).style.marginLeft = "-" + parseInt(object.offsetWidth / 2) + "px";
  document.getElementById(object).style.marginTop = "-" + parseInt(object.offsetHeight / 2) + "px";
 }
 



// Get value of radio object
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function checkFileUpload(form, extensions, requireUpload, sizeLimit, minWidth, minHeight, maxWidth, maxHeight, saveWidth, saveHeight) {
  var allUploadsOK = true;
  document.MM_returnValue = false;
  for (var i = 0; i < form.elements.length; i++) {
    field = form.elements[i];
    if (!field.type || field.type.toUpperCase() != 'FILE') {
      continue;
    }
    checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    if (!field.uploadOK) {
      allUploadsOK = false;
      break;
    }
  }
  if (allUploadsOK) {
    document.MM_returnValue = true;
  }
}

function checkOneFileUpload(field, extensions, requireUpload, sizeLimit, minWidth, minHeight, maxWidth, maxHeight, saveWidth, saveHeight) {
  var fileName = field.value.replace(/"/gi,'');
  field.uploadOK = false;
  if (fileName == '') {
    if (requireUpload) {
      alert('File is required!');
      field.focus();
      return;
    } else {
      field.uploadOK = true;
    }
  } else {
    if (extensions != '') {
      checkFileExtension(field, fileName, extensions);
    } else {
      field.uploadOK = true;
    }
    if (!document.layers && field.uploadOK) {  
      document.PU_uploadForm = field.form;
      re = new RegExp("\.(gif|jpg|png|bmp|jpeg)$","i");
      if(re.test(fileName) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
        checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
      }
    }
  }
  return;
}

function checkFileExtension(field, fileName, extensions) {
  var re = new RegExp("\\.(" + extensions.replace(/,/gi,"|").replace(/\s/gi,"") + ")$","i");
  var agt = navigator.userAgent.toLowerCase();
  var is_mac = (agt.indexOf("mac") != -1);
  var is_op = (agt.indexOf("opera") != -1);
  if (is_op) {
    var ext = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length);
    var extArr = extensions.split(',');
    var extCheck = false;
    for (var i = 0; i < extArr.length; i++) {
      if (extArr[i].toLowerCase() == ext.toLowerCase()) {
        extCheck = true;
        break;
      }
    }
    if (extCheck == false) {
      alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
      field.focus();
      field.uploadOK = false;
      return;
    }
  } else {
    if (!re.test(fileName)) {
      alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
      field.focus();
      field.uploadOK = false;
      return;
    }
  }
  field.uploadOK = true;
}

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) {
  var agt = navigator.userAgent.toLowerCase();
  var is_mac = (agt.indexOf("mac") != -1);
  var is_ie = document.all;
  var is_ns6 = (!document.all && document.getElementById ? true : false);
  var fileURL = field.value;
  if (is_ie && is_mac) {
    begPos = fileURL.indexOf('/',1);
    if (begPos != -1) {
      fileURL = fileURL.substring(begPos+1,fileURL.length);
    }
  }
  fileURL = 'file:///' + fileURL.replace(/:\\/gi,'|/').replace(/\\/gi,'/').replace(/:([^|])/gi,'/$1').replace(/"/gi,'').replace(/^\//,'');
  if (!field.gp_img || (field.gp_img && field.gp_img.src != fileURL) || is_ns6) {
    if (is_ie && is_mac) {
      var dummyImage;
      dummyImage = document.createElement('IMG');
      dummyImage.src = 'dummy.gif';
      dummyImage.name = 'PPP';
      field.gp_img = dummyImage;
    } else {
      field.gp_img = new Image();
    }
    with (field) {
      gp_img.field = field;
      gp_img.sizeLimit = sizeL*1024;
      gp_img.minWidth = minW;
      gp_img.minHeight = minH;
      gp_img.maxWidth = maxW;
      gp_img.maxHeight = maxH;
      gp_img.saveWidth = saveW;
      gp_img.saveHeight = saveH;
      gp_img.onload = showImageDimensions;
      gp_img.src = fileURL+'?a=123'; // +(Math.round(Math.random()*998)+1);
    }
  }
}

function showImageDimensions(fieldImg) {
  var is_ns6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !is_ns6 ? fieldImg : this);
  if (img.width > 0 && img.height > 0) {
    if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
      alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight);
      img.field.uploadOK = false;
      return;
    }
    if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
      alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight);
      img.field.uploadOK = false;
      return;
    }
    if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
      alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes');
      img.field.uploadOK = false;
      return;
    }
    if (img.saveWidth != '') {
      document.PU_uploadForm[img.saveWidth].value = img.width;
    }
    if (img.saveHeight != '') {
      document.PU_uploadForm[img.saveHeight].value = img.height;
    }
    if (document.PU_uploadForm[img.field.name+'_width']) {
      document.PU_uploadForm[img.field.name+'_width'].value = img.width;
    }
    if (document.PU_uploadForm[img.field.name+'_height']) {
      document.PU_uploadForm[img.field.name+'_height'].value = img.height;
    }
    img.field.uploadOK = true;
  }
}


