<!--
// Open a new/existing window according to the following:
//wnm = "_blank": generates unique window name
//wnm = "": opens in current window
//wnm = "WIN%": open in existing window; if doesn't exist, will close the window
function openWindow(frm, loc, wnm, feat)
{
	var win, svact;

	if (wnm == "_blank") {
		// unique window name based on number of milliseconds
		wnm = new String(new Date().getTime());
	}
	if (wnm != "") {
		if (wnm.substring(0, 3) == "WIN") feat = "left=9999";
		win = window.open("", wnm, feat);
		if (wnm.substring(0, 3) == "WIN") {
			// if opened in a new window then close it
			if (win.screenLeft >= 9999) {
				win.close();
				return 0;
			}
		}
	}
	svact = frm.action;
	frm.action = loc;
	frm.target = wnm;
	frm.submit();
	frm.action = svact;
	frm.target = "";

	return win;
}

function newImage(arg)
{
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages()
{
	var i;

	if (document.images && (preloadFlag == true)) {
		for (i = 0; i < changeImages.arguments.length; i += 2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages()
{
	if (document.images) {
		p11 = newImage("images/tab_profile_up.gif");
		p12 = newImage("images/tab_education_up.gif");
		p13 = newImage("images/tab_experience_up.gif");
		p14 = newImage("images/tab_skills_up.gif");
		p15 = newImage("images/tab_references_up.gif");
		p21 = newImage("images/tab_profile_down.gif");
		p22 = newImage("images/tab_education_down.gif");
		p23 = newImage("images/tab_experience_down.gif");
		p24 = newImage("images/tab_skills_down.gif");
		p25 = newImage("images/tab_references_down.gif");
		p31 = newImage("images/tab_profile_sel.gif");
		p32 = newImage("images/tab_education_sel.gif");
		p33 = newImage("images/tab_experience_sel.gif");
		p34 = newImage("images/tab_skills_sel.gif");
		p35 = newImage("images/tab_references_sel.gif");
		preloadFlag = true;
	}
}

function getDefaultOption(elm)
{
	var i, n, val;

	val = "";
	if (elm.length) {
		for (i = n = 0; i < elm.length; i++) {
			if (elm[i].defaultSelected) {
				n = i;
				break;
			}
		}
		val = elm[n].value
	}

	return val;
}

function getDirty(frm)
{
	var i, tp, dirty;

	for (i = 0; i < frm.elements.length; i++) {
		tp = frm.elements[i].type.toLowerCase();
		switch (tp) {
			case "text":
			case "textarea":
				if (frm.elements[i].value != frm.elements[i].defaultValue) {
					return 1;
				}
				break;
			case "select":
			case "select-one":
				if (frm.elements[i].value != getDefaultOption(frm.elements[i])) {
					return 1;
				}
				break;
		}
	}
	return 0;
}

var mdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var wkdays = "sõmïtõwåthõfòsaôaæbå\0";	//s m t w th f sa a b
var nthwds = "láfiòseãthiòfoõfifô\0";	//l fi se thi fo fif
var months = "jan\0feb\0mar\0apr\0may\0jun\0jul\0aug\0sep\0oct\0nov\0dec\0\0";
var mmm = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var bival;

function ParseDate(datevar)
{
	var wkday, nthwd, aftbef;
	var munth, dae, yere, hr, min, sec;
	var i, j, pos, t1, t2, t3;
	var match;
	var today;
	var d;
	var c;
	var datestr, tmpstr;

	wkday = new Array(-1,-1,-1);
	nthwd = new Array(-1,-1,-1);
	aftbef = new Array(-1,-1,-1);
	
	datestr = datevar+"\0";

	if (datestr.charCodeAt(0) == 0) return "";

	today = new Date();

    i = 0;
	do {
		if ((match = MatchAlpha( datestr, wkdays )) == -1) break; // find day of week, after, before

		t1 = match&0x7FFF;
		pos = match>>16;
		if (i < 3) {
		    tmpstr = datestr.substr( 0, pos )+"\0";
			if ((match = MatchAlpha( tmpstr, nthwds )) != -1) { // find last, first to fifth
				nthwd[i] = match&0x7FFF;
			} else {
				nthwd[i] = BlankInt( tmpstr ); // get int [0,32767], or -1 if none
				tmpstr = bival;
			}

			if (t1 < 7) {
				wkday[i] = t1;
			} else if (nthwd[i] != -1) {
				aftbef[i] = t1;
			} else if (i > 0) {
				i--;
				aftbef[i] = t1;
			}
		} else if (t1 > 6) {
			aftbef[2] = t1;
		}

		datestr = datestr.substr( pos );
		i++;
    } while (i < 4);

    t2 = 0; // check for month day year
    if ((match = MatchAlpha( datestr, months )) != -1) {
		t2 = 2; // check for day year
		munth = (match&0x7FFF)+1;
    }
    i = 0;
    while (true) {
		if (i >= datestr.length) break;
		if (0 <= (c = datestr.charCodeAt(i)-0x30) && c <= 9) {
			if (t2 == 0) {
				munth = c;
				t2 = 1;
			} else if (t2 == 1) {
				munth = munth*10+c;
				if (munth != 0) {
					if (munth > 12) {
						munth = Math.floor(munth/10);
						i--;
					}
					datestr = datestr.substr( 0, i+1 )+" "+datestr.substr( i+1 );
					i++;
					t2 = 2;
				}
			} else if (t2 == 2) {
				dae = c;
				t2 = 3;
			} else if (t2 == 3) {
				dae = dae * 10 + c;
				if (dae != 0) {
					if (dae > mdays[munth-1] && (munth != 2 || dae != 29)) i--;
					datestr = datestr.substr( 0, i+1 )+" "+datestr.substr( i+1 );
					break;
				}
			}
		} else {
			if (t2 == 1) t2 = 2;
			if (t2 == 3) break;
		}
		i++;
	}

    yere = today.getFullYear();
    t1 = BlankInt( datestr );
    datestr = bival;
    t2 = BlankInt( datestr );
    datestr = bival;
    if (match != -1) {
		if (t1 > 0 && t1 <= mdays[munth-1]) { // check for valid day
			if (t2 == -1) {
				if (today.getMonth()+1 > munth) yere++;
			} else {
				if (t2 > 9999) t2 = 9999;
				yere = t2 < 100 ? t2+Math.floor(yere/100)*100 : t2;
			}
		    dae = t1;
		} else if (munth == 2 && t1 == 29) { //check for leap day
			if (t2 == -1) {
				yere = ((yere+(today.getMonth()+1 > 2 ? 4 : 3))>>2)<<2;
			} else {
				if (t2 > 9996) t2 = 9996;
				yere = (((t2 < 100 ? t2+Math.floor(yere/100)*100 : t2) + 3)>>2)<<2;
			}
			if (yere%100 == 0 && yere%400 != 0) yere += 4;
			dae = t1;
		} else if (t1 != -1) {
		    if (t1 > 9999) t1 = 9999;
			yere = t1 < 100 ? t1+Math.floor(yere/100)*100 : t1;
			dae = 1;
		} else {
			if (today.getMonth()+1 > munth) yere++;
		    dae = 1;
		}
	} else if (t2 == -1) {
		if (0 < t1 && t1 <= 12) {
			munth = t1;
			dae = 1;
		} else {
			munth = today.getMonth()+1;
			dae = today.getDate();
		}
	} else {
		t3 = BlankInt( datestr );
		datestr = bival;
		if (0 < t1 && t1 <= 12) {
			munth = t1;
			if (0 < t2 && t2 <= mdays[munth-1]) {
				if (t3 == -1) {
					if (today.getMonth()+1 > munth) yere++;
				} else {
					if (t3 > 9999) t3 = 9999;
					yere = t3 < 100 ? t3+Math.floor(yere/100)*100 : t3;
				}
				dae = t2;
			} else if (munth == 2 && t2 == 29) {
				if (t3 == -1) {
					yere = ((yere+(today.getMonth()+1 > 2 ? 4 : 3))>>2)<<2;
				} else {
					if (t3 > 9996) t3 = 9996;
					yere = (((t3 < 100 ? t3+Math.floor(yere/100)*100 : t3)+3)>>2)<<2;
				}
				if (yere%100 == 0 && yere%400 != 0) yere += 4;
				dae = t2;
			} else {
				if (t2 > 9999) t2 = 9999;
				yere = t2 < 100 ? t2+Math.floor(yere/100)*100 : t2;
				dae = 1;
			}
		} else {
			if (t1 > 9999) t1 = 9999;
			yere = t1 < 100 ? t1+Math.floor(yere/100)*100 : t1;
			munth = 1;
			dae = 1;
		}
    }

	today.setFullYear(yere, munth-1, dae);
    t1 = today.getDay();

	d = 0;
	i = 2;
	do {
		pos = aftbef[i];
		if (wkday[i] != -1) {
			if (nthwd[i] == 0) { // last
				munth = today.getMonth()+1;
				dae = mdays[munth-1];
				if (munth == 2) {
					yere = today.getFullYear();
					if (yere&3 == 0 && (yere%100 != 0 || yere%400 == 0)) {
						dae = 29;
					}
				}
				today.setFullYear(yere, munth-1, dae);
				if ((t2 = wkday[i]-today.getDay()) > 0) t2 -= 7;
			} else {
				t2 = wkday[i]-t1;
				if (pos == 7) { // after
					if (t2 <= 0) t2 += 7;
					if (nthwd[i] > 1) t2 += (nthwd[i]-1)*7;
				} else if (pos == 8) { // before
					if (t2 >= 0) t2 -= 7;
					if (nthwd[i] > 1) t2 -= (nthwd[i]-1)*7;
				} else {
					if (t2 < 0) t2 += 7;
					if (nthwd[i] > 1) t2 += (nthwd[i]-1)*7;
				}
			}
			d += t2;
			t1 = wkday[i];
		} else if ((j = nthwd[i]) > 0) {
			if (pos != 7) j = -j;
			d += j;
			t1 = today.getDay();
		}
	} while (--i >= 0);

	today.setDate(dae+d);
	datestr = mmm[today.getMonth()]+" "+today.getDate()+", "+today.getFullYear();
	return datestr;
}

function BlankInt(s)
{
	var i, tot, fnd;
	var c;

	i = fnd = tot = 0;
	while (true) {
		if (0 <= (c = s.charCodeAt(i)-0x30) && c <= 9) {
			fnd--;
			tot = (tot*10+c)&0x7FFFFFFF;
			s = s.substr(0, i)+" "+s.substr(i+1);
		} else {
			if (fnd) break;
			if (c == 0-0x30) {
				tot = -1;
				break;
			}
		}
		i++;
	}
	bival = s;
	return tot;
}

function MatchAlpha(s, l)
{
	var i, j, p1, p2;
	var c1, c2, brk;

// l is assumed to be lower case alpha, null or sign terminated
	p1 = 0;
	p2 = 0;
	i = 0;
	j = 0;
	while (true) {
		if ((c1 = s.charCodeAt(i)) == 0) return -1;
		c1 |= 0x20;
		if (0x61 <= c1 && c1 <= 0x7A) {
			brk = 0;
			p1 = i;
			do {
				i = p1;
				do {
				    c1 = s.charCodeAt(i);
					i++;
					if ((c2 = l.charCodeAt(j)) == 0) {
						brk = 1;
						break;
					}
					if (0x41 <= c1 && c1 <= 0x5A) c1 |= 0x20;
					j++;
				} while (c1 == c2);
				if (brk) break;
				if (((c2 ^= 0x80)&0x80) == 0) {
					if (c1 < 0x61 || c1 > 0x7A || c1 == c2) {
						brk = 1;
						break;
					}
				}
				j--;
				do {
				    c2 = l.charCodeAt(j);
				    j++;
				} while (0 < c2 && c2 <= 0x7F);
				p2++;
			} while ((c2 = l.charCodeAt(j)) != 0);
			if (brk) break;
			i--;
			do {
			    c1 = s.charCodeAt(i)|0x20;
			    i++;
			} while (0x61 <= c1 && c1 <= 0x7A);
			p1 = i-1;
			p2 = 0;
			i = p1-1;
			j = 0;
		}
		i++;
    }
    i--;
	do {
	    c1 = s.charCodeAt(i)|0x20;
		i++;
    } while (0x61 <= c1 && c1 <= 0x7A);

	return ((i-1)<<16)+p2;
}

function strltrim()
{
    return this.replace(/^\s+/,'');
}
function strrtrim()
{
    return this.replace(/\s+$/,'');
}
function strtrim()
{
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
function strisNumeric()
{
	var re = /^(\d+)(\.?)(\d*)$/;
	return re.test(this);
}
function strisEmail()
{
	var ve = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{1,4})+$/; ///\S+@\S+\.\S+/;	// must be of form user@domain.extension (actually c@c.c)
	return ve.test(this);
}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
String.prototype.isNumeric = strisNumeric;
String.prototype.isEmail = strisEmail;
//-->
