﻿// judy


var shiftkeydown=false 
var wkeydown=false 
var controlkeydown=false 
var returnkeydown=false 
var bkeydown=false 
var editflag=false
vcloggedin=false
var FCKStyle=""

var dopoll

var mousedown=false

var formarama_page=""

var hasheader=false
var havetable=false

if ((document.location+" ").indexOf("alpha/formarama")!==-1) {formarama_host="http:/alpha/formarama"}
if ((document.location+" ").indexOf("sony/formarama")!==-1) {formarama_host="http:/sony/formarama"}
if ((document.location+" ").indexOf("vinacarta.com")!==-1)   {formarama_host="http://www.vinacarta.com"}
if ((document.location+" ").indexOf("formarama.com")!==-1)   {formarama_host="http://www.formarama.com"}


document.onkeydown = storeVal; 
document.onkeyup   = clearVal; 

var to_handle // time-out handle for smooth scrolling

var logwindow

	//logwin=window.open("about:blank","","fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=yes,width="+600+",height="+600+"")
    //logwin.document.body.innerHTML="hello world"

//=====================================================================================================
//function gebi(anid) {logwin.document.body.innerHTML=logwin.document.body.innerHTML+anid+"<br>";return document.getElementById(anid)}
function gebi(anid) {return document.getElementById(anid)}

//=====================================================================================================
function storeVal(evt){ 
	(evt) ? thekey=evt.keyCode : thekey=event.keyCode;
	if (thekey==87) {wkeydown=true}
	if (thekey==16) {shiftkeydown=true}
	if (thekey==16) {shiftkeydown=true}
	if (thekey==17) {controlkeydown=true}
	if (thekey==13) {returnkeydown=true}
	if (thekey==66) {bkeydown=true}
}

//=====================================================================================================
function clearVal(evt){ 
	(evt) ? thekey=evt.keyCode : thekey=event.keyCode;
	if (thekey==16) {shiftkeydown=false}
	if (thekey==87) {wkeydown=false}
	if (thekey==17) {controlkeydown=false}
	if (thekey==13) {returnkeydown=false}
	if (thekey==66) {bkeydown=false}
	
}

//=====================================================================================================
function BrowserDetectLite() {

	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	this.versionMinor = parseFloat(navigator.appVersion); 
	if (this.isNS && this.isGecko) {this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );}
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	this.versionMajor = parseInt(this.versionMinor); 

	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isNS7up = (this.isNS && this.versionMajor >= 7);
}


var browser = new BrowserDetectLite();




//=====================================================================================================
function cb(subscriber_id,massmail) {
	if (!massmail) {
		for (var i=0, l=document.option_form.length;i<l;i++) {
			if (document.option_form[i].name!=="regid_"+subscriber_id) {
				document.option_form[i].checked=false
			}
		}
	}
}

//=====================================================================================================
function setaction(thepage,subaction) {
		extra=""
		
		if (editflag) {
		    if (!confirm("There are unsaved changes.\nAreyou sure you want to leave this page?")) {
			     return
		    } 
		}
        editflag=false  
		
		if ((thepage.indexOf(".asp")!==-1) || (thepage.indexOf(".htm")!==-1)) {
		
			currentloc=document.location+" "
			ipos=currentloc.indexOf("gq=")
			if (ipos!==-1) {
				extra=currentloc.substring(ipos,500)
			}
				// current location has extra querystring for google ads
				

			thislocation=document.location+" "

			if (thepage.indexOf("mapexample1.asp")!==-1) {extra="airport locations runway"}
			if (thepage.indexOf("mapexample2.asp")!==-1) {extra="meteor craters meteors meteorites"}
			
			(thepage.indexOf("?")!==-1) ?	window.parent.location=thepage+"&"+extra : 	window.parent.location=thepage
			return
		}

		// come here only for main() 
		if (document.option_form) {
			if (document.option_form.thepage) {document.option_form.thepage.value=thepage }
			if (document.option_form.subaction) { document.option_form.subaction.value=subaction }
		}
		if (getobject("whiteout")) {
			getobject("whiteout").style.visibility="hidden"
			getobject("loading").style.display="inline"
		}
		document.option_form.submit()
	}
	


//=====================================================================================================
function breakout(thelink) {
	window.parent.parent.parent.location=thelink
}

//=====================================================================================================
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
		
	return curleft;
}

//=====================================================================================================
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//=====================================================================================================
function setpage(n) {
	if (document.option_form.current_rec) {
		document.option_form.current_rec.value=""
	}
	if (document.option_form.pageno) {
		document.option_form.pageno.value=n
	}
	setaction("submissions","")
}

//=====================================================================================================
function LTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        j++;
        s = s.substring(j, i);
   }
   return s;
}

//=====================================================================================================
function RTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        i--;
        s = s.substring(0, i+1);
   }
   return s;
}

//=====================================================================================================
function Trim(str) {return RTrim(LTrim(str));}


// ======================================================================	
function getobject(aname) {
	if (document.all) {
		return document.all(aname)
	}
	else {
		return gebi(aname)
	}
}	

