// OPEN NEW WINDOW (centered)
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function OpenWindow(mypage, myname) {		
win = window.open(mypage, myname, '')
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// CLEAR LOGIN
function ClearLogin(ID,I_NAME) {
	if (confirm("Are you sure you want to clear your login (username & password) information ?")) {
		window.location.replace("reminder.asp?smode=clear");
	}
}

// VALIDATE ISSUE
function ValidStepOne(){
	if (document.frm.title.value=="") {
		alert("Please enter a descriptive title for the question you would like to submit.")
		document.frm.title.focus()
	return false }
}

// NEW NOTE INFORMATION FORM VALIDATION
function ValidateNewNoteInformation()
{    	
	if (document.frm.add_info.value=="") 
	{        	
		alert("Please enter new note information.")
		document.frm.add_info.focus()
		return false
	}
	else
	{
		return ValidateAttachmentInformation()
	}
}

// NEW ATTACHMENT VALIDATION
function ValidateAttachmentInformation()
{
	
	if (document.frm.Att_SourceFile.value!="" && document.frm.Att_Title.value == "") 
	{
	alert("Please enter the attachment title.")
	document.frm.att_title.focus()
		return false 
	}
 }


// CLEAR BOOKMARKS
function ClearBooks() {
	if (confirm("Clear all bookmarks ?")) {
		window.location.replace("bookmarks.asp?clear=true");
	}
}
// CLOSE ISSUE
function CloseIssue(ID) {
	if (confirm("Would you like to close this issue ?")) {
		window.location.replace("update.asp?ID=" + ID + "&closed=True");
	}
}    
// VALIDATE STATUS
function ValidateStatus(){
	if (document.frm.id.value=="") {
		alert("Please enter issue ID (number) to track.")
		document.frm.id.focus()
	return false }
}    
// ADD BOOKMARK
function AddBookmark(ID, CATE) {
	if (confirm("Add this article to your bookmarks ?")) {
		window.location.replace("bookmark_add.asp?ID=" + ID + "&CATE=" + CATE);
	}
}
// REMINDER FORM VALIDATION
function ValidateREMINDER(){
	if (document.frm.email.value=="") {
		alert("Please enter your email address.")
		document.frm.email.focus()
	return false }
}
// SEND EMAIL FORM VALIDATION \\
function ValidateSENDEMAIL(){
	if (document.frm.y_name.value=="") {
		alert("Please enter your name.")
		document.frm.y_name.focus()
	return false }
	if (document.frm.y_email.value=="") {
		alert("Please enter your email address.")
		document.frm.y_email.focus()
	return false }
	if (document.frm.f_name.value=="") {
		alert("Please enter friend's name.")
		document.frm.f_name.focus()
	return false }
	if (document.frm.f_email.value=="") {
		alert("Please enter friend's email address.")
		document.frm.f_email.focus()
	return false }
}
// SEARCH FORM VALIDATION \\
function ValidateSEARCH(){
	if (document.frm.search.value=="") {
		alert("Please enter a phrase to search for.")
		document.frm.search.focus()
	return false }
}
// MY QUESTIONS LOGIN FORM VALIDATION \\
function ValidateMYQUESTIONS(){
	if (document.frm.username.value=="") {
		alert("Please enter your username.")
		document.frm.username.focus()
	return false }
	if (document.frm.password.value=="") {
		alert("Please enter your password.")
		document.frm.password.focus()
	return false }
}
// SUBMIT ISSUE FORM VALIDATION \\
function ValidateNEWISSUE(){
	if (document.frm.name.value=="") {
		alert("Please enter your name.")
		document.frm.name.focus()
	return false }
	if (document.frm.email.value=="") {
		alert("Please enter your email address.")
		document.frm.email.focus()
	return false }
	if (document.frm.title.value=="") {
		alert("Please enter questions title.")
		document.frm.title.focus()
	return false }        
	if (document.frm.cate.value==0) {
	alert("Please choose a Category.")
	document.frm.title.focus()
	return false }
	if (document.frm.question.value=="") {
		alert("Please enter your question.")
		document.frm.question.focus()
	return false }
	return ValidateAttachmentInformation()        
}
// OPEN SIDE WIDNOW PANEL
function MDM_openWindow(theURL,winName,features) { 
  window.resizeTo(screen.width-280,screen.height-26)
  window.moveTo(0,0);
  var _W=window.open(theURL,winName,features);
  _W.focus();
  _W.resizeTo(280,screen.height-26)
  _W.moveTo(screen.width-280,0); 	  
  _W.opener.name = "opener";
}
// ASK BEFORE LAUNCHING
function ASK_MDM_openWindow(theURL,winName,features) { 
	if (confirm("Launch Browser Toolbar Window ? \n\nA new window will be opened next to this one featuring \neasily accessible help desk issues and search utility.")) {
	  window.resizeTo(screen.width-280,screen.height-26)
	  window.moveTo(0,0);
	  var _W=window.open(theURL,winName,features);
	  _W.focus();
	  _W.resizeTo(280,screen.height-26)
	  _W.moveTo(screen.width-280,0); 	  
	  _W.opener.name = "opener";
	}
}      
// VALIDATE COMMENT FORM
function ValidComment(){
	if (document.frm.comment.value=="") {
		alert("Please enter your comment.")
		document.frm.comment.focus()
	return false }
}
// DROP DOWN NAVIG    
function Jump(fe){
	var opt_key = fe.selectedIndex;
	var uri_val = fe.options[opt_key].value;
	window.open(uri_val,'_top');
	return true;
}
function trimWhiteSpace(stringToTrim)
{
	var returnValue = stringToTrim;
	if (stringToTrim != null)
	{
		returnValue = stringToTrim.replace(/^\s*|\s*$/g, "");
	}
	return returnValue;
}
function isEmptyString(stringToCheck, trimFirst)
{	
	var returnValue = true;
	if (stringToCheck != null)
	{
		var afterTrim = stringToCheck;
		if (trimFirst)
		{
			afterTrim = trimWhiteSpace(afterTrim);
		}
		returnValue = afterTrim.length == 0;
	}
	return returnValue;
}
function getSafeWindowName(windowName)
{
	var returnValue = windowName;
	if (!isEmptyString(windowName, false))
	{
		returnValue = returnValue.replace(/-/g, ''); 
	}
	return returnValue;
}
function openWindowAS(newWindowURL, newWindowName, newWindowFeatures, childArray, parentName)
{	
	var safeWindowName = getSafeWindowName(newWindowName);	
	var newWindow = window.open(newWindowURL, safeWindowName, newWindowFeatures);		
	newWindow.focus();
}

var defaultDialogOptions = 'fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,channelmode=no,directories=no';
function openIssue(issueId, categoryId)
{
	var windowOptions = 'fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,channelmode=no,directories=no,width=600,height=460'
	var windowUrl = 'issue_view.asp?ID=' + issueId;
	if (categoryId && categoryId != "")
	{
		windowUrl += '&CATE=' + categoryId;
	}
	openWindowAS(windowUrl, 'issueview' + issueId + categoryId, windowOptions, null, null);
	return document.MM_returnValue;
}

