function openCenter(surl,sname,iwidth,iheight,sscrollbars){
  	var iwide = (screen.availWidth-iwidth)/2;
  	var itall = (screen.availHeight-iheight)/2;
    var bvalue = window.open(surl, sname, "screenX=" + iwide.toString() + ",screenY=" + itall.toString() + ",height=" + iheight.toString() + ",innerHeight=" + iheight.toString() + ",width=" + iwidth.toString() + ",innerWidth=" + iwidth.toString() + ",menubar=no,toolbar=no,location=no,status=no,scrollbars=" + sscrollbars.toString() + ",resizable=no");
  	//bvalue.moveTo(iwide,itall);
	bvalue.focus();
}
function uploadFile() {
	openCenter('sys_document_upload.asp','upload','605','275','no')
}
//This function is numbers, decimal point or dollar sign
function txtOnlyNumbers_onKeydown()
{
	//alert(window.event.keyCode);
	
	switch (window.event.keyCode) {
	case 8: case 9: case 48: case 49: case 50: case 51: case 52: 
	case 53: case 54: case 55: case 56: case 57: case 96: case 97:
	case 98:case 99:case 100: case 101: case 102: case 103: case 104:
 	case 105: case 37: case 39: case 36: case 35: case 190: case 110:
	case 46:
		break;
	default:
		window.event.keyCode = 0;
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return false;
	}
}
function IsValidEmail(txtEmail)
{
	var bFieldOk

	bFieldOk = IfNotEmpty(txtEmail, "e-mail address");
	if (!bFieldOk) return bFieldOk;
	
	var semail = txtEmail.value;
	if ((semail.indexOf("@") <= 0) || (semail.indexOf(".") <= 0)) {
		alert("Please enter a valid email address. (e.g. myname@somewhere.com)");
		txtEmail.focus();
		txtEmail.select();
		return false;
	}
	return true;
}

function IfNotEmpty(txtControlToCheck, sControlDescription) {

	if (txtControlToCheck.value == "") {
		alert("Please enter the " + sControlDescription + " before continuing.");
		txtControlToCheck.focus();
		//If its blank whats the point of selecting it plus it will now work with SELECT controls too
		//txtControlToCheck.select();
		return false;
	}
	
	return true;
}

function IfInvalidFileExtension(txtControlToCheck, sValidExtensions) {
	var sFilename = txtControlToCheck.value;
	var sExtension;
	
	sExtension = sFilename.substr(sFilename.lastIndexOf(".")+1)
	if (sValidExtensions.indexOf(sExtension) >=0) {
		return true;
	}
	else {
		return false;
	}
}

function setImage(txtImageFileName, imgImage, sImageURL) {
	txtImageFileName.value=sImageURL;
	imgImage.width = 50;
	imgImage.height = 50;
	imgImage.border = 1;
	imgImage.src = sImageURL;
	ImageText.innerHTML = "Click here to change the image";
	ZoomImageLink.href = "javascript:openCenter('zoom_image.asp?image=" + sImageURL + "','zoomimage','500','500','yes')";
}
function disableButton(cmdButtonToDisable) { 
	if (document.all || document.getElementById) { 
		cmdButtonToDisable.disabled = true; 
		//setTimeout('alert("Your form has been submitted.  Notice how the submit and reset buttons were disabled upon submission.")', 2000); 
		return true; 
	} 
	else { 
		//alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission."); 
		return false; 
	} 
} 
function buildQueryString(theFormName) {
  theForm = document.forms[theFormName];
  var qs = ''
  for (e=0;e<theForm.elements.length;e++) {
    if (theForm.elements[e].name!='') {
      qs+=(qs=='')?'?':'&'
			//Check for a checkbox
			if (theForm.elements[e].type == "checkbox" ) {
				if (theForm.elements[e].checked) {
		      qs+=theForm.elements[e].name+'=1';
				} else {
		      qs+=theForm.elements[e].name+'=';
				}
      } else {
	      qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
			}
    }
	}
  return qs
}

//This function will open the URL passed in into a new hidden IFrame on the page
//This is useful for getting around access denied issues when setting the content type and content disposition
//to download data like in a CSV file.
// See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306673 
// http://www.oreillynet.com/pub/a/javascript/2002/02/08/iframe.html
// for more info
function openURLInIFrame(URL) {
	var IFrameObj; // our IFrame object
  if (!document.createElement) {return true};

  var IFrameDoc;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
    var tempIFrame=document.createElement('iframe');
    tempIFrame.setAttribute('id','RSIFrame');
    tempIFrame.style.border='0px';
    tempIFrame.style.width='0px';
    tempIFrame.style.height='0px';
    IFrameObj = document.body.appendChild(tempIFrame);
  
    if (document.frames) {
      // this is for IE5 Mac, because it will only
      // allow access to the document object
      // of the IFrame if we access it through
      // the document.frames array
      IFrameObj = document.frames['RSIFrame'];
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 
    && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}
function openApplication() {
	openCenter('http://ic.natinstore.com/ICApplication/application/ApplicantInfoKO.aspx','application',600,600,'yes');
}