//========================================================================
function make_light(acolor,allowdark) {

	rs=acolor.substring(1,3)
	r=parseInt(rs,16)
	gs=acolor.substring(3,5)
	g=parseInt(gs,16)
	bs=acolor.substring(5)
	b=parseInt(bs,16)
	
	if (allowdark) {
		((r+g+b)<383 ) ? increment=30 : increment=-30
	}
	else {
		increment=15
	}
	
	r=r+increment
	g=g+increment
	b=b+increment
	if (r>255) {r=255}
	if (g>255) {g=255}
	if (b>255) {b=255}
	
	if (r<0) {r=0}
	if (g<0) {g=0}
	if (b<0) {b=0}
	
	rs=r.toString(16)
	gs=g.toString(16)
	bs=b.toString(16)
	if (rs.length<2) rs="0"+rs
	if (gs.length<2) gs="0"+gs
	if (bs.length<2) bs="0"+bs
	
	return "#"+rs+gs+bs
}

//=====================================================================================================
function get_hex(c) {

	if (document.all) {return c}
	c=c.substring(4)
	
	c=c.substring(0,c.length-1)
	r=parseInt(c.split(/\,/)[0])
	g=parseInt(c.split(/\,/)[1])
	b=parseInt(c.split(/\,/)[2])
	rs=r.toString(16)
	gs=g.toString(16)
	bs=b.toString(16)
	if (rs.length<2) rs="0"+rs
	if (gs.length<2) gs="0"+gs
	if (bs.length<2) bs="0"+bs
	
	return("#"+rs+gs+bs)
}

var hooversave

//=====================================================================================================
function hooverin(anobject) {
    hooversave=anobject.style.backgroundColor
    hoovernew=make_light(get_hex(hooversave),true)
    anobject.style.backgroundColor=hoovernew

}

//=====================================================================================================
function hooverout(anobject) {anobject.style.backgroundColor=hooversave}

// ======================================================================
function lost_it() {
	document.option_form.mailaction.value=''
	if (document.option_form.semail.value=="") {
		alert("Please fill in your email address, so we can send your password to this address")
		return
	}	
	if (!test_email(document.option_form.semail.value)) {
		alert("This is not a valid email address.")
		return
	}
	
	setaction('lost_it','')
}

// ======================================================================
function mailit() {

    //var oEditor = FCKeditorAPI.GetInstance("themail")
    //oEditor.UpdateLinkedField()

	if (document.option_form.returnaddress) {
		if (!test_email(document.option_form.returnaddress.value)) {
			alert("Please check the address in the 'From' Field")
			return
		}
	}

	if (Trim(document.option_form.subject.value)=='') {
		alert("you cannot leave the subject line blank.")
		return
	}
	if (Trim(gebi("themail").value)=='') {
		alert("you cannot leave the message body blank.")
		return
	}

	setaction('mail','mail_send')
}
	
// ======================================================================
function check_selected(apage,anaction) {
	
		// checks if a checkbox is checked for 'edit selected' and 'delete selected' and 'clone
		
		nchecked=0
		for (var i=0, l=document.option_form.length;i<l;i++) {
			if (document.option_form[i].checked) {
				nchecked=nchecked+1
			}
		}
		if (nchecked==0){
			alert("Please select an entry first")
			document.option_form.subaction.value=""
		}
		else {
		    
		    if (anaction==='clone_selected') {
		        if (nchecked>1) {alert("Please select a single record to clone");return}
		        var answer = confirm("You are about to clone a record.\nAre you sure you want to tho this?")
                if (!answer) {return}
				setaction(apage,anaction)
		    } 
		    else {
		    
			    if (nchecked==1) {
				    var answer = confirm("You are about to delete a record.\nAre you sure you want to tho this?")
			    }
			    else {
				    var answer = confirm("You are about to delete "+nchecked+" records.\nAre you sure you want to tho this?")
			    }
			    if (answer) {
				    setaction(apage,anaction)
			    }	
			    else {
				    return		
			    }
			}
		}
	}


// ======================================================================
function check_mailcbs() {
	
	// checks if a checkbox is checked for 'edit selected' and 'delete selected'
	
	nchecked=0
	for (var i=0, l=document.option_form.length;i<l;i++) {
		if (document.option_form[i].checked) {
			nchecked=nchecked+1
		}
	}
	if (nchecked==0){
		alert("Please select recipients first")
		document.option_form.subaction.value=""
	}
	else {
		setaction("mail","")
	}
}

// ======================================================================
function setorder(item) {
	document.option_form.order1.value=item ;

	if (document.option_form.sort_direction.value == "desc") {
		document.option_form.sort_direction.value="asc";
	}
	else {
		document.option_form.sort_direction.value="desc";
	}
	if (document.option_form.pageno) {
		document.option_form.pageno.value="1"
	}
	setaction("submissions","")	
}

// ======================================================================
function reset_filters() {

	for (var i=0, l=document.option_form.length;i<l;i++) {
		thename=document.option_form[i].name
		if (thename.substring(0,6)=="filter") {
   			document.option_form[i].value=""
   		}
	} 
   		
	if (document.option_form.pageno) {
		document.option_form.pageno.value="1"
	}
	if (document.option_form.search) {
		document.option_form.search.value=""		
	}
	locnew=document.location+" "
	locnew=replace(locnew,"search=","void=")
	document.option_form.action=locnew
	setaction("submissions","")
}



// ======================================================================
function search() {
	if (getobject("search").value!=="") {
		document.option_form.pageno.value='1'
		document.option_form.current_rec.value=''
		setaction("submissions","")
		
	}
}

// ======================================================================
function set_current(subscriber_id,openinfowindow,zoom,mt,anindex,endindex) {
	getobject("current_rec").value=subscriber_id
}




