﻿// JScript File


var datetime = "0123456789/";
var time = "0123456789:";
var telephone = "0123456789";
var myfloat = ".0123456789";
var numb = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var alpha_extended = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .-'()";
var validate_string = "";

function res(t,v)
{
    var w = "";

    if (v == time)
    if (
        (t.value.indexOf('.') > -1) ||
        (t.value.indexOf(',') > -1) ||
        (t.value.indexOf(';') > -1) ||
        (t.value.indexOf(' ') > -1)
       )
    {
        t.value = t.value.replace('.',':').replace(',',':').replace(';',':').replace(' ',':');;
    }
    
    if (v == datetime)
    if (
        (t.value.indexOf('.') > -1) ||
        (t.value.indexOf('-') > -1) ||
        (t.value.indexOf(',') > -1) ||
        (t.value.indexOf(' ') > -1)
       )
    {       
        t.value = t.value.replace('.','/').replace('-','/').replace(',','/').replace(' ','/');
    }
    
    //alert('a');

    for (i=0; i < t.value.length; i++) 
    {
        x = t.value.charAt(i);
        if (v.indexOf(x,0) != -1)
        {
//if ((v ==  myfloat) && (x == '.') && (v ==  myfloat))
            w += x;
        }
    }
    
    if (t.value != w)
    {
        t.value = w;
    }
    
    //t.value = t.value;
}



function GetSelectedValue(el){try{return document.getElementById(el).options[document.getElementById(el).selectedIndex].value;}catch(e){return ''}}
function GetSelectedValue2(el){var result=null;try{var j=0;while(j<=document.getElementById(el).length){if(document.getElementById(el).childNodes[j].selected==true)result=document.getElementById(el).childNodes[j].value;j++}}catch(e){}return result}
function SetValue(toEl,val,fromEl){try{if((val==null)&&(fromEl!=null))val=GetValue(fromEl);document.getElementById(toEl).value=val}catch(e){}}
function SetInnerHTML(el,h){try{document.getElementById(el).innerHTML=h}catch(e){}} 

function addOption(myparent,val,txt){var o=document.createElement("OPTION");if(txt!=null){var t=document.createTextNode(txt);o.appendChild(t)}if((val!=null)&&(val.length>0))o.value=val;if(myparent!=null)myparent.appendChild(o);return o}
function FindBy2(el,el2,val,id,text){try{if(el2!=null)val=document.getElementById(el2).value;var j=0;while(j<=document.getElementById(el).length){if((text!=null)&&(document.getElementById(el).childNodes[j].text==text)){document.getElementById(el).childNodes[j].selected=true;return}if((id!=null)&&(document.getElementById(el).childNodes[j].id==id)){document.getElementById(el).childNodes[j].selected=true;return}if((val!=null)&&(document.getElementById(el).childNodes[j].value==val)){document.getElementById(el).childNodes[j].selected=true;return}j++}}catch(e){}}
function FindBy(el,el2,val,id,text){try{if(el2!=null)val=document.getElementById(el2).value;var j=1;while(j<=document.getElementById(el).length*2){
//alert(document.getElementById(el).childNodes[j].value+' '+val+' '+( document.getElementById(el).childNodes[j].value==val  ));
if((text!=null)&&(document.getElementById(el).childNodes[j].text==text)){document.getElementById(el).childNodes[j].selected=true;return}if((id!=null)&&(document.getElementById(el).childNodes[j].id==id)){document.getElementById(el).childNodes[j].selected=true;return}if((val!=null)&&(document.getElementById(el).childNodes[j].value==val)){document.getElementById(el).childNodes[j].selected=true;return}j=j+2}}catch(e){}}

