﻿// JScript File

function jsCreateElement(el)
{ 
    this.obj =document.createElement(el); 
    return this.obj;
} 

function jsCreateAttribute(obj,att,val)
{ 
    obj.setAttribute(att,val); 
    return;
}  

function CheckKeyCode()
{
  if( (event.keyCode==110 || event.keyCode == 189 || event.keyCode == 109) ||
      (event.keyCode >= 48 && event.keyCode <= 57) || 
      (event.keyCode >= 96 && event.keyCode <= 105) ) {
    return true; }
  else {
    return false;
  }
}

function forceNumber(e, type) {
    
	//type = 1: real number, type = 2: interger number

	var unicode=e.charCode? e.charCode : e.keyCode
	if(type==1 && unicode!=9)
    {
        if (unicode!=8 && unicode!=46 && unicode.keyCode!=37 && unicode.keyCode!=39)
        { //if the key isn't the backspace key (which we should allow)
                if (unicode<48||unicode>57) //if not a number
                return false //disable key press
         }
    }
	if(type==2 && unicode!=9)
    {
        if (unicode!=8  && unicode.keyCode!=37 && unicode.keyCode!=39)
        { //if the key isn't the backspace key (which we should allow)
                if (unicode<48||unicode>57) //if not a number
                return false //disable key press
         }
    }
}

function openWindow(filename, winname, width, height, feature) {
	var features, top, left;
	var reOpera = /opera/i ;
	var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));
	
	left = (window.screen.width - width) / 2;
	top = (window.screen.height - height) / 2;	
	if(feature == '')
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
	else
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
	//if(!winnameRequired)	winname = "";
	void(window.open(filename,winname,features));
}

function ToDate()
{
    var Today = new Date();
    var day = Today.getDate();
    var month = Today.getMonth();
    var year = Today.getYear();
    strday = day
    strmonth = month + 1
    if (year < 2000)
    var year = year + 1900;
    if (day < 10)
    var strday = '0' + day
    if (strmonth < 10)
    var strmonth = '0' + strmonth
    var strDate=strday+"/"+strmonth+"/"+year;
    return strDate;
}

function isEmailAddr(email) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789@~";
	var theStr = new String(email)
	var index = theStr.indexOf("@");

	for (var a=0; a<pattern.length; a++) {
		if (pattern.indexOf(email.charAt(a),0) == -1) return false;
	}
	if (theStr.indexOf(" ",0) != -1) return false;
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) return true;
	}
	return false;
}

function convertDate(date)
{
    
    var day=date.substring(0,2);
    var month=date.substring(3,5);
    var year=date.substring(6,10);
    return new Date(month+'/'+day+'/'+year);
}

function convertDateToString(date)
{
    var day = date.getDate();
    var month = date.getMonth()+1;
    month=(month<10)?('0'+month):month;
    var year = date.getFullYear();
    var strDate=day+"/"+month+"/"+year;
    return strDate;
}