// ======================================================================	
function getscrollwidth(anid) {
	if (document.all) {
	
		return parseInt(getobject(anid).clientWidth)
	}
	else {
		return parseInt(getobject(anid).offsetWidth)
	}
}

// ======================================================================	
function getscrollheight(anid) {

	if (document.all) {
		return parseInt(getobject(anid).clientHeight)
	}
	else {
	    //if (!getobject(anid)){alert(anid)}
		return parseInt(getobject(anid).offsetHeight)
	}
}



// ======================================================================	
function pop_help(theobject, bak,header,msg) {

    if (getobject("help_box")) {
    
        //msg=msg+" "+findPosY(theobject)
	    var content ="<TABLE width=100 BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR="+bak+" style='border-collapse: collapse'>"
	    if (header!=="") {content=content+"<tr><td  style='font-family:Verdana;font-size:10px'><b>"+header+"</b></font></td></tr>"}
	    content=content+"<tr><td  style='font-family:Verdana;font-size:10px'>"+msg+"</font></td></tr>"
    	
	    content=content+"</table>"

	    thepop=getobject("help_box")
	    thepop.innerHTML = content;

	    //try to stay within 200 - 1200 x and 100 - 800 y

	    thex=findPosX(theobject)
	    they=findPosY(theobject)
	    getobject("help_box").style.display = "inline";  
    	
	    h=getobjectscrollheight(thepop)
	    they=they-h-10
        if (they<0) {
            they=10
            thex=thex-getobjectscrollwidth(thepop)-20            
        }
        else {
	        thex=thex+30
	       }
       if (they+h>getWindowSize("h")) {
        they=getWindowSize("h")-h
       }

   	    if (document.all) {
		    place_object(getobject("help_box"),thex,they)
	    }
	    else {
		    place_object(getobject("help_box"),thex,they)  // in netscape the iframe obscures pop up
	    }		

	    getobject("help_box").style.zindex=300000
    }

}


// ======================================================================	
function kill_help() {
    if (getobject("help_box")) {
	    getobject("help_box").style.display = "none";
    }
}

// ======================================================================	
function place_object(object,x,y) {
	
	setleft(object,x)
	settop(object,y)
}



// ======================================================================
function replace(string,text,by) {
	// Replaces text with by in string
	    var strLength = string.length, txtLength = text.length;
	    if ((strLength == 0) || (txtLength == 0)) return string;

	    var i = string.indexOf(text);
	    if ((!i) && (text != string.substring(0,txtLength))) return string;
	    if (i == -1) return string;

	    var newstr = string.substring(0,i) + by;

	    if (i+txtLength < strLength)
	        newstr += replace(string.substring(i+txtLength,strLength),text,by);

	    return newstr;
	}	
	
