




if(document.all){ browserType='IE';}
else if(document.getElementById){ browserType='FF';}

var zVal='';	// global variable to hold existing value of an element.


function DivSetHight(fe1, fe2) {
	obj1 = document.getElementById(fe1);
	h1 = obj1.offsetHeight;


	obj2 = document.getElementById(fe2);
	h2 = obj2.offsetHeight;


	if(browserType =='FF'){ h1=h1-2; h2=h2-2; }
	 
	if (h1>h2)
	 obj2.style.height=h1+'px';
	else
	 obj1.style.height=h2+'px';
}

function togDiv( iv, status,from ) {
//alert(iv + '  --  '  + from );
	if (!(document.getElementById(iv))) 

		alert( ' ERROR  --  ' + iv + '  --  '  + from );
	else
	   obj=document.getElementById(iv);x='';if(status==0){x=0;}else if(status==1){x=1;}else if (status==2){if(obj.style.display=='none'){x=1;}else{x=0;}}if(x==1){obj.style.display='block';}else if(x==0){obj.style.display='none';}
	// Set status 0 off, 1 on, 2 on/off
}


function fmatCur(num){ num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";cents=Math.floor((num*100+0.5)%100);num = Math.floor((num*100+0.5)/100).toString();if(cents < 10)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));}return('$'+num+'.'+cents);}
function fmatCura(num){ num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";cents=Math.floor((num*100+0.5)%100);num = Math.floor((num*100+0.5)/100).toString();if(cents < 10)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));}return(num+'.'+cents);}
function fmatCur0(num){num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";cents=Math.floor((num*100+0.5)%100);num = Math.floor((num*100+0.5)/100).toString();if(cents < 10)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));} if(num+'.'+cents!='0.00') return(num+'.'+cents);		else return '';}
function fmatCur1(num){num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";cents=Math.floor((num*100+0.5)%100);num = Math.floor((num*100+0.5)/100).toString();if(cents < 10)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));} if(num+'.'+cents!='0.00') return('$'+num+'.'+cents);	else return '';}
function fmatCur2(num){num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";cents=Math.floor((num*100+0.5)%100);num = Math.floor((num*100+0.5)/100).toString();if(cents < 10)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));} if(num+'.'+cents=='0.00') return'';						else return('$'+num+'.'+cents);}
function fmatInt(num){num=num.toString().replace(/\$|\,/g,'').replace('.','').trimEnds();if(isNaN(num))num="";return( num );}

function fmatDec(num){num=num.toString().replace(/\$|\,/g,'');if(isNaN(num)){	num="0";}cents=Math.floor((num*1000+0.5)%1000);num = Math.floor((num*1000+0.5)/1000).toString();if(cents < 10)cents="00"+cents;else if(cents < 100)cents="0"+cents;
for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));} if(num+'.'+cents!='0.000')return(num+'.'+cents);else return '';}



function getId(e){
return document.getElementById(e);
}


function setVal(e,v) {
//alert(e);
	document.getElementById(e).value= v;
}



function stripSpaces(str){
	str = str.replace(/ /g,'');
	return str;
}


function setRadio(f,e,v){

	var RadioObj = eval('document.'+f+'.'+e);

	var radioLength = RadioObj.length

	for(var i = 0; i < radioLength; i++) {
		RadioObj[i].checked = false;
		if(RadioObj[i].value == v.toString()) {
			RadioObj[i].checked = true;
		}
	}
}

function setInHtml(e,v) {
	document.getElementById(e).innerHTML= v;
}

function getInHtml(e) {
	//alert(e);
	return document.getElementById(e).innerHTML;
}

function setBG(e,bg) {
	document.getElementById(e).style.backgroundColor=bg;
}

function setClass(e,f){
	if(f==1) 
		var z='selected';
	else 
		var z='off';
	document.getElementById(e).className=z;
}

function setChecked(e,tf){ 
	document.getElementById(e).checked=tf;
}

function setDisabled(e){
	document.getElementById(e).disabled=true;
}

function setEnabled(e){
	document.getElementById(e).disabled=false;
}

function setBGI(e,bgi) {

// alert( e + ' - ' + bgi );
	var url = 'url('+bgi+')';

	document.getElementById(e).style.backgroundImage=url;
//	eval('document.getElementById(\''+e+'\').style.backgroundImage="url(\'/images/leftdivfade-C6D3DC.gif\')"');
}
 

function myReplace(sOrgVal,sSearchVal,sReplaceVal)
{
   var sVal;
   try
   {
      sVal = new String(sOrgVal);
      if (sVal.length < 1) { return sVal; }
      var sRegExp = eval("/" + sSearchVal + "/g");
      sVal = sVal.replace(sRegExp,sReplaceVal);
   }
   catch (exception)  { }
   return sVal;

 }
 



function createWindow(fe){
var theStr=getVal(fe);
if(theStr.trimEnds().length==0)return false;
var winName = window.open("about:blank","winName");
winName.document.write(theStr);
winname.document.close();
}

function setColor(e,co) {
	document.getElementById(e).style.color=co;
}
function setVis(e,offOn){
  var v = "visible";
  if(offOn==0)
	var v = "hidden";
 
 document.getElementById(e).style.visibility=v;
}


function getVal(e) { // alert( e );
	var retval = document.getElementById(e).value;
	return retval;
}

function getRadioVal(fn,fe){

	var el = eval('document.'+fn+'.'+fe);

	for(var i = 0; i < el.length; i++) {
		if(el[i].checked) {
			return el[i].value;
		}
	}
}

function getChecked(e){
	if(document.getElementById(e).checked)
		return 1;
	else 
		return 0;
}


function setFocus(e) {
	document.getElementById(e).focus();
}

function setSRC(e,val){
	document.getElementById(e).src = val;
}

function getSRC(e){
	return document.getElementById(e).src;
}


function setZ(iv,z) {
	document.getElementById(iv).style.zIndex=z;
}


function textCounter(field, countfield, maxlimit) {

	if (field.value.length > maxlimit) 

		field.value = field.value.substring(0, maxlimit);

	else 
		countfield.value = maxlimit - field.value.length;
 }


function selectOption(fe,valtoselect) {


    var optlist = document.getElementById(fe); 
     for (j = 0; j < optlist.options.length; j++){  


	if (valtoselect.toLowerCase()==optlist.options[j].value.toLowerCase()){  

		optlist.options[j].selected=true; 
		break; 
	   } 
     }
  } 

function selectAddOption(fe, txtadd, valadd ) {
    var optlist = document.getElementById(fe); 
	var totalOps = optlist.options.length;
    for (var j = 0; j < totalOps; j++){  
		if (txtadd.toLowerCase()==optlist.options[j].text.toLowerCase()) {
				return false; 
		}
	}
	optlist.options[totalOps] = new Option(txtadd,valadd);
} 




function selectRemoveOption(fe, val2remove ) {
    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (val2remove==optlist.options[j].value){  
		optlist.options[j]=null; 
		break; 
	   } 
     }
  } 
function selectChangeTxtOption(fe, listvalue, newtext ) {
    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (listvalue==optlist.options[j].value){  
		optlist.options[j].text=newtext; 
		break; 
	   } 
     }
  } 