function setStyle(object, styleText) { if (object.style.setAttribute) { object.style.setAttribute("cssText", styleText,0); } else { object.setAttribute("style", styleText); } }
function addGenericButton(myparent,type,id,val,style,classname,onclick,onblur,onfocus,maxlength,onkeyup,tabindex){var b=document.createElement("input");var prefix='';switch(type){case "file":b.type="file";prefix="fil";break;case "password":b.type="password";prefix="pwd";break;case "reset":b.type="reset";prefix="rst";break;case "submit":b.type="submit";prefix="sbt";break;case "hidden":b.type="hidden";prefix="hdn";break;case "radio":b.type="radio";prefix="rad";break;case "checkbox":b.type="checkbox";prefix="chk";break;case "text": b.type = "text"; prefix = "txt";  break; default:b.type="button";prefix="btn"}  if((id!=null)&&(id.length>0)){b.setAttribute("id",id);b.name=id}   if(classname!=null)b.setAttribute("className",classname);  if(val!=null) if(((val==true)||(val==false) || (val=='true')||(val=='false'))&&((type=="radio")||(type=="checkbox"))){b.defaultChecked=val}else if(val.length>0)b.value=val;       if(onclick!=null)b.onclick=new Function(onclick);if(onblur!=null)b.onblur=new Function(onblur);if(onfocus!=null)b.onfocus=new Function(onfocus);if(onkeyup!=null)b.onkeyup=new Function(onkeyup);    setStyle(b, style); b.maxLength=maxlength;b.tabIndex=tabindex; if(myparent!=null)myparent.appendChild(b);return b}

function addTextBox(myparent, val, style, classname, id, onclick, onblur, onfocus, maxlength, onkeyup, tabindex) {  return addGenericButton(myparent, "text", id, val, style, classname, onclick, onblur, onfocus, maxlength, onkeyup, tabindex) }
function addSelect(myparent, id, size_int, style, classname, multiple, onchange, onfocus, tabindex) { var s = document.createElement("SELECT"); if (id != null) { s.id = id; s.name = id; } if (classname != null) s.setAttribute("className", classname); if (size_int != null) s.size = size_int; if (multiple != null) s.multiple = multiple; if (onchange != null) s.onchange = new Function(onchange); if (style != null) setStyle(s, style); if (onfocus != null) s.onfocus = new Function(onfocus); s.tabIndex = tabindex; if (myparent != null) myparent.appendChild(s); return s }
function addSelect(myparent,id,size_int,style,classname,multiple,onchange){var s=document.createElement("SELECT");if(id!=null)s.id=id;if(classname!=null)s.setAttribute("className",classname);if(size_int!=null)s.size=size_int;if(multiple!=null)s.multiple=multiple;if(onchange!=null)s.onchange=new Function(onchange);if(style!=null) setStyle(s,style);if(myparent!=null)myparent.appendChild(s);return s}

function GetChecked(el) {
	try {
		return (document.getElementById(el)) ? document.getElementById(el).checked : null;
	} catch (e) {
		return '';
	}
}

function HiddenFixed(el, hidden) {

    if (document.getElementById(el).style.setAttribute == undefined) {
        try {
            if ((hidden == true) || (hidden == null)) {
                document.getElementById(el).style.visibility = "hidden"; //.setAttribute("style", "visibitily:hidden;");
            }
            else {
                document.getElementById(el).style.visibility = "visible"; //.setAttribute("style", "visibitily:visible;");
            }
        }
        catch (e) { }
    }
    else if ((document.getElementById(el).style.setAttribute != null)) // && (document.getElementById(el).style.setAttribute.toString() != '')) 
    {
        try {
            if ((hidden == true) || (hidden == null)) {
                document.getElementById(el).style.setAttribute('visibility', "hidden", 0)
            }
            else {
                document.getElementById(el).style.setAttribute('visibility', "visible", 0)
            }
        }
        catch (e) { }
    }
}
function GetValue(el) {
	try {
		return (document.getElementById(el)) ? document.getElementById(el).value + '' : '';
	}
	catch (e) {
		return ''
	}
}

function GetSelectedText(el) {
	try {
		return document.getElementById(el).options[document.getElementById(el).selectedIndex].text;
	}
	catch (e) {
		return ''
	}
}