// ======================================================================
function test_error(anaction) {
    

        
		// CON_DD_REQUIRED_LEN_MINI_MAXI_TBTYPE
		err=false	
		errmes=""

		for (var i=0, l=document.option_form.length;i<l;i++) {

			theobject=document.option_form[i]
			theid=theobject.id
				thelist=theid.split(/\_/)


                if ((theid.indexOf("__Config")===-1) && (theid.indexOf("_style")===-1))  {
				if (thelist[0]=="CON") {
				
					type=thelist[1]

					// ----------------------------------------------------------------------------------------
					// Drop Down
					// ----------------------------------------------------------------------------------------
					
					if (type=="DD") {
						if (thelist[2]=="REQUIRED" ) {
					        selCount=0
					        for (var j=0; j<theobject.length; j++) {
                                if (theobject[j].selected) {
                                    selCount++
                                    avalue=theobject[j].value
                                }
                            }
							if ((selCount==0) || (avalue=="")) {errmes="This is a required field" }
                            
						}
					}
					

					
					// ----------------------------------------------------------------------------------------
					// Country Selector
					// ----------------------------------------------------------------------------------------
					
					if (type=="CS") {
						if (thelist[2]=="REQUIRED" ) {
					
							if (theobject.selectedIndex==0) {
								errmes="This is a required field" 
							}
						}
					}
					
				
					// ----------------------------------------------------------------------------------------
					// Radio button
					// ----------------------------------------------------------------------------------------
				
					if (type=="OB") {
						if (thelist[2]=="REQUIRED" ) {
					
							checked=false
							for (var j=0, k=eval("document.option_form."+theid+".length");j<k;j++) {
								if (eval("document.option_form."+theid)[j].checked) {checked=true}
							}
							if (checked==false) {
								errmes="This is a required field" 
							}
						}
					}
					
					// ----------------------------------------------------------------------------------------
					// Checkbox
					// ----------------------------------------------------------------------------------------
					
					
					if (type=="CB") {
						if (thelist[2]=="REQUIRED" ) {
					
							if (!theobject.checked) {
								errmes="This is a required field" 
							}
						}
					}
					
					// ----------------------------------------------------------------------------------------
					// (Rich) Textarea or alphanumeric text box
					// ----------------------------------------------------------------------------------------
					if ((type=="TR") && (typeof(FCKeditorAPI)!=='undefined')) { // Rich text area
				        var oEditor = FCKeditorAPI.GetInstance(theobject.id)
				        if (oEditor.EditorDocument) {
                            thisdoc=oEditor.EditorDocument
                            oEditor.UpdateLinkedField()
                        }
                        else {
                        
                            //errmes="please switch back to html first"
                            
                            
                            //anode=document.createElement("text")
                            //anode
                            
                            
                            
                            
                        }
                        
                        
                        // here we need to remove the div which wraps the html
                        
                        //pageno=gebi("css2_"+theid).value
                        
                        //if (gebi(theid).value.indexOf('<div id="'+pageno+'">')!==-1) {
                        
                         //   newval=replace(gebi(theid).value,'<div id="'+pageno+'">','')
                         //   newval=newval.substring(0,newval.length-6)
                         //   gebi(theid).value=newval
                         //   alert(newval)
                        //}
                        
                        
                        
					}
					if ((type=="TA") | (type=="TR") | (type=="TB" & thelist[6]=="A") | (type=="TB" & thelist[6]=="F") | (type=="TB" & thelist[6]=="I")) {
						thelen=Trim(theobject.value).length
						if ((thelen>1000) & (type=="TA")) {
							errmes="Maximum is 1000 characters" 
						}
						
						if (thelen>100 & type=="TB") {
							errmes="Maximum is 100 characters" 
						}
							
						if (thelist[2]=="REQUIRED" ) {
							if (thelen==0) { 
								errmes="This is a required field" 
							}
							mini=parseInt(thelist[4],10)
							maxi=parseInt(thelist[5],10)
							if (!(mini==-9999)) { 
								if (thelen<mini) {
									errmes="Minimum amount of characters is " + mini
								}
							}
							if (!(maxi==-9999)) { 
								if (thelen>maxi) {
									errmes="Maximum amount of characters is " + maxi
								}
							}
						}
					}
					
					// ----------------------------------------------------------------------------------------
					// Numeric text box
					// ----------------------------------------------------------------------------------------
					if (type=="TB" && ((thelist[6]=="N") ))  {
						thelen=Trim(theobject.value).length
						if (thelen>0 && isNaN(theobject.value) ) {				
							errmes="Please enter a numeric value"
						}
						else {
						
							if (thelen>100) {
								errmes="Maximum is 100 characters" 
							}

							if (thelist[2]=="REQUIRED" ) {
								if (thelen==0) { 
									errmes="This is a required field" 
								}
							}
							mini=parseFloat(thelist[4])
							maxi=parseFloat(thelist[5])
							if (!(mini==-9999)) { 
								if (parseFloat(theobject.value)<mini) {
									errmes="Minimum is " + mini
								}
							}
							if (!(maxi==-9999)) { 
								if (parseFloat(theobject.value)>maxi) {
									errmes="Maximum is " + maxi
								}
							}
							
						}
					}
					
					// ----------------------------------------------------------------------------------------
					// Email text box
					// ----------------------------------------------------------------------------------------
					
					
					if (type=="TB" & thelist[6]=="E") {
						thelen=Trim(theobject.value).length
						
						if (thelen>100) {
							errmes="Maximum is 100 characters" 
						}

						if (thelist[2]=="REQUIRED" ) {
							if (thelen==0) { 
								errmes="This is a required field" 
							}
						}

						if (thelen>0 && !test_email(theobject.value)) {
							errmes="Please provide a valid email address"
						}
					}				
					
					// ----------------------------------------------------------------------------------------
					// Link text box
					// ----------------------------------------------------------------------------------------
					
					
					if (type=="TB" & thelist[6]=="L") {
						thelen=Trim(theobject.value).length
						
						if (thelen>100) {
							errmes="Maximum is 100 characters" 
						}

						if (thelist[2]=="REQUIRED" ) {
							if (thelen==0) { 
								errmes="This is a required field" 
							}
						}
						
					}							
					
					// ----------------------------------------------------------------------------------------
					// Date text box
					// ----------------------------------------------------------------------------------------
					
					
					if (type=="TB" & thelist[6]=="D") {
						thelen=Trim(theobject.value).length
						
						if (thelen>100) {
							errmes="Maximum is 100 characters" 
						}

						if (thelist[2]=="REQUIRED" ) {
							if (thelen==0) { 
								errmes="This is a required field" 
							}
						}
						
						if (thelen>0) {
						date_format=thelist[7]
						thedate=Trim(theobject.value)
						theobject.value=thedate
						thedate=replace(thedate," ","-")
						thedate=replace(thedate,"/","-")
						theobject.value=thedate					
						datelist=thedate.split(/\-/)
						mstring="JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|"
						if (date_format==1) {
							theformat="dd-mm-yyyy"					
							day=datelist[0]
							month=datelist[1]
							if (isNaN(parseInt(month,10))) {errmes="Please enter a date in the format " + theformat}
							year=datelist[2]
						}
						if (date_format==2) {
							theformat="mm-dd-yyyy"					
							day=datelist[1]
							month=datelist[0]
							if (isNaN(parseInt(month,10))) {errmes="Please enter a date in the format " + theformat}						
							year=datelist[2]
						}
						if (date_format==3) {
							theformat="yyyy-mm-dd"					
							day=datelist[2]
							month=datelist[1]
							if (isNaN(parseInt(month,10))) {errmes="Please enter a date in the format " + theformat}						
							year=datelist[0]
						}
						if (date_format==4) {
							theformat="dd mmm yyyy"					
							day=datelist[0]
							month=datelist[1].substring(0,3).toUpperCase()
							month.substring(0,1).toUpperCase()
							if (mstring.indexOf(month)==-1) {errmes="Please enter a date in the format " + theformat}
							year=datelist[2]
							
						}
						if (date_format==5) {
							theformat="mmm dd yyyy"					
							day=datelist[1]
							month=datelist[0].substring(0,3).toUpperCase()
							if (mstring.indexOf(month)==-1) {errmes="Please enter a date in the format " + theformat}
							year=datelist[2]	
						}
						
						date_error="Please enter a date in the format " + theformat
						if (isNaN(parseInt(day,10))) {errmes=date_error}
						if (isNaN(parseInt(year,10))) {errmes=date_error}
						
						if ((parseInt(day,10)<1) | (parseInt(day,10)>31)) {errmes=date_error}
						if ((parseInt(year,10)<1000) | (parseInt(year,10)>2050)) {errmes=date_error}
						
						//theobject.value=thedate
						}	
					}							
															
				}
				if (errmes!=="") {
					setrowcolor(thelist[3],"FF0000",'#ffffff',false)
					scrollto("stable","TR_"+thelist[3])
                    document.location.hash="#"
                    alert(errmes)
					return
				}
				
				
			}
			
		}
		
		
		for (var i=0, l=document.option_form.length;i<l;i++) {

			theobject=document.option_form[i]
			theid=theobject.id
			
				thelist=theid.split(/\_/)


                if (theid.indexOf("__Config")===-1) {
				    if (thelist[0]=="CON") {
    				
					    type=thelist[1]

					    // ----------------------------------------------------------------------------------------
					    // Drop Down
					    // ----------------------------------------------------------------------------------------
    					
					    if (type=="TR") {
					    
					        theobject.name=thelist[3]
					    }
					}
			    }
		}
		
        if ((document.location+" ").indexOf("builder=true")!==-1) {
		    // let parent know that we are staring an update
            var qs = new Querystring()  ;      
            docLoc=qs.get("loc");
		    window.parent.location=docLoc+'#updatestarted'
		}
		
		setaction("",anaction) // anaction is either update or insert
}