function selectGetTxt(fe,val) {
    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (val==optlist.options[j].value){  
	   return optlist.options[j].text;
	   } 
     }
  } 
function selectGetSelectedTxt(fe) {
    var optlist = document.getElementById(fe); 
	for(var i=0; i< optlist.options.length; i++) {
		if(optlist.options[i].selected==true){
			return optlist.options[i].text;
		}
	}
}



function selectIsSameTxtInList(e,newTxt){
    var optlist = document.getElementById(e); 
	for(var i=0; i< optlist.options.length; i++) {
		if ( newTxt==optlist.options[i].text && optlist.options[i].selected==false ){  
			return 1;
		}
	}
			return 0;
}





 
 
function inArray(array){              
  var o = {};
  for(var i=0;i<=array.length;i++){
    o[array[i]]='';
  }
  return o;
}


String.prototype.trimEnds = function () { // trim white-space off both ends of object string
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

String.prototype.enc = function () { // convert ampersand
//	return this.replace(/&/g,'%26');

	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = this;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;

}


function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}



function trimEnds2(str){
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');

}
 



String.prototype.revString = function() {
    var s = "";
    var i = this.length;
    while (i>0) {
        s += this.substring(i-1,i);
        i--;
    }
    return s;
}












function checkKeyPressed(e){

	return e.keyCode;
}


function stripCC(e) { 

 	var retval = e.replace(/[^0-9-]/g, ''); 
	retval = retval.replace(/--/g, '');
			

   	return retval; 
}


function stripAlpha(e) { 

 	var retval = e.replace(/[^0-9]/g, ''); 
   	return retval; 
}
 

function stripNonAlpha(e) { 

 	var retval = e.replace(/[^0-9-]/g, ''); 
   	return retval; 
}


// Get elementById
function getElement(obj){
var theObj;

	if(document.all) {			// If IE
	  if(typeof obj=="string"){
	  	return document.all(obj);
	    } 
	  else {
	   	return obj;
	    }
	 }

	if(document.getElementById) {  		// Everything Else
	  if(typeof obj=="string") {
	  	return document.getElementById(obj);
	    } 
	  else {
	  	return obj;
	   }
	 }
	 
   return null;
}



function fmatComma(nStr)
{
	nStr += '';
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}



function droppedInto(){


	var dropTarget	=	dd.obj.getEltBelow();


	if( dropTarget != null ){
	
		setSRC( 'item1_img', getSRC(dd.obj.name) );
		dd.obj.hide(true);
		
	
	}

 //alert( dd.obj.name + ' -- ' + dropTarget.name );


}
