browser = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )));

var arFunction = new Array
var arAll=new Array('','-- all --'), arSelect=new Array('','-- select --')
var da=document.all

/*
function getCookie(sName)
{
    var aCookie = document.cookie.split(";");
    for (var i=0; i < aCookie.length; i++)
    {
      var aCrumb = aCookie[i].split("=");
      if (sName == aCrumb[0]) 
        return unescape(aCrumb[1]);
    }
  return null;
}
*/

function getCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

// Create a cookie with the specified name and value.
//setCookie(this.checked,'nautica.user.clip','<%=rs("uid")%>')
function setChkBoxCookie(val, sName, sValue)
{
/*  var Hr=60*60*1000
  var expDate = new Date()
  expDate.setTime (expDate.getTime() + 0.5*Hr)
*/
	var oriCookie = getCookie(sName)

	if (val) { // Add ChkBox Item
		if(oriCookie == null || oriCookie=='undefined') 
			{setCookie(sName,","+sValue+",",null,"/")}
		else
			{setCookie(sName,oriCookie+sValue+",",null,"/")}
		}
	else
		{ // Remove ChkBox Item
			var pos = oriCookie.indexOf("," + sValue + ",")
			if (pos>=0){
			    if (pos < oriCookie.length) {
					sValue= oriCookie.substring(0,pos) + oriCookie.substring(pos+sValue.length+1,oriCookie.length) 
					}
				if (sValue==",") sValue = ""
			}
			setCookie(sName,sValue,null,"/")
		}
// alert(getCookie(sName))
//  document.cookie = sName + "=" + escape(sValue) + "; expires="+expDate.toGMTString();
//  document.cookie = sName + "=" + escape(sValue) + ";
}

function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

// In check box
function chkEnableCookie(obj,msg){
	if((ie && !navigator.cookieEnabled) || (ns && document.cookie=='')){
		if (msg) alert(msg)
			else alert('Please enable "Cookies" support in your browser.\n\rNOTE: We do NOT save any cookies on your computer, all cookies will be cleared once you close your browser.');
		obj.checked = false;
	}
}

function setClip(name,chkName){
//		alert(getCookie(name))
		var ckClipVal=getCookie(name);
		var arClip = new Array()
		if (!(ckClipVal==null || ckClipVal=='undefined')) { arClip = eval("new Array("+ckClipVal.substring(1,ckClipVal.length-1)+")"); }

		for (var i=0; i< arClip.length; i++)
			if (eval(chkName+arClip[i]))
				eval(chkName+arClip[i]+'.checked = true');
	}

function showMultiItem(str,ar){
	var tmpStr = ""
	if (str != "" && str !="||"){
		var arTmp = str.split("|")

		for (var i=1;i<arTmp.length-1;i++){
			if (tmpStr != "") tmpStr = tmpStr + ", "
				for (var j=0;j<ar.length;j=j+2)
				{
					if (arTmp[i] == ar[j]){
					tmpStr = tmpStr + ar[j+1];break;
					}
				}
		}
	}
	document.write(tmpStr)
}

function cNavBtn(curPage,pageCount,mOutImage,mOverImage,mDownImage,btnClass,width,frm,page){
	this.curPage = curPage
	this.pageCount = pageCount
	this.mOutImage = mOutImage
	this.mOverImage = mOverImage
	this.mDownImage = mDownImage
	this.btnClass = btnClass
	this.width = width
	this.frm = frm
	this.page = page

	this.firstBtn=function(str){
		document.writeln('<input type=submit value="'+ (str==null?"    |<    ":str) + '" name="btnFirst" width='+ this.width + (this.btnClass==null?"":" class="+this.btnClass) + (this.curPage==1?" disabled":"")  + ' onclick="document.'+this.frm+'.'+this.page+'.value=1" onMouseOut="chgbg(this,\''+this.mOutImage+'\')" onMouseOver="chgbg(this,\''+this.mOverImage+'\')" onMouseDown="chgbg(this,\''+this.mDownImage+'\')">')
	}
						
	this.prevBtn=function(str){
		document.writeln('<input type=submit value="'+ (str==null?"    <    ":str) + '" name="btnPrev" width='+ this.width + (this.btnClass==null?"":" class="+this.btnClass) + (this.curPage==1?" disabled":"")  + ' onclick="document.'+this.frm+'.'+this.page+'.value=eval(document.'+this.frm+'.'+this.page+'.value)-1<=1?1:eval(document.'+this.frm+'.'+this.page+'.value)-1" onMouseOut="chgbg(this,\''+this.mOutImage+'\')" onMouseOver="chgbg(this,\''+this.mOverImage+'\')" onMouseDown="chgbg(this,\''+this.mDownImage+'\')">')
	}
				
	this.nextBtn=function(str){
		document.writeln('<input type=submit value="'+ (str==null?"    >    ":str) + '" name="btnNext" width='+ this.width + (this.btnClass==null?"":" class="+this.btnClass) + (this.curPage>=this.pageCount?" disabled":"")  + ' onclick="document.'+this.frm+'.'+this.page+'.value=eval(document.'+this.frm+'.'+this.page+'.value)+1>='+this.pageCount+'?'+this.pageCount+':eval(document.'+this.frm+'.'+this.page+'.value)+1" onMouseOut="chgbg(this,\''+this.mOutImage+'\')" onMouseOver="chgbg(this,\''+this.mOverImage+'\')" onMouseDown="chgbg(this,\''+this.mDownImage+'\')">')
	}
			
	this.lastBtn=function(str){
		document.writeln('<input type=submit value="'+ (str==null?"    >|    ":str) + '" name="btnLast" width='+ this.width + (this.btnClass==null?"":" class="+this.btnClass) + (this.curPage>=this.pageCount?" disabled":"")  + ' onclick="document.'+this.frm+'.'+this.page+'.value=' + this.pageCount +'" onMouseOut="chgbg(this,\''+this.mOutImage+'\')" onMouseOver="chgbg(this,\''+this.mOverImage+'\')" onMouseDown="chgbg(this,\''+this.mDownImage+'\')">')
		// alert(str)
	}
						
}