// ======================================================================
function setrowcolor(id,bgcolor,tcolor,isbold) {
	gebi("TD_" + id).bgColor=bgcolor;
	gebi("TD_" + id).style.color=tcolor;
	(isbold) ? 	gebi("TD_" + id).style.fontWeight="bold" : gebi("TD_" + id).style.fontWeight="normal";
}




// ======================================================================
function test_email(emailStr) {

	emailStr=Trim(emailStr)
	var emailPat = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {
		return false;
	}
	return true
}
	
// ======================================================================
function match(string,asearch) {

	pattern="/"+Trim(asearch) + "/i"
	var matchArray = string.match(eval(pattern));
	if (matchArray == null) {
		return false;
	}
	return true
}



// ======================================================================	
function getleft(anobject) {if (document.all) {return parseInt(anobject.style.pixelLeft)} else {return parseInt(anobject.style.left)}}

// ======================================================================	
function gettop(anobject) {if (document.all) {return parseInt(anobject.style.pixelTop)} else {return parseInt(anobject.style.top)}}

// ======================================================================	
function getright(anobject) {if (document.all) {return getleft(anobject)+parseInt(anobject.scrollWidth)} else {	return getleft(anobject)+parseInt(anobject.offsetWidth)}}

// ======================================================================	
function getbottom(anobject) {if (document.all) {return gettop(anobject)+parseInt(anobject.scrollHeight)} else {return gettop(anobject)+parseInt(anobject.offsetHeight)}}

// ======================================================================	
function setleft(anobject,avalue) {if (document.all) {anobject.style.pixelLeft=avalue} else {anobject.style.left=avalue}}

// ======================================================================	
function settop(anobject,avalue) {if (document.all) {anobject.style.pixelTop=avalue} else {	anobject.style.top=avalue}}

function init() {

    a = document.location + " "
    if (a.indexOf("showmain") !== -1) {   // we are in an iframe of formarama, so we can access the parent
        //alert(gebi("totaltable").scrollHeight)
        //alert(gebi("totaltable").offsetHeight)
        if (top.gebi("logedinfooter")) {
            top.gebi("mainiframe").style.height = top.getWindowSize("h") - 173
        }
        else {
            top.gebi("mainiframe").style.height = top.getWindowSize("h") - 115
        }
        //top.gebi("mainiframe").style.width = gebi("stable").scrollWidth 
        
    }

}


// ======================================================================	
function init_scroller2() {

		len=document.getElementsByTagName("DIV").length
    
		

//		 make array with id's
		index=0
		myarray = new Array(10)
		for (var i=0, l=len;i<l;i++) {
			if (document.getElementsByTagName("DIV")[i].id) {
				if (document.getElementsByTagName("DIV")[i].id.indexOf("_tholder")!==-1) {
					myarray[index]=document.getElementsByTagName("DIV")[i].id
					
					index=index+1
				}
			}	
		}
		
		for (var i=0, l=index;i<l;i++) {
					
			table_shortname=replace(myarray[i],"_tholder","")
			atable=gebi(table_shortname)
			tholder=gebi(table_shortname+"_tholder")
			targeth=getobjectscrollheight(tholder)
			hasheader=false

			// does it have a header?
			if (gebi(table_shortname+"_hholder"))	{
				hasheader=true
				hholder=gebi(table_shortname+"_hholder")
			}

			// remove the header for netscape 6. doesn't work
			
			if (browser.isNS && !browser.isNS7up && hasheader) {
				hholder.parentNode.removeChild(hholder)
				hasheader=false
			}
			else {
				if (hasheader) {
					acopy=atable.cloneNode(true)
					acopy.id=table_shortname+"_aclone"
					acopy.style.left=0
					acopy.style.position="relative"
					table_shortname+"_aclone"
					hholder.appendChild(acopy)
					var trlist=atable.getElementsByTagName("tr")
					var clonelist=acopy.getElementsByTagName("tr")
					for (var j=0, k=clonelist.length;j<k;j++) {
						clonelist[j].id=""
					}
					hholder.style.height=getobjectscrollheight(trlist[0])
					tholder.style.height=parseInt(tholder.style.height)-getobjectscrollheight(trlist[0])
					// if the height doesn't fit in the holder, then there is vertical scroll bar. adjust the width of the header.
					
					if (getobjectscrollheight(atable)>getobjectscrollheight(tholder)) {
						//hholder.style.width=parseInt(tholder.style.width)-16
					}
					
					trlist[0].style.visibility='hidden'
					atable.tBodies[0].appendChild(trlist[0])
				}
			}
			//if (gebi("searchandnav")) {
			//	nh=targeth-getscrollheight("searchandnav")
			//	resize_scroller(table_shortname,0,nh)
			//}
		}
		
		if (gebi("stable_tholder")) {havetable=true; tholder=gebi("stable_tholder")}
		if (gebi("stable_hholder")) {hasheader=true; hholder=gebi("stable_hholder")}
				resize_scroller()
				//window.onresize=resize_scroller

	}
	
	
