
/*
 Ask for confirmation if delete icon (for any entity) is pressed
 Example: deleteEntity("user", "User Name", "gcc.UserDel?ID=123")
*/
function doDelete (entityType, entityName, servletName) {
	if (confirm("Are you sure you want to delete the " +
	entityType + ": " + entityName + "?")) {
			window.location.href = servletName;
	}
}

/*
 Checks text length typed into the input field and allowed characters.
 Example: onKeyUp="checkInputField (this, 10, '[^a-z,A-Z]')"
 For last parameter, RegularExpression check JavaScript document at:
 http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm
*/
function checkInputField(inputField, maxSize, pattern) {

	taValue = inputField.value;
	if(taValue.length > maxSize) {
		alert("Maximum size for the field exceeded!");
		inputField.value = taValue.substring(0, maxSize);
		taValue = inputField.value;
	}

	if(pattern != '') {
		regExp = new RegExp (pattern);

		if(regExp.test(inputField.value))
			alert("Character not allowed for the field!");

		while(regExp.test(inputField.value))
			inputField.value = inputField.value.replace(regExp, "");

	}
}

/*
 Cancel action and return to the pervious page.
 You need to pass history object as parameter.
*/
function doCancel(pageHistory) {
    if (pageHistory.length > 0){
		pageHistory.back();
	}
}

/*
 Submit form with properties from page.
 You need to pass form object as parameter.
*/
function doSubmit(propertiesForm) {
    propertiesForm.submit();
}

/*
 Submit form with properties from page.
 You need to pass form object as parameter,
 parent window and alert message to be displayed
 after submit
*/
function doAlertSubmit(propertiesForm, parentWindow, alertMessage) {
    propertiesForm.submit();
	parentWindow.alert(alertMessage);
}

function doUpdate(entityType, entityName, propertiesForm) {
//	if (confirm("Are you sure you want to update " + entityType + ": " + entityName + "?")) {
		propertiesForm.submit();
//	}
}

function checkPhone(inputField, minSize) {
    taValue = inputField.value;
    if(taValue.length>0 && taValue.length < minSize) {
        return false;
   }
   return true;
}

function check_email(e) {
    if (!e.length > 0)  {
        return (true);
    }
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){
            return (false);
        }
    }
    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);
        }
    }
    
}
function bookmark(url,title){
	
	  var ua=navigator.userAgent.toLowerCase();
	  var isKonq=(ua.indexOf('konqueror')!=-1);
	  var isSafari=(ua.indexOf('webkit')!=-1);
	  var isMac=(ua.indexOf('mac')!=-1);

	  if(isKonq) {
	      alert('You need to press CTRL + B to bookmark our site.');
	  } else if(isSafari){
		  alert("You need to press Command + D to bookmark our site");
	  } else  if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,""); 
	  } else if( window.external ) { // IE Favorite
			    window.external.AddFavorite( url, title);
	  } else if(window.opera && window.print) { // Opera Hotlist
	        var elem = document.createElement('a');
	        elem.setAttribute('href',url);
	        elem.setAttribute('title',title);
	        elem.setAttribute('rel','sidebar');
	        elem.click();
	  }
}