function GetSelectedValue(el) {
	try {
		return document.getElementById(el).options[document.getElementById(el).selectedIndex].value;
	}
	catch (e) {
		return ''
	}
}

function GetSelectedValue2(el) {
	var result = null;
	try {
		var j = 0, node= null, nodes = document.getElementById(el).childNodes;
		while (j < nodes.length) {
			if (nodes[j].selected == true) result = nodes[j].value;
			j++;
		}
	}
	catch (e) {
		return result;
	}
	return result;
}


function IsValidDate(DateVal1)
{ 
    DateVal1= DateVal1.replace('.','/').replace('.','/')
    var Day,Mn,Yr;
    var CurrentDate = new Date(Date());
    if (DateVal1.indexOf('/')==-1)
    {   //no slashes - short format
        Day = DateVal1.substring(0,2)
        Mn = DateVal1.substring(2,4)
        Yr = DateVal1.substring(4,DateVal1.length)
        //alert('2'+Day+Mn+Yr)
    }
    else
    {   //long format
        Day = DateVal1.substring(0,2)
        Mn = DateVal1.substring(3,5)
        Yr = DateVal1.substring(6,DateVal1.length)
        //alert('2'+Day+Mn+Yr) 
    }
 
//SetInnerHTML('validate',DateVal1);
//document.write(Day+Mn+Yr);
            
//CurrentDate.getFullYear();
//potential 2k bug?
            
    if (Yr.length < 3) 
    {
        if (parseInt(Yr)>60)
            Yr='19'+Yr;
        else
        {
        if (parseInt(Yr)<=60)
            Yr='20'+Yr;
        }   
    }
            
    var DateVal = Mn + "/" + Day + "/" + Yr; 
    
    //alert(Mn + "/" + Day + "/" + Yr);
    
    var dt = new Date(DateVal);
    
    if(dt.getDate()!=Day)
    {
        //alert('Invalid Date'+dt.getDate().toString()+' '+Day);
        return(false);
    }
        
    if(dt.getMonth()+1!=Mn) //this is for the purpose JavaScript starts the month from 0
    {
        //alert('Invalid Date'+(dt.getMonth()+1).toString()+' '+Mn);
        return(false);
    }
    
    //allow max 100 years each way to be the valid date
    if(dt.getFullYear()!=Yr||parseInt(dt.getFullYear())>parseInt(CurrentDate.getFullYear()+100)||parseInt(dt.getFullYear())<parseInt(CurrentDate.getFullYear()-100))
    {
        //alert('Invalid Date' + dt.getFullYear().toString()+' '+Yr);
        return(false);
    }
    
    return(Day+"/"+Mn+"/"+Yr);
    
    //return(true);
}

function SetValidator(id,onflag) {
	var elm = $get(id);
	if (elm) {
		if (onflag) {
			$addClass(elm, 'invalid');
		}
		else {
			$removeClass(elm, 'invalid');
		}
	}
}


/***********************************************
* Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

/*
Here's an explanation of the 4 parameters of showLocalTime():

ContainerID (string): The ID of the DIV or span that will house the local time. 
Servermode (string): Valid values are either "server-php", "server-asp", or "server-ssi", to indicate this page as either of type, PHP, ASP, or SSI. 
LocaltimeoffsetMinutes (integer): The offset in minutes of the local time you wish to display, from the server time. For example, if your server time is currently 9:30 AM and you know the desired local time is 11:30AM, the offset is 120, or 2 hours then. 
Display Format (string): valid values are either "short" or "long". The latter will cause the local date to be displayed along with the time. 
For the "servermode" parameter, it must be set to either "server-php", "server-asp", or "server-ssi", depending on whether your page is php, asp, or ssi enabled, respectively. This script will NOT work on 100% static pages, such as plain .html.

*/

var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]

function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
var servertimestring=(servermode=="server-asp")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= DateTime.Now.ToString() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}