
// only return 0-9 a-z or A-Z
function ValHandle1(o){
  o.value=o.value.replace(/([^0-9A-Za-z\x2D])/g,"");
}

// only return 0-9 a-z or A-Z
function ValHandle2(o){
  if(/[^0-9A-Za-z]/.test(o.value)){
    o.value=o.value.replace(/([^0-9A-Za-z\x2D])/g,"");
  }
}

// Macromedia Library functions for menu control
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function jump(menu){
  var loc = menu[menu.selectedIndex].value.split("|");
  if(loc.length == 2)
    window.open(loc[1], loc[0]);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// This function tests any text cell for the presence of double width chars
function WidthTest(evt, option) {
	// option 0 = anything allowed
	// option 1 = auto convert double english to single
	// option 2 = error on double width english
	for (count=0; count<=evt.value.length; count++)	{
		teststring = evt.value
		testchar = teststring.substr(count, 1);
		testasc = testchar.charCodeAt()
		// option 1 dbl width english conversion
		if ((testasc > 65295) && (testasc < 65371) && (option == 1)) {
								evt.value = teststring.substr(0, count) + String.fromCharCode(testasc-65248) + teststring.substr(count+1, (teststring.length - (count+1)));
    							}
		// Convert full width Katakana to half width Katakana						
		if ((testasc >= 12450) && (testasc <= 12531) && (option == 1)) {
			//alert(testasc);
			result = "";
			if (testasc == 12450) {result = String.fromCharCode(65393);};
			if (testasc == 12452) {result = String.fromCharCode(65394);};
			if (testasc == 12454) {result = String.fromCharCode(65395);};
			if (testasc == 12456) {result = String.fromCharCode(65396);};
			if (testasc == 12458) {result = String.fromCharCode(65397);};
			
			if (testasc == 12459) {result = String.fromCharCode(65398);};
			if (testasc == 12460) {result = String.fromCharCode(65398) + String.fromCharCode(65438);};
			if (testasc == 12461) {result = String.fromCharCode(65399);};
			if (testasc == 12462) {result = String.fromCharCode(65399) + String.fromCharCode(65438);};
			if (testasc == 12463) {result = String.fromCharCode(65400);};
			if (testasc == 12464) {result = String.fromCharCode(65400) + String.fromCharCode(65438);};
			if (testasc == 12465) {result = String.fromCharCode(65401);};
			if (testasc == 12466) {result = String.fromCharCode(65401) + String.fromCharCode(65438);};
			if (testasc == 12467) {result = String.fromCharCode(65402);};
			if (testasc == 12468) {result = String.fromCharCode(65402) + String.fromCharCode(65438);};

			if (testasc == 12469) {result = String.fromCharCode(65403);};
			if (testasc == 12470) {result = String.fromCharCode(65403) + String.fromCharCode(65438);};
			if (testasc == 12471) {result = String.fromCharCode(65404);};
			if (testasc == 12472) {result = String.fromCharCode(65404) + String.fromCharCode(65438);};
			if (testasc == 12473) {result = String.fromCharCode(65405);};
			if (testasc == 12474) {result = String.fromCharCode(65405) + String.fromCharCode(65438);};
			if (testasc == 12475) {result = String.fromCharCode(65406);};
			if (testasc == 12476) {result = String.fromCharCode(65406) + String.fromCharCode(65438);};
			if (testasc == 12477) {result = String.fromCharCode(65407);};
			if (testasc == 12478) {result = String.fromCharCode(65407) + String.fromCharCode(65438);};

			if (testasc == 12479) {result = String.fromCharCode(65408);};
			if (testasc == 12480) {result = String.fromCharCode(65408) + String.fromCharCode(65438);};
			if (testasc == 12481) {result = String.fromCharCode(65409);};
			if (testasc == 12482) {result = String.fromCharCode(65409) + String.fromCharCode(65438);};
			if (testasc == 12484) {result = String.fromCharCode(65410);};
			if (testasc == 12485) {result = String.fromCharCode(65410) + String.fromCharCode(65438);};
			if (testasc == 12486) {result = String.fromCharCode(65411);};
			if (testasc == 12487) {result = String.fromCharCode(65411) + String.fromCharCode(65438);};
			if (testasc == 12488) {result = String.fromCharCode(65412);};
			if (testasc == 12489) {result = String.fromCharCode(65412) + String.fromCharCode(65438);};

			if (testasc == 12490) {result = String.fromCharCode(65413);};
			if (testasc == 12491) {result = String.fromCharCode(65414);};
			if (testasc == 12492) {result = String.fromCharCode(65415);};
			if (testasc == 12493) {result = String.fromCharCode(65416);};
			if (testasc == 12494) {result = String.fromCharCode(65417);};

			if (testasc == 12495) {result = String.fromCharCode(65418);};
			if (testasc == 12496) {result = String.fromCharCode(65418) + String.fromCharCode(65438);};
			if (testasc == 12497) {result = String.fromCharCode(65418) + String.fromCharCode(65439);};
			if (testasc == 12498) {result = String.fromCharCode(65419);};
			if (testasc == 12499) {result = String.fromCharCode(65419) + String.fromCharCode(65438);};
			if (testasc == 12500) {result = String.fromCharCode(65419) + String.fromCharCode(65439);};
			if (testasc == 12501) {result = String.fromCharCode(65420);};
			if (testasc == 12502) {result = String.fromCharCode(65420) + String.fromCharCode(65438);};
			if (testasc == 12503) {result = String.fromCharCode(65420) + String.fromCharCode(65439);};
			if (testasc == 12504) {result = String.fromCharCode(65421);};
			if (testasc == 12505) {result = String.fromCharCode(65421) + String.fromCharCode(65438);};
			if (testasc == 12506) {result = String.fromCharCode(65421) + String.fromCharCode(65439);};
			if (testasc == 12507) {result = String.fromCharCode(65422);};
			if (testasc == 12508) {result = String.fromCharCode(65422) + String.fromCharCode(65438);};
			if (testasc == 12509) {result = String.fromCharCode(65422) + String.fromCharCode(65439);};

			if (testasc == 12510) {result = String.fromCharCode(65423);};
			if (testasc == 12511) {result = String.fromCharCode(65424);};
			if (testasc == 12512) {result = String.fromCharCode(65425);};
			if (testasc == 12513) {result = String.fromCharCode(65426);};
			if (testasc == 12514) {result = String.fromCharCode(65427);};

			if (testasc == 12516) {result = String.fromCharCode(65428);};
			if (testasc == 12517) {result = String.fromCharCode(65429);};
			if (testasc == 12518) {result = String.fromCharCode(65429);};
			if (testasc == 12519) {result = String.fromCharCode(65430);};
			if (testasc == 12520) {result = String.fromCharCode(65430);};

			if (testasc == 12521) {result = String.fromCharCode(65431);};
			if (testasc == 12522) {result = String.fromCharCode(65432);};
			if (testasc == 12523) {result = String.fromCharCode(65433);};
			if (testasc == 12524) {result = String.fromCharCode(65434);};
			if (testasc == 12525) {result = String.fromCharCode(65435);};

			if (testasc == 12526) {result = String.fromCharCode(65436);};
			if (testasc == 12527) {result = String.fromCharCode(65436);};
			if (testasc == 12530) {result = String.fromCharCode(65382);};
			if (testasc == 12531) {result = String.fromCharCode(65437);};
					
			if (result != "") {		
					resultstring = teststring.substr(0, count) + result + teststring.substr(count+1, (teststring.length - (count+1)));
					evt.value = resultstring;
					//alert(result.charCodeAt());
								}
								}
		// option 2 dbl width english error						
		if ((testasc > 65295) && (testasc < 65371) && (option == 2)) {
								alert("<%=WebTextCart(7)%>");
									// No Double Width Chars Allowed!
								evt.value = "";
								evt.focus();
								evt.focus();
    							}

													}
}

//------------------------------ This for tree menu --------------------------------------
function Toggle(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
	 
   if (visible) {
     obj.style.display="none";
   } else {
      obj.style.display="block";
   }
}

function Toggle_Menu_Ins_old(item, imagefolder, style, level) {
	obj=document.getElementById(item);
	visible=(obj.style.display!="none")
	key=document.getElementById("X" + item);
	if (style == '2') {
		if (level == '2') {
		   imagefileExpand = imagefolder+"expand2.gif"
		   imagefileCollapse = imagefolder+"collapse2.gif"
		} else {
		   imagefileExpand = imagefolder+"expand1.gif"
		   imagefileCollapse = imagefolder+"collapse1.gif"
		}
	} else {
	   imagefileExpand = imagefolder+"expand.gif"
	   imagefileCollapse = imagefolder+"collapse.gif"
	}
	if (visible) {
	 obj.style.display="none";
	 key.innerHTML="<img src='"+imagefileExpand+"' border=0>";
	} else {
	  obj.style.display="block";
	  key.innerHTML="<img src='"+imagefileCollapse+"' border=0>";
	}
}

function Toggle_Menu_Ins(item, imagefolder) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   key=document.getElementById("X" + item);
   imagefileExpand = imagefolder+"expand1.gif"
   imagefileCollapse = imagefolder+"collapse1.gif"
   if (visible) {
     obj.style.display="none";
     key.innerHTML="<img src='"+imagefileExpand+"' border=0>";
   } else {
      obj.style.display="block";
      key.innerHTML="<img src='"+imagefileCollapse+"' border=0>";
   }
}


function Toggle_Menu_Ins2(item, imagefolder) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   key=document.getElementById("X" + item);
   imagefileExpand = imagefolder+"expand2.gif"
   imagefileCollapse = imagefolder+"collapse2.gif"
   if (visible) {
     obj.style.display="none";
     key.innerHTML="<img src='"+imagefileExpand+"' border=0>";
   } else {
      obj.style.display="block";
      key.innerHTML="<img src='"+imagefileCollapse+"' border=0>";
   }
}

function Toggle_Help_Over(item) {
	obj=document.getElementById(item);
	if(obj != null)
		obj.style.display="block";
}

function Toggle_Help_Out(item) {
	obj=document.getElementById(item);
	if(obj != null)
		obj.style.display="none";
}
/*function Expand() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="block";
     key=document.getElementById("X" + divs[i].id);
     key.innerHTML="<img src='/clientinc/template0/colapse.gif' border=0>";
   }
}

function Collapse() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="none";
     key=document.getElementById("X" + divs[i].id);
     key.innerHTML="<img src='/clientinc/template0/expand.gif' border=0>";
   }
}*/

/* BookMark URL Used on the Members Promotion Tips Page */

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

/* Limit Max Chars */

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function validateMaxChars(frm,maxchar,ID) {
		var char_count = frm.value.length;
		document.getElementById(ID).innerHTML = char_count + "/" + maxchar;
			
		if(char_count > maxchar){
			frm.value = frm.value.substring(0, maxchar);
		}
	}

/* Refresh Page */
function timedPageRefresh(timePeriod) {
	setTimeout("location.reload(true);",timePeriod);
}


/*

Project:	Input Placeholder Text
Title:		Automatic population of form fields with contents of title attributes
Author      Jon Gibbins (aka dotjay)
Created:	13 Aug 2005
Modified:	26 Oct 2009



Notes:

Add the following classes to text inputs or textareas to get the 
desired behaviour:

auto-select
	Will pre-populate the input with the title attribute and select the
	text when it receives focus.

auto-clear
	Will pre-populate the input with the title attribute and clear the 
	text when it receives focus. Note: if auto-select and auto-clear 
	are set, auto-select takes precedence.

populate
	Will just populate the input with the title attribute.

NB: A class name of "placeholder" is set on form inputs that have 
placeholder text in them. This allows you to style the inputs 
differently when there is user input versus placeholder text, e.g.
input.placeholder,
textarea.placeholder{
color: #777;
}



Potential additions:

Add in handling of default text if an initial value is detected (line 
60, line 93, etc) using something like:
if (!el.defaultValue) continue;
el.onfocus = function() {
	if (this.value == this.defaultValue) this.value = "";
}
el.onblur = function() {
	if (this.value == "") this.value = this.defaultValue;
}


*/

function hasClass(el,cls) {
	return el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(el,cls) {
    if (!this.hasClass(el,cls)) el.className += " "+cls;
}
function removeClass(el,cls) {
    if (hasClass(el,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        el.className = el.className.replace(reg,' ');
    }
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function initFormPlaceholders() {

	if (!document.getElementsByTagName) return true;

	ourForms = document.getElementsByTagName('form');

	// go through each form
	var numForms = ourForms.length;
	for (var i=0;i<numForms;i++) {

		// go through each form element
		var numFormElements = ourForms[i].elements.length;
		for (var j=0;j<numFormElements;j++) {

			var el = ourForms[i].elements[j];

			// ignore submit buttons
			if (el.type == "submit") continue;

			// if we got a text type input or textarea
			if ((el.type == "text") || (el.type == "textarea")) {
				// only populate if we want it to
				// note: might want title attribute but no pre-population of inputs
				var ourClassName = el.className;
				if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
					// only populate if empty
					if (el.value == '') {
					    addClass(el, "placeholder");
					    el.value = el.title;
					}
				}

				// add auto select if class contains auto-select
				// note: else if below so auto-select takes precedence (assuming select is better than clear)
				if (el.className.match('auto-select')) {
					el.onfocus = function () {
						if (this.value == this.title) {
						    removeClass(this, "placeholder");
						    this.select();
						}
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);

					el.onblur = function () {
						if (this.value == '') {
						    this.value = this.title;
						}
						if (this.value == this.title) {
						    addClass(this, "placeholder");
						}
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}

				// add auto clear if class contains auto-clear
				else if (el.className.match('auto-clear')) {
					el.onfocus = function () {
						if (this.value == this.title) {
						    removeClass(this, "placeholder");
						    this.value = '';
						}
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);

					el.onblur = function () {
						if (this.value == '') {
						    this.value = this.title;
						}
						if (this.value == this.title) {
						    addClass(this, "placeholder");
						}
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}
			}

		}

	}

}

addLoadEvent(initFormPlaceholders);