function loadRun()
{for(var i=0;i<arFunction.length;i++)eval(arFunction[i])}

function loadAdd(str)
{arFunction[arFunction.length]=str}

//change button background
function chgbg(obj,bg){
	obj.style.background='url("'+bg+'")';
}

function btnMouseOver() {
	with(event.srcElement.style)
	switch(event.srcElement.className){
		case "btn70":backgroundImage="url('image/btn70b.gif')";break;
		case "btn100":backgroundImage="url('image/btn100b.gif')";break;

	}
}

function btnMouseOut() {
	with(event.srcElement.style)
	switch(event.srcElement.className){
		case "btn70":backgroundImage="url('image/btn70.gif')";break;
		case "btn100":backgroundImage="url('image/btn100.gif')";break;

	}
}

function mouseOver(imgDocID,imgObjName) {
	//   imgDocID - the name or number of the document image to be replaced
	//   imgObjName - the name of the image object to be swapped in
	if (browser) {
	        document.images[imgDocID].src = "images/" + imgObjName
		}		
}	

function mouseOut(imgDocID,imgObjName) {
	//   imgDocID - the name or number of the document image to be replaced
	//   imgObjName - the name of the image object to be swapped in
	if (browser) {
	        document.images[imgDocID].src = eval(imgObjName+".src")
		}		
}	

function findTag(htmlElement,tagName){
	var checked = false 
	if (htmlElement) {
		while (htmlElement.tagName != tagName &&  htmlElement.tagName != "HTML") {
			htmlElement = htmlElement.parentElement
		}

		if (htmlElement.tagName == tagName ) {
			checked = true
		}
	}
	
	if (checked){
		return htmlElement}
	else{
		return false
	}
}

function lstCheck(lstObj,optCount,val){

	for(var i=0;i<optCount;i++){
		if (lstObj.options[i].value == val){
			lstObj.options[i].selected = true
			return true
			break;
		}
	}
	return false
}


function nullToEmpty(str){
	if (str==null)
		{return ""}
	else
		{return str}
}

function lstBox(lstName,ar,val,style){
	document.open()
	document.writeln("<select name=" + lstName + (style==""?"":" " +style) + ">")
	for(var i=0;i<ar.length;i+=2)
		document.writeln("<option value='"+ar[i] + "'" + (ar[i]==val?" selected":"") + ">" + ar[i+1] + "</option>")
		document.writeln("</select>")
		document.close()
					
}


function radioBtn(radName,ar,val,defIndex,frm){
	var chk = false
	// alert("name:" +radName)
	// alert("val:" +val)
	// alert("def:" +def)
	document.open()
	for(var i=0;i<ar.length;i+=2)
	{
		// alert(ar[i]==val)	
		// alert(nullToEmpty(val))
		// alert(ar[i]==def)
		// alert(nullToEmpty(val)=="" && ar[i]==def)
		document.writeln("<input type=radio name='"+radName+"' value='"+ar[i] + "'" + (ar[i]==val?" checked":"") + "> " + ar[i+1])
		if (ar[i]==val && !chk) chk = true
	}
	if (!chk && nullToEmpty(defIndex)!="") {
		//alert("*")
		//alert(frm+"."+radName+"["+defIndex+"].checked")
		//alert(eval(frm+"."+radName+"["+defIndex+"].checked"))
		eval(frm+"."+radName+"["+defIndex+"]").checked = true
	  // for(var i=0; i<o.length; i++) o[i].checked = s.indexOf(o[i].value)>=0

	}
	document.close()
}

