// Java script source


//***** show confirmation message and redirect to another web page
function confirmRedirect(title,mess,icon,defbut,mods,yesURL,noURL) {
   if (document.all) {
      icon = (icon==0) ? 0 : 2;
      defbut = (defbut==0) ? 0 : 1;
      retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal = (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }

   if (retVal) {
		if (yesURL != '') {window.location = '' + yesURL + '';}
   }
   else {
		if (noURL != '') {window.location = '' + noURL + '';}
   }

   return retVal;
}


//***** trap the Enter key, works under IE ******************************
function captureEnterKey(btn){
	if (document.all){
		if (event.keyCode == 13) {
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
}


//***** trap the Enter key and numeric value, works under IE ******************
function captureEnterKeyAndNumeric(btn){
	captureEnterKey(btn);
	acceptDigit();
}


//***** trap the Enter key, numeric value and slashes, works under IE ************
function captureEnterKeyAndDigitAndSlash(btn){
	captureEnterKey(btn);
	acceptDigitAndSlash();
}


//***** get keyCode *****************************************************
function getKeyCode() {
	// Check For Browser Type
	if (document.all) {
		return event.keyCode;
	}
	else {
		return event.which;
	}
}


//***** accept only digit ************************************************
function acceptDigit(){
	var keyCode = getKeyCode();
    var shift = (event.shiftKey) ? true : false;
    
	if (keyCode == 33 || keyCode == 34 || keyCode == 35 || keyCode == 36) {
		// 33=PageUp  34=PageDown  35=End  36=Home  
		return true;
	}
			    			    
    if (event.ctrlKey) {
		// 33=ctrlPageUp  34=ctrlPageDown  65=ctrl-a  67=ctrl-c  86=ctrl-v  88=ctrl-x
		if (keyCode == 33 || keyCode == 34 || keyCode == 65 || keyCode == 67 || keyCode == 86 || keyCode == 88) 
			return true;
    }
	
	// enter, backspace, tab, insert and delete keys are allowed thru
	if ((keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 45 ||keyCode == 46 ||
			keyCode == 37 || keyCode == 39 || (keyCode>47 && keyCode<58) ||	 
			(keyCode>95 && keyCode<106)) && !shift) {									
       return true;
	}
	else {
	//alert(keyCode + '  keycode is ' + String.fromCharCode(keyCode) );
       event.returnValue=false;
       event.cancel = true;
       return false;
	}
}


//***** accept only digit and /  *****************************************
function acceptDigitAndSlash() {
	var keyCode = getKeyCode();	

	//if (String.fromCharCode(keyCode)=='/') {	// not work under .net
	if (keyCode == 111 || keyCode == 191) {
		return true;
	}
	else {
		return acceptDigit();
	}
}


//***** accept only digit and .   *****************************************
function acceptDigitAndDot() {
	var keyCode = getKeyCode();	

	//if (String.fromCharCode(keyCode) == '.') {	// not work under .net
	if (keyCode == 110 || keyCode == 190) {	
		return true;
	}
	else {
		return acceptDigit();
	}
}


//***** trim leading spaces   ******************************************
function leftTrim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  return s;
}


//***** trim trailing spaces   ********************************************
function rightTrim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  return s;
}


//***** trim leading and trailing spaces   **********************************
function trim(s) {
  var temp = leftTrim(s);
  temp = rightTrim(temp);
  return temp;
}


//***** enable btn when txtFld length >= minLen  ******************************
function enableBtnForTxtFld(txtFld,btn,minLen) {
 if (document.all) {
     event.returnValue=false;
     myStr=leftTrim(txtFld.value);
     if (myStr.length >= minLen)  {
		btn.disabled=false;
	 } else {
		btn.disabled=true;
	 }
 } else {
	btn.disabled=false;
 }
}


//***** hide or show an object   ******************************************
function hideShow(show, obj) {
    if (!document.getElementById) return;
    if (show) {
        document.getElementById('confirmDiv').style.display = ''; //'block'
      //  document.all[obj].style.display = ''; //'block'
    } else {
    //document.all[obj].style.display = 'none';
    document.getElementById('confirmDiv').style.display = 'none';
    }
}


//***** hide or show email input fields   ******************************************
function showEmail(show) {
    if (!document.getElementById) return;
    if (show) {
//        var ct = document.getElementById('proof-email1Box');
//        if (ct) ct.style.display = '';
        //$get('proof-email1Box').style.display = '';
        document.all['proof-email1Box'].style.display = ''; //'block'
        document.all['proof-email2Box'].style.display = ''; //'block'
        document.all['proof-email3Box'].style.display = ''; //'block'
    } else {
//        var ct = document.getElementById('proof-email1Box');
//        if (ct) ct.style.display = 'none';
    //$get('proof-email1Box').style.display = 'none';
        document.all['proof-email1Box'].style.display = 'none';
        document.all['proof-email2Box'].style.display = 'none';
        document.all['proof-email3Box'].style.display = 'none';
    }
}


//***** hide or show company input fields   ******************************************
function showCompany(show) {
    if (!document.getElementById) return;
    if (show) {
        //$get('mailing_address_line1IdBox').style.display = '';
        document.all['mailing_address_line1IdBox'].style.display = '';
        document.all['mailing_address_line2IdBox'].style.display = '';
        document.all['cityIdBox'].style.display = '';
        document.all['stateIdBox'].style.display = '';
        document.all['zipIdBox'].style.display = '';
        
        document.all['mailing_address_line1IdBox2'].style.display = '';
        document.all['mailing_address_line2IdBox2'].style.display = '';
        document.all['cityIdBox2'].style.display = '';
        document.all['stateIdBox2'].style.display = '';
        document.all['zipIdBox2'].style.display = '';
        
        document.all['mailing_address_line1IdBox3'].style.display = '';
        document.all['mailing_address_line2IdBox3'].style.display = '';
        document.all['cityIdBox3'].style.display = '';
        document.all['stateIdBox3'].style.display = '';
        document.all['zipIdBox3'].style.display = '';
    } else {
    //$get('mailing_address_line1IdBox').style.display = 'none';
        document.all['mailing_address_line1IdBox'].style.display = 'none';
        document.all['mailing_address_line2IdBox'].style.display = 'none';
        document.all['cityIdBox'].style.display = 'none';
        document.all['stateIdBox'].style.display = 'none';
        document.all['zipIdBox'].style.display = 'none';
        
        document.all['mailing_address_line1IdBox2'].style.display = 'none';
        document.all['mailing_address_line2IdBox2'].style.display = 'none';
        document.all['cityIdBox2'].style.display = 'none';
        document.all['stateIdBox2'].style.display = 'none';
        document.all['zipIdBox2'].style.display = 'none';
        
        document.all['mailing_address_line1IdBox3'].style.display = 'none';
        document.all['mailing_address_line2IdBox3'].style.display = 'none';
        document.all['cityIdBox3'].style.display = 'none';
        document.all['stateIdBox3'].style.display = 'none';
        document.all['zipIdBox3'].style.display = 'none';
    }
}


//***** hide or show key code details ******************************************
function showKeyCodeDetails(show) {
    if (!document.getElementById) return;
    if (show) {
        document.all['if_keycode_changes'].style.display = ''; //'block'
    } else {
        document.all['if_keycode_changes'].style.display = 'none';
    }
}


//***** show keyCode   ******************************************
function showKeyCode() {
	var keyCode = getKeyCode();
	alert(keyCode + '  keycode is ' + String.fromCharCode(keyCode) );
	return true;
}


//***** for web page timeout   ******************************************
function redirectFunction(){ 
	window.location.href="CloseWebPage.aspx" 
}


//***** limit the length of an object   ***************************************
function limitLength(obj, length) {
	var keyCode = getKeyCode();
	var maxlength = length - 1;
	
	if (keyCode == 33 || keyCode == 34 || keyCode == 35 || keyCode == 36) {
		// 33=PageUp  34=PageDown  35=End  36=Home  
		return true;
	}
			    			    
    if (event.ctrlKey) {
		// 33=ctrlPageUp  34=ctrlPageDown  65=ctrl-a  67=ctrl-c  86=ctrl-v  88=ctrl-x
		if (keyCode == 33 || keyCode == 34 || keyCode == 65 || keyCode == 67 ||  keyCode == 88) 
			return true;
    }    
	
	// enter, backspace, tab, insert and delete keys are allowed thru
	if (keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 45 ||keyCode == 46 ||
			keyCode == 37 || keyCode == 39)  {									
       return true;
	}
			    			    	    	
	if (obj.value.length > maxlength) {
       event.returnValue=false;
       event.cancel = true;
       return false;	
	}
}


//***** split question mark   ***************************************
function splitQMark(inputString) {
	var inStr = inputString + '?';
	return inStr.split("?")[0];
}


//***** set client timestamp   ***************************************
function setClientTime(obj) {
    var now = new Date();

    var dd = now.getDate();
    var mm = now.getMonth() + 1; //January is 0!
    var yyyy = now.getFullYear();
    if (dd < 10) { dd = '0' + dd }
    if (mm < 10) { mm = '0' + mm }

    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds()
    var milSec = now.getUTCMilliseconds()
    var newhours = hours
    if (hours > 12) { newhours = hours - 12 }
    if (newhours < 10) { newhours = '0' + newhours }
    var timeValue = "" + newhours
    if (timeValue == "0") timeValue = 12;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue += ":" + milSec;
    timeValue += (hours >= 12) ? " PM" : " AM"

    var timeStamp = mm + '/' + dd + '/' + yyyy + ' ' + timeValue

    var ct = document.getElementById(obj);
    if (ct) ct.value = timeStamp;
}


//***** set client timestamp   ***************************************
function setClientTimestamp() {
    var now = new Date();

    var dd = now.getDate();
    var mm = now.getMonth() + 1; //January is 0!
    var yyyy = now.getFullYear();
    if (dd < 10) { dd = '0' + dd }
    if (mm < 10) { mm = '0' + mm }

    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds()
    var milSec = now.getUTCMilliseconds()
    var newhours = hours
    if (hours > 12) { newhours = hours - 12 }
    if (newhours < 10) { newhours = '0' + newhours }
    var timeValue = "" + newhours
    if (timeValue == "0") timeValue = 12;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue += ":" + milSec;
    timeValue += (hours >= 12) ? " PM" : " AM"

    var timeStamp = mm + '/' + dd + '/' + yyyy + ' ' + timeValue

    var ct = document.getElementById('client-timestampId');
    if (ct) ct.value = timeStamp;
}


//***** open confirmation window   ***************************************
function openConfirmWindow(doneLoc,rtnLoc) {
    var myArg = new Object();
    var returnValue = window.showModalDialog("confirm.htm", myArg, "dialogWidth:400px; dialogHeight:300px; center:yes; status:no; scroll:no; edge:sunken; ");
    if (returnValue == 'redirect') {
        window.location = doneLoc;
    }
    /*if (returnValue == '2Form') {
        window.location = rtnLoc;
    }*/
}


//***** open calendar   ***************************************
function calendarPicker(strField) {
    window.open('DatePicker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}

//***** open calendar   ***************************************
function openCalendar(strField) {
    window.open('PopCal.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}


//***** client file upload completion   ***************************************
function uploadComplete(sender, args) {
    /*???  var contentType = args.get_contentType();
    var text = args.get_length() + " bytes";
    if (contentType.length > 0) {
    text += ", '" + contentType + "'";
    }
    $get('txtSelectedFile').innerText = "selected";
    $get('txtSelected').innerText = "File selected";*/
    var fs = document.getElementById('FileSelectInfo');
    if (fs) fs.style.display = 'none';
    var ct = document.getElementById('Buttons');
    if (ct) ct.style.display = '';
}



function showFileSelectInfo() {
    var fs = document.getElementById('FileSelectInfo');
    if (fs) fs.style.display = '';
}


function ShowPopup() {
    $get('UpdatePanel1_ModalPopupExtender').show();
}

function HidePopup() {
    $get('UpdatePanel1_ModalPopupExtender').hide();
}


function hideButtons() {
    //if (!document.getElementById) return;
    //document.all['Buttons'].style.display = 'none';
    var ct = document.getElementById('Buttons');
    if (ct) ct.style.display = 'none';
    //$get('Buttons').style.display = 'none';
}