// ======================================================================	
function resize_scroller() {
//resize to window width and height
    a=0
    b=0
//logwin.document.body.innerHTML=logwin.document.body.innerHTML+"resize1"+"<br>"    
    id="stable"
    if (gebi("tabholder"))    {a=getscrollheight("tabholder")}
//logwin.document.body.innerHTML=logwin.document.body.innerHTML+"resize2"+"<br>"    
    
    if (gebi("searchandnav")) {b=getscrollheight("searchandnav")}
    c=getscrollheight("totaltable")
    w=getscrollwidth("totaltable")
    
    xh=getWindowSize("h")
    w=getWindowSize("w")
    xh=xh-a-b
    //alert(w)
    //alert(xh)
	if (gebi(id+"_tholder")) {
		atable=gebi(id)
		tholder=gebi(id+"_tholder")
		b=parseInt(tholder.parentNode.parentNode.parentNode.parentNode.border)*2
		b=0
		if (w!==0) {
			w=parseInt(w-b)
			tholder.style.width=w
			if (getobject(id+"_hholder")) {
				hholder=getobject(id+"_hholder")
				hholder.style.width=w
			
				if (getobjectscrollheight(atable)>getobjectscrollheight(tholder)) {
					//hholder.style.width=parseInt(tholder.style.width)-16
				}
				var trlist=hholder.getElementsByTagName("tr")
				hholder.style.height=getobjectscrollheight(trlist[0])
				
			}
		}
		if (xh!==0) {
			h=parseInt(xh-b)
			if (h>0 ) {
			tholder.style.height=h

			if (getobject(id+"_hholder")) {
				hholder=getobject(id+"_hholder")
				
				var trlist=hholder.getElementsByTagName("tr")
				hholder.style.height=getobjectscrollheight(trlist[0])
				tholder.style.height=max(0,h-getobjectscrollheight(trlist[0]))
				if (getobjectscrollheight(atable)>getobjectscrollheight(tholder)) {
					//hholder.style.width=parseInt(tholder.style.width)-16
				}
				else {
					hholder.style.width=parseInt(tholder.style.width)
				}
			}
			else {
				tholder.style.height=h
			}
			
			}
			
		}
	}
}



// ======================================================================	
function setheader(anobject) {
	if ((browser.isNS) && !(browser.isNS7up)) return
	
	theid=anobject.id
	hholderid=replace(theid,"_tholder","_hholder")
	cloneid=replace(theid,"_tholder","_aclone")
	if (gebi(cloneid)) {
		gebi(cloneid).style.left=-parseInt(gebi(theid).scrollLeft)
	}
	
}	


// ======================================================================	
function getobjectscrollwidth(anobject) {
	thewidth=parseInt(anobject.offsetWidth)
	if (browser.isOpera) {
		// add half the border size
		done=false
		if (anobject.border) {
			thewidth=thewidth+parseInt(anobject.border)
			done=true
		}
		if (!done) {
			if (anobject.style.border) {
				thewidth=thewidth+parseInt(anobject.style.borderWidth)
			}
		}
	}
	return thewidth
}

// ======================================================================	
function getobjectscrollheight(anobject) {
	theheight=parseInt(anobject.offsetHeight)
	
	if (browser.isOpera) {
		// add half the border size
		done=false
		if (anobject.border) {
			done=true
		}
		if (!done) {
			if (anobject.style.border) {
				theheight=theheight+parseInt(anobject.style.borderWidth)
			}
		}
	}
	return theheight
}

// ======================================================================	
function scrollto(tablename,anid) {
	clearTimeout(to_handle)
	if (gebi(tablename+"_tholder")) {

		theholder=gebi(tablename+"_tholder")
		vpheight=getobjectscrollheight(theholder)
		atable=gebi(tablename)
		tableheight=getobjectscrollheight(atable)
		trlist=atable.getElementsByTagName("tr")

		rows=trlist.length
		
		
		for (var i=0, l=rows-1;i<=l;i++) {
			if (trlist[i].id==anid){ 
				thepos=trlist[i].offsetTop-theholder.scrollTop
				rowheight=getobjectscrollheight(trlist[i])
				
				if (thepos<0) { 
					//above the viewport, decrease scrolltop
					newscrolltop=theholder.scrollTop+thepos-vpheight/2+rowheight/2
					if (newscrolltop<0) {newscrolltop=0}
					smoothscroll(tablename,newscrolltop)
				}
				else {
					//below the viewport, increase scrolltop
					if (thepos+rowheight>vpheight) {
					
						newscrolltop=theholder.scrollTop+((thepos+rowheight)-vpheight)+vpheight/2-rowheight/2
						if (newscrolltop>tableheight-vpheight) {newscrolltop=tableheight-vpheight}
						smoothscroll(tablename,newscrolltop)
					}
				}
				break
				alert("a record not found in scrollto")
			}
		}
	}
}	