function showVal(ar,val){
	for(var i=0;i<ar.length;i+=2)
		if (val==ar[i])	{document.write(ar[i+1])}
}

function getElement(str,i,separator)
{
	var ar=str.split(separator);
	var tmp = ar.length>i ? ar[i] : ''
	return(tmp)
}

function chkDate(str,type){ // t=dmy|mdy|ymd
	var tmpDate, y, m, d
	var separator = (type=='ansi'?'.':'/')
	
	switch(type){
		case 'dmy':
			d=parseInt(getElement(str,0,separator),10);
			m=parseInt(getElement(str,1,separator),10)-1;
			y=parseInt(getElement(str,2,separator),10); 
			break;
		case 'mdy': 
			d=parseInt(getElement(str,1,separator),10);
			m=parseInt(getElement(str,0,separator),10)-1;
			y=parseInt(getElement(str,2,separator),10); 
			break;
		case 'ymd': 
			d=parseInt(getElement(str,2,separator),10);
			m=parseInt(getElement(str,1,separator),10)-1;
			y=parseInt(getElement(str,0,separator),10); 
			break;
		case 'ansi': 
			d=parseInt(getElement(str,2,separator),10);
			m=parseInt(getElement(str,1,separator),10)-1;
			y=parseInt(getElement(str,0,separator),10); 
			break;
	}

	tmpDate=new Date(y, m, d ); 

	return((str.replace(/([^\/])/g,'')=='//' || str.replace(/([^\.])/g,'')=='..') &&
		y==tmpDate.getFullYear() && m==tmpDate.getMonth() && d==tmpDate.getDate())
}


function chkEmail(str)
{
  var c1,c2,c3,c4,err="";
  if(str.length != 0)
  {
	var i1=0
	var i2=0
	
	if (str.indexOf(";") >= 0 || str.indexOf(",") >= 0 )
	{
		return false
	}

	for(i=1;i<str.length;i++)
	{ 
	  c1=str.substr(i,1);
	  if(c1 == "@") i1=i1+1;
	}
		
	for(i=3;i<str.length;i++)
	{ 
	  c2=str.substr(i,1);
	  if(c2 == ".") i2=i2+1;
	}
		
	c1=str.substr(0,1);
	c2=str.substr(str.length-1,1);
		
//	if (i1!=1 | i2<1 | i2>3 | c1=="@" | c2=="@" | c1=="."| c2==".")
	if (i1!=1 | i2<1 | c1=="@" | c2=="@" | c1=="."| c2==".")
	{ 
		//alert(c2+'/'+c3+'/'+i1+'/'+i2);
		return false}
	  }
  // else
  // { alert("Email must be entered");;return false }
	  
  return true;
}

function cValidate(frm,ar){
	this.frm = frm
	this.ar = ar	
	this.errorTxt = ""
	
  this.field=function(i){
	// alert(eval('document.'+this.frm+'.'+this.ar[i]+".value"))
	 return eval('document.'+this.frm+'.'+this.ar[i]+".value");
  }

  this.chkEmpty = function(i){
	return(!this.ar[i+5] && this.field(i+1)=="")
  }		

  this.addErrTxt = function(i){
	this.errorTxt=this.errorTxt + this.ar[i+4] + "\n"
  }		

  this.validate=function(){
		  this.errorTxt = ""
		for(var i=0;i<=this.ar.length-1; i=i+6){
		switch(this.ar[i]){
			case('txt'):
				if (this.chkEmpty(i))
					{ this.addErrTxt(i) }					
				else if (this.field(i+1)!="" && (this.field(i+1).length<this.ar[i+2] || this.field(i+1).length>this.ar[i+3]) )
					{ this.addErrTxt(i) }	
				break
			case('int'):
				if (this.chkEmpty(i))
					{ this.addErrTxt(i) }					
				else if (this.field(i+1)!="" && (this.field(i+1).search(/([^\/0-9])/) == 0 || parseInt(this.field(i+1),10) < this.ar[i+2] || parseInt(this.field(i+1),10) > this.ar[i+3] ))
					{ this.addErrTxt(i) }					
				//
				break
			case('date'):
				if (this.chkEmpty(i))
					{ this.addErrTxt(i)	}					
				else if (this.field(i+1)!="" && (!chkDate(this.field(i+1),this.ar[i+2])))
					{ this.addErrTxt(i)	}					
				break
			case('email'):
				if (this.chkEmpty(i))
					{ this.addErrTxt(i)	}					
				else if (this.field(i+1)!="" && (!chkEmail(this.field(i+1))))
					{ this.addErrTxt(i)	}					
				break
		}
		}

		if (this.errorTxt !="")
		{
			alert(this.errorTxt)
			return false	
		}
		else
		{return true}
	}
}