//<script>

window.onload			= init;

// GET PHP VALUES FOR BASE_DIR & DEBUG_MODE
var BASE_DIR			= '';
var IS_DEBUG_MODE		= true;

// BROWSER SNIFFING FOR DYNAMIC BROWSER CAPABILITIES
var AGENT				= navigator.userAgent.toLowerCase();
var IS_DYNAMIC_BROWSER  = document.all || document.getElementById;
var IS_IE				= AGENT.indexOf("msie") != -1 && AGENT.indexOf("opera") == -1;
var IS_NETSCAPE         = AGENT.indexOf('mozilla')!=-1 && AGENT.indexOf('spoofer')==-1 && AGENT.indexOf('compatible') == -1 && AGENT.indexOf('opera')==-1 && AGENT.indexOf('webtv')==-1 && AGENT.indexOf('hotjava')==-1;
var IS_COMPAT_MODE		= document.compatMode == "CSS1Compat";

// IMG ROLLOVER SETTINGS <img class='rollover' src='path/to/img_out.jpg' />
var g_strImgClass		= "rollover";
var g_strOver_ext		= "_over";
var g_strOut_ext		= "_out";

// called "onload"...all onload functions should be called within init()
function init() {
    processImages();
}
function addRollover( p_oTag ) {
	if( p_oTag.className == g_strImgClass ) {
		var preload;
		var strSrc           = p_oTag.src;
		preload		         = new Image();
		preload.src          = strSrc.replace( g_strOut_ext, g_strOver_ext );
		p_oTag.onmouseover   = toggleImgOver;
		p_oTag.onmouseout    = toggleImgOver;
	}
}
function fixPNG( p_oTag ) {
	if(IS_IE) {
	  var version			 		= parseFloat( navigator.appVersion.split("MSIE")[1] );
	  if( version >= 5.5 && version < 7 && document.body.filters ) {
	    strSrc				 		= p_oTag.src;
		strSrc_lower				= strSrc.toLowerCase();
		if( strSrc_lower.substring(strSrc_lower.length-3, strSrc_lower.length) == "png" ) {
		  p_oTag.src		 		= BASE_DIR + "/lib/images/spacer.gif";
		  p_oTag.style.cssText		= "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + strSrc + "', sizingMethod='scale');" + p_oTag.style.cssText;
		}
	  }
	}
}
function processImages() {
    if( document.getElementsByTagName ) {
        var arrIMGTags       = document.getElementsByTagName("IMG");
        var arrINPUTTags     = document.getElementsByTagName("INPUT");

        for(i=0,j=0; i < arrIMGTags.length; i++) {
			addRollover( arrIMGTags[i] );
			fixPNG( arrIMGTags[i] );
        }
        for(i=0,j=0; i < arrINPUTTags.length; i++) {
		  if( arrINPUTTags[i].type == "image" ) {
			addRollover( arrINPUTTags[i] );
			fixPNG( arrINPUTTags[i] );
		  }
        }
    }
}
function toggleImgOver(e) {
    if(!e) e = event;
	this.src = e.type=="mouseover" ? this.src.replace( g_strOut_ext, g_strOver_ext ) : this.src.replace( g_strOver_ext,g_strOut_ext );
}

function limitKeyStrokes(p_oElement, p_oCounter, i) {
	bOkay									= p_oElement.value.length <= i;
	p_oCounter.value						= p_oElement.value.length;
	p_oCounter.style.backgroundColor		= bOkay ? "white"          : "red";
	p_oCounter.style.color					= bOkay ? "black"          : "white";

	if( !bOkay ) { p_oElement.value         = p_oElement.value.substring(0,i); }
}

function checkAll(p_oTag, p_strElements) {
	oForm							= p_oTag.form;
	arrCheckboxes					= oForm.elements[p_strElements];

	for( i=0; i<arrCheckboxes.length; i++ ) {
		arrCheckboxes[i].checked	= p_oTag.checked;
	}
}
function clearDefault(p_obj, p_strDefault) {
	if( p_obj.value == p_strDefault ) p_obj.value = "";
}
function bookmark() {
	strURL			= window.location.href;
	strTitle		= document.title.replace(/\:+/g,"-");
	if( document.all )        { window.external.AddFavorite(strURL, strTitle); }
	else if( window.sidebar ) { window.sidebar.addPanel(strTitle, strURL, ""); }
}
function toggleChild( p_oTag ) {
	strDisplay		= getTagByID( p_oTag.id+"_child").style.display;
	getTagByID(p_oTag.id+"_child").style.display		= strDisplay=="block" ? "none" : "block";
}
function getBody() {
	return( document.body.parentNode ? document.body.parentNode : document.body );
}
function getTagByID( p_strID ) {
    return( document.all ? document.all[p_strID] : document.getElementById(p_strID) );
}
function debugWrite( p_strText ) {
	if( IS_DEBUG_MODE ) { alert( p_strText ); }
}
function doNothing() { return }

function removeText(formField) {
  if (formField.defaultValue==formField.value) { formField.value = "" }
} 
function replaceText(formField) {
  if (formField.value=="") { formField.value = formField.defaultValue }
}




//------------------- for clearing and replacing text in form input fields and textareas -------------------//
function removeText(formField) {
  if (formField.defaultValue==formField.value) { formField.value = "" }
} 
function replaceText(formField) {
  if (formField.value=="") { formField.value = formField.defaultValue }
}
function clearOptionals(formFields){
	fields = formFields.split(',')
	for(i=0;i<fields.length;i++){
		if (fields[i].charAt(0) == ' ') { 
			fields[i] = fields[i].substring(1);
		}
		removeText(document.getElementById(fields[i]));
	}
}

//------------------- Form Validation -------------------//

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte;
  for (i=1; i<a.length;i=i+4){
	if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
	o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
	o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
	v=o.value;t=a[i+2];dv = o.defaultValue;
	if (o.type=='text'||o.type=='password'||o.type=='hidden'){
	  if ((r&&v.length==0)||v==dv){err=true}
	  if (v.length>0)
	  if (t==1){ //fromto
		ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
	  } else if (t==2){
		rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
	  } else if (t==3){ // date
		ma=a[i+1].split("#");at=v.match(ma[0]);
		if(at){
		  cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
		  dte=new Date(cy,cm,cd);
		  if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
		}else{err=true}
	  } else if (t==4){ // time
		ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
	  } else if (t==5){ // check this 2
			if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
			if(!o1.checked){err=true}
	  } else if (t==6){ // the same
			if(v!=MM_findObj(a[i+1]).value){err=true}
	  }
	} else
	if (!o.type&&o.length>0&&o[0].type=='radio'){
		  at = a[i].match(/(.*)\[(\d+)\].*/i);
		  o2=(o.length>1)?o[at[2]]:o;
	  if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
	  if (t==2){
		oo=false;
		for(j=0;j<o.length;j++){oo=oo||o[j].checked}
		if(!oo){s+='* '+a[i+3]+'\n'}
	  }
	} else if (o.type=='checkbox'){
	  if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
	} else if (o.type=='select-one'||o.type=='select-multiple'){
	  if(t==1&&o.selectedIndex/1==0){err=true}
	}else if (o.type=='textarea'){
	  if(v.length<a[i+1] || v == 'Comments: *' || v == ''){err=true}
	}
	if (err){s+=a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('Please complete the following required fields:\n\n'+s)}
  document.MM_returnValue = (s=='');
}