// ======================================================================	
function doscroll(anobject) {
	setheader(anobject)
}
// ======================================================================	
function smoothscroll(tablename,target) {
	current=gebi(tablename+"_tholder").scrollTop
	if (current==target) {
		clearTimeout(to_handle)
	}
	else {
		
		delta=parseInt(target-current)
		if (Math.abs(target-current)>=2) {delta=parseInt((target-current)/2)}
		if (Math.abs(target-current)>=5) {delta=parseInt((target-current)/5)}
		if (Math.abs(target-current)>=10) {delta=parseInt((target-current)/10)}
	
		if (delta==0) {
			clearTimeout(to_handle)
		}
		else {
			theholder.scrollTop=current+delta
			to_handle=setTimeout("smoothscroll('"+tablename+"',"+target+")",1)		
		}
	}
}










// ======================================================================	
function get_color(aname) {
	if (aname=="green") {return "#008000"} 
	if (aname=="navy") {return "#000080"} 
	if (aname=="maroon") {return "#800000"} 
	if (aname=="lime") {return "#00ff00"} 
	if (aname=="blue") {return "#0000ff"} 
	if (aname=="red") {return "#ff0000"} 
	
	if (aname=="teal") {return "#008080"} 
	if (aname=="purple") {return "#800080"} 
	if (aname=="olive") {return "#808000"} 
	if (aname=="aqua") {return "#00ffff"} 
	if (aname=="fuchsia") {return "#ff00ff"} 
	if (aname=="yellow") {return "#ffff00"} 
}

//===================================================================================================
function open_window(aname,aw,ah) {
    if(!aw) {aw=500}
    if(!ah) {ah=200}
	newwin=window.open(aname,"","fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=yes,width="+aw+",height="+ah+"")
}		









//===================================================================================================
function getval(anid) {
	if (getobject(anid)) {return getobject(anid).value}
	return ""
}




//===================================================================================================
function getWindowSize(item) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (item=='w') return myWidth
  if (item=='h') return myHeight
}



//===================================================================================================
function min(a,b) {
	if (a<b) {return a}	else {return b}
}

//===================================================================================================
function max(a,b) {
	if (a>b) {return a} else {return b}
}

//===================================================================================================
function checkreturn(afunction) {
	if (returnkeydown) {
	    eval(afunction)
	    return true
	}
	return false
}

 //===================================================================================================
function RGB2Color(r,g,b)
  {
    return '#' + byte2Hex(r) + byte2Hex(g) + byte2Hex(b);
  }

//===================================================================================================
function byte2Hex(n){
    var nybHexString = "0123456789ABCDEF";
    return String(nybHexString.substr((n >> 4) & 0x0F,1)) + nybHexString.substr(n & 0x0F,1);
}







// ======================================================================
function test_url(w) {
    var j = new RegExp(); 
    w=w.toLowerCase()
	if (w.substring(0,7) !== "http://") {w = "http://" + w;} //make sure protocol is at beginning

    j.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+"); 
    if (!j.test(w)) { 
           return false; 
    } 
    else {
        return true
    }
    
}


// ======================================================================
function showinframe(thehost,event_c) {

    if (gebi("showframed").checked) {
        gebi("codediv").style.display = ''
        setcenter("codediv","screen")
        ah=getscrollheight("mainiframe")
        aw=getscrollwidth("mainiframe")

        aw=gebi("tablewidth").value
        ah=gebi("tableheight").value
        gebi("mainiframe").style.height=ah
        gebi("mainiframe").style.width = aw

    }
    else {
        gebi("codediv").style.display='none'
    
        gebi("mainiframe").style.height="100%"
        gebi("mainiframe").style.width = "100%"
        init()

    }
    window.frames[0].resize_scroller()

    generate_code(thehost,event_c) 
}

// ======================================================================
function generate_code(thehost,event_c) {
    aw=gebi("tablewidth").value
    ah=gebi("tableheight").value

	email_f=false
	email_s=false
	iframe=false

	if (gebi("emaillink1").checked)  { email_f=true }
	if (gebi("emaillink2").checked)  { email_s=true }
	if (gebi("iframelink").checked)  { iframe=true }
	if (gebi("inputlink").checked)  {thepage="showform"}
	if (gebi("resultlink").checked)  {thepage="submissions"}
	if (gebi("summarylink").checked)  {thepage="summary"}
	
	if (email_f) {gebi("linktext").value=thehost+"/showmain.asp?thepage="+ thepage+"&event_c="+event_c}
	if (email_s) {gebi("linktext").value=thehost+"/main.asp?thepage="+ thepage+"&event_c="+event_c }
	if (iframe)  {
	    gebi("linktext").value="<iframe width=" + aw + " height="+ah+" frameborder=0 scrolling='no'  marginwidth=0 marginheight=0 src='"+thehost+"/main.asp?thepage="+ thepage + "&event_c="+event_c+"&framed=true'></iframe>"
	}
}



function FCKeditor_OnComplete( editorInstance ) {
  if ((document.location+" ").indexOf("builder=true")!==-1) {
    editorInstance.EditorDocument.body.style.cssText = FCKStyle ;
    return
    // attach the style from the parent document
        
    if (gebi("css_"+editorInstance.Name)) {
    
        pageid=gebi("css2_"+editorInstance.Name).value
        
        
        thisdoc=editorInstance.EditorDocument
        
        alist=window.parent.document.getElementsByTagName("style")
        
        style=""
		for (var i=0, j=alist.length;i<j;i++) {
            style=style+alist[i].innerHTML
        }
        style=replace(style,"#"+pageid,"body")
      
        var styleElement = thisdoc.createElement('style');
        styleElement.type = 'text/css';
        if (styleElement.styleSheet) {
            styleElement.styleSheet.cssText = style;
        } else {
            styleElement.appendChild(thisdoc.createTextNode(style));
        }
        thisdoc.getElementsByTagName('head')[0].appendChild(styleElement);
      
      }
    }
    
    
    
    
}
function check_passwords(action) {
	p1=getval("password1")
	p2=getval("password2")
	mes=""
	if (p1.indexOf(" ")!==-1) {mes="Please don't use spaces or quotes in your password"}
	if (p1.indexOf("'")!==-1) {mes="Please don't use spaces or quotes in your password"}
	if (p1.indexOf('"')!==-1) {mes="Please don't use spaces or quotes in your password"}
	if (p1.length<6) {mes="Password has to be 6 characters at least"}
	if (p1.length>10) {mes="Password has to be between 6 and 10 characters"}
	if (p1!==p2) {mes="please check your password"}
	if (mes!=="") {
		alert(mes)
		return
	}
	
	if (Trim(getval("password1"))=="") {return}
	if (Trim(getval("password2"))=="") {return}


    gebi("thepage").value=""  // make sure that the querystring gets there, not a form value

	document.option_form.action=action+"check";
	document.option_form.submit()
}

function remove_pic(label) {

    if (gebi("fck_id")) {
        anid=gebi("fck_id").value
        var oEditor = FCKeditorAPI.GetInstance(anid)
        
        if (!oEditor.EditorDocument) {
        
            return
         }
         
				                
        if (oEditor.EditorDocument.getElementById("tmppic_"+label)) {
            el=oEditor.EditorDocument.getElementById("tmppic_"+label)
            el.parentNode.removeChild(el)
        }
        if (oEditor.EditorDocument.getElementById("pic_"+label)) {
            el=oEditor.EditorDocument.getElementById("pic_"+label)
            el.parentNode.removeChild(el)
        }
        
         
    }


}

        // ======================================================================	
        function addStyle(cssCode) {
           
            var styleElement = document.createElement('style');
            styleElement.type = 'text/css';
            if (styleElement.styleSheet) {
            styleElement.styleSheet.cssText = cssCode;
            } else {
            styleElement.appendChild(document.createTextNode(cssCode));
            }
            document.getElementsByTagName('head')[0].appendChild(styleElement);
        }        

        // ======================================================================	
        function poll() {
            if (!dopoll) {return}
            
            ahash=document.location.hash
            if (ahash==="#update") {
                document.location.hash="#"
                gebi("updatebutton").onclick()                
            }
            else if (ahash==="#cancel") {
                document.location.hash="#"            
                gebi("cancelbutton").onclick()
            }
            setTimeout(function(){poll()},500)
            
        }
// ======================================================================	
//    http://adamv.com/dev/javascript/querystring	
// ======================================================================	
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	this.get=Querystring_get;
	if (qs == null) {
		qs=location.search.substring(1,location.search.length);
        if (qs.indexOf("?")!==-1) {
        
            // if coming from a proxy page, then we can have 2 questionmarks. start from the last
            qs=qs.substr(qs.indexOf("?")+1);
       }
        
        
	if (qs.length === 0) 
		{return;}

	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
	for (var i=0;i<args.length;i++) {
		var pair = args[i].split('=');
		var name = unescape(pair[0]);
		if (pair.length===2) {value =unescape(pair[1]);} else {value=name;}
		//var value = (pair.length==2)
		//	? unescape(pair[1])
		//	: name;
		
		this.params[name] = value;
	}
	}
}

// ======================================================================	
function Querystring_get(key, default_) {
	var value=this.params[key];
	return (value!=null) ? value : default_;
}


function setcenter(idToCenter, idToCalculate, addScroll) {
    windowH = noPx(getWindowSize("h"));
    windowW = noPx(getWindowSize("w"));

    // center something in the middle of a screen;
    oldvis = gebi(idToCenter).style.display;
    gebi(idToCenter).style.display = "block";
    if (idToCalculate === "content") { idToCalculate = "content"; }
    gebi(idToCenter).style.position = "absolute";
    if ((idToCalculate === "window") || (idToCalculate === "screen")) {
        x = windowW / 2 - getscrollwidth(idToCenter) / 2;
        y = windowH / 2 - getscrollheight(idToCenter) / 2;
    }
        document.getElementById(idToCenter).style.left = x + 'px';
        document.getElementById(idToCenter).style.top = y + 'px';

    
    gebi(idToCenter).style.display = oldvis;

}
//=======================================================;
function noPx(aval) {
    if (aval === "") { return 0; }
    return parseInt(aval, 10);
}

