﻿function trimLeft(str){
  if (str==null){return null;}
  for(var i=0;str.charAt(i)==" ";i++);
  return str.substring(i,str.length);
}
function trimRight(str){
  if (str==null){return null;}
  for(var i=str.length-1;str.charAt(i)==" ";i--);
  return str.substring(0,i+1);
}
function trim(str){return trimLeft(trimRight(str));}
function trimLeftAll(str) {
  if (str==null){return str;}
  for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
  return str.substring(i,str.length);
}
function trimRightAll(str) {
  if (str==null){return str;}
  for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
  return str.substring(0,i+1);
}
function replaceAll(varb, replaceThis, replaceBy)
 {
      newvarbarray=varb.split(replaceThis);
      newvarb=newvarbarray.join(replaceBy);
      return newvarb;
}   
function trimAll(str) {
  return trimLeftAll(trimRightAll(str));
}
// isNull(value)
//   Returns true if value is null
function isNull(val){return(val=="");}

// isBlank(value)
//   Returns true if value only contains spaces
function isBlank(val){
  return isNull(trimAll(val));
}

// isInteger(value)
//   Returns true if value contains all digits
function isInteger(val){
  if (isBlank(val)){return false;}
  for(var i=0;i<val.length;i++){
    if(!isDigit(val.charAt(i))){return false;}
  }
  return true;
}

// isNumeric(value)
//   Returns true if value contains a positive float value
function isNumeric(val){return(parseFloat(val)==(val*1)&&parseFloat(val)>=0);}

// isArray(obj)
// Returns true if the object is an array, else false
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

// isDigit(value)
//   Returns true if value is a 1-character digit
function isDigit(num) {
  if (num.length>1){return false;}
  var string="1234567890";
  if (string.indexOf(num)!=-1){return true;}
  return false;
}

// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//Basic function added
//return true if the string is valid email string
function isEmailChar(str){
  for (i=0; i<str.length; i++){
    c = str.charAt(i);	  
    if("~!#$%^&*(),\'`:\;?<>=+\n\t \\\"".indexOf(c,0) > 0)
      return false;	
  }
  return true;
}

//return true if the parts of email are valid
function isValidEmail(email){

var array = email.split("@");
  if(array.length != 2) return false; 
  var first, last;
  first = array[0]; last = array[1];
  if( first.charAt(0)=='.') return false;  
  if( first.charAt(first.length)=='.') return false;
  if( last.charAt(0)=='.') return false;
  if(first == "" || last == "") return false;
  first = trimLeftAll(first);
  last = trimRightAll(last);
  if(!isEmailChar(first) || !isEmailChar(last)) 
    return false;
  return true;
}

// return true if number is in range of number
function isInRangeOfNumber(number, from, to){
  if(from<=number&&number<=to)
    return true;
  return false;
}

// round by type
// type="L": lowerRound. Ex: roundEx(1.255, 2, "L") = 1.25
// type="U": upperRound. Ex: roundEx(1.254, 2, "U") = 1.26
// type=others:  Ex:roundEx(1.255, 2, "") = 1.26

var DEFAULT_ROUND_TYPE = "L";
function roundEx(val, digit, type) {
  var result = val;
  if (type == "L")
    result = lowerRound(val, digit); 
  else if (type == "U")
    result = upperRound(val, digit); 
  else  
    result = round(val, digit); 
  return result;
}

// return round number. Ex: lowerRound(1.255, 2) = 1.26
function round(number, digits) { 
  var num = Math.pow(10, digits);
  var result = Math.round(number*num);
  result = result / num;
  return result; 
}

// return round number. Ex: upperRound(1.254, 2) = 1.26
function upperRound(number, digits) {
  var num = Math.pow(10, digits);
  num = num + 0.5;
  var result = Math.round(number * num);
  result = result / num;
  return result;
}

// return round number. Ex: lowerRound(1.256, 2) = 1.25
function lowerRound(number, digits) {
  var num = Math.pow(10, digits);
  var result = parseInt(number * num);
  result = result / num;
  return result;
}
//return true if the ENTER key is pressed
function isEnterPressed(evt) {
  evt = (evt) ? evt : event;
  var charCode  = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
  if (charCode == 13 || charCode == 3)
    return true;
  return false;
}
function txt_copy(txtFrom, txtTo){ 
  txtTo.value = txtFrom.value;
}

// File chondat.js
function DefineBrowser()
{
  // Neu trinh duyet la IE thi return "IE"
  // Neu trinh duyet la FireFox thi return "FF"

  return checkbrowser(); 
}
function checkbrowser() {

  var browsertype = navigator.userAgent.toLowerCase();  
  if (browsertype.indexOf('msie') != -1)        {
     browser = 'IE';
     return browser;
  }
  else if (browsertype.indexOf('netscape') != -1) {
     browser = 'NS';
     return browser;                         
  }
  else if (browsertype.indexOf('safari') != -1) {
     browser = 'SF';
     return browser;
  }
  else if (browsertype.indexOf('gecko') != -1) {
     browser = 'FF';
     return browser;
  }
}
// play movie file
function PlayFile( strSource, ctlID )
{
  var width=300;
  var height=300;
  var s;
  if(strSource.indexOf(".flv") > 0 || strSource.indexOf(".mp4") > 0)
  {
		s =" <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
      s+=" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' ";
     s+=" width='" + width + "' ";
     s+=" height='" + height + "' ";
     s+=" bgcolor='#FFFFFF'>";
     s+=" <param name='movie' value='images/FLVscrubber2.swf?file="+strSource+"&bufferTime=3&autoStart=true'/>";
     s+=" <param name='quality' value='high' />";
     s+=" <param name='allowScriptAccess' value='sameDomain'/>";
     s+=" <param name='allowFullScreen' value='true'/>";
      s+=" <embed src='images/FLVscrubber2.swf?file="+strSource+"&bufferTime=3&autoStart=true&loop=true'";
      s+=" quality='high' allowScriptAccess='sameDomain' pluginspage='http://www.macromedia.com/go/getflashplayer'";
       s+=" type='application/x-shockwave-flash'  width='" + width + "' height='" + height + "' style='background-color:#FFFFFF' />";
   s+=" </object>";
  }
  else
  {
		s="<OBJECT id=winMediaPlayerID ";
		s+="codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 ";
		s+="type=application/x-oleobject height=" + height + " ";
		s+="standby=\"Loading Microsoft Windows Media Player components...\" "; 
		s+="width=" + width + " classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ";
		s+="name=winMediaPlayerID>";
		s+="<PARAM NAME=\"URL\" VALUE=\""+strSource+"\"> ";
		s+="<PARAM NAME=\"rate\" VALUE=\"1\">";
		s+="<PARAM NAME=\"balance\" VALUE=\"0\">";
		s+="<PARAM NAME=\"currentPosition\" VALUE=\"0\">";
		s+="<PARAM NAME=\"defaultFrame\" VALUE=\"0\">";
		s+="<PARAM NAME=\"playCount\" VALUE=\"999\">";
		s+="<PARAM NAME=\"CursorType\" VALUE=\"-1\">";
		s+="<PARAM NAME=\"autoStart\" VALUE=\"1\">";
		s+="<PARAM NAME=\"autoplay\" VALUE=\"1\">";
		s+="<PARAM NAME=\"currentMarker\" VALUE=\"0\">";
		s+="<PARAM NAME=\"invokeURLs\" VALUE=\"-1\">";
		s+="<PARAM NAME=\"volume\" VALUE=\"50\">";
		s+="<PARAM NAME=\"mute\" VALUE=\"0\">";
		s+="<PARAM NAME=\"stretchToFit\" VALUE=\"-1\">";
		s+="<PARAM NAME=\"windowlessVideo\" VALUE=\"0\">";
		s+="<PARAM NAME=\"enabled\" VALUE=\"1\">";
		s+="<PARAM NAME=\"fullScreen\" VALUE=\"0\">";
		s+="<PARAM NAME=\"enableContextMenu\" VALUE=\"0\">";
		s+="<PARAM NAME=\"enableErrorDialogs\" VALUE=\"0\"> \n";

		s+="<Embed id='winMediaPlayerIDFF' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' filename='"+strSource+"' src='"+strSource+"' Name='winMediaPlayerIDFF' "; 
		s+="width='" + width + "' ";
		s+="height='" + height + "' ";
		s+="AutoSize='1' ";
		s+="AutoStart='1' ";
		s+="AutoPlay='1' ";
		s+="ClickToPlay='1' ";
		s+="DisplaySize='1' ";
		s+="EnableContextMenu='0' ";
		s+="EnableFullScreenControls='1' "; 
		s+="EnableTracker='1' ";
		s+="Mute='0' ";
		s+="PlayCount='999' "; 
		s+="ShowControls='1' "; 
		s+="ShowAudioControls='1' "; 
		s+="ShowDisplay='0' ";
		s+="ShowGotoBar='0' ";
		s+="ShowPositionControls='1' "; 
		s+="ShowStatusBar='1' ";
		s+="ShowTracker='1'> ";
		s+="</embed> ";
		s+="</OBJECT>";
  }
  ctlID.innerHTML = s;
}

//Format so voi ki tu phan cach phan 1000 la ','
//numberOfFloatingPointNumber la so ki tu cua phan thap phan ( so ki tu sau dau '.')
function NumericFormat(txt, numberOfFloatingPointNumber)
{
  var value = trimAll(txt.value);
  if(value.indexOf(",,")>0 || value.indexOf(".,")>0 || value.indexOf(",.")>0) return;
  value = replaceAll(value, ",", "");
  if(value!="" && !isNaN(value))
  {
    var sign = "";
    var floatingPart = "";
    
    // Luu lai phan dau cua value, neu co =========================
    if(value.charAt(0)=="+" || value.charAt(0)=="-")
    {
      sign = value.substring(0,1);
      value = value.replace(sign,"");
    }
    // Loai het so 0 phia truoc ===================================
    while(value.charAt(0) == '0')
    {
      try{
        value = value.substring(1);
      }catch(e){}
    }
    //value = "" + parseFloat(value);
    // ============================================================
    // Dinh dang phan thap phan
    // Cat bot phan thap phan neu phan thap phan = 0 hoac nhieu hon numberOfFloatingPointNumber
    var floatingPointPos = value.indexOf(".");
    if(floatingPointPos>0)
    {
      floatingPart = value.substring(floatingPointPos + 1,value.length);
      value = value.substring(0,floatingPointPos);
    }
    if(floatingPart.length > numberOfFloatingPointNumber)
    {
      floatingPart = floatingPart.substring(0, numberOfFloatingPointNumber);
    }
    if(numberOfFloatingPointNumber != null && numberOfFloatingPointNumber > 0 && floatingPart.length > 0 && parseFloat(floatingPart) > 0)
    {
      floatingPart = '.' + floatingPart;
    }
    else 
    {
      floatingPart = "";
    }
    // ============================================================
    // Dinh dang phan nguyen
    // Them vao dau phan cach
    var count = 0;
    var i = value.length;
    while(i>0)
    {
      if(count==3)
      {
        value = value.substring(0,i) + "," + value.substring(i,value.length);
        count = 1;
      }
      else
      {
        count++;
      }
      i--;
    }
    // ============================================================
    txt.value = (sign.replace("+","") + value + floatingPart).replace("NaN","");
  }
}

function OpenPopup(name, width, height, url)
{	
	var winW = 800, winH = 600;	
	winW = screen.width;
	winH = screen.height; 
	var posW = (winW - width)/2;		
	var posH = (winH - height)/2; 		
  var attributes = "width=" + width + ", height=" + height+ ", top="+posH+",left="+posW+",menubar=no, resizable=no,scrollbars=yes, status=1";  
  window.open(url,name, attributes);    
} 
///// Khanh addd to check price
function IsNumeric(sText)
		{
			 var ValidChars = "0123456789.";
			 var IsNumber=true;
			 var Char;

		 
			 for (i = 0; i < sText.length && IsNumber == true; i++) 
					{ 
					Char = sText.charAt(i); 
					if (ValidChars.indexOf(Char) == -1) 
						 {
						 IsNumber = false;
						 }
					}
			 return IsNumber;
		   
		}
		function HaveDot(value)
		{
			if(value.indexOf('.') >= 0)
			{
				return true;
			}
			return false;
			
		}
	 function CheckNumber(textbox)
	 {
			lastnumber = textbox.value.substring(textbox.value.length - 1, textbox.value.length);
			if(!IsNumeric(lastnumber) )
			{
				textbox.value = textbox.value.substring(0, textbox.value.length - 1);
			}
			else
			{
				if(lastnumber == '.')
				{
					if((HaveDot(textbox.value.substring(0,textbox.value.length - 1))))
					{
						textbox.value = textbox.value.substring(0, textbox.value.length - 1);
					}
				}
			}
	 }
// File Cookie.js

function setCookie (name, value, lifespan, access_path) {      
  var cookietext = name + "=" + escape(value)  
  if (lifespan != null) {  
    var today=new Date()     
    var expiredate = new Date()      
    expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
    cookietext += "; expires=" + expiredate.toGMTString()
  }
  if (access_path != null) { 
    cookietext += "; PATH="+access_path 
  }
  document.cookie = cookietext 
  return null  
}
function setDatedCookie(name, value, expire, access_path) {
  var cookietext = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
  if (access_path != null) { 
    cookietext += "; PATH="+access_path 
  }
  document.cookie = cookietext 
  return null        
}
function getCookie(Name) {
  var search = Name + "="                       
  var CookieString = document.cookie            
  var result = null                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
      } 
    }
   return result                                
}
function deleteCookie(Name, Path) {
  setCookie(Name,"Deleted", -1, Path)
}
// JScript File Tooltip.js
//tooltip
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip" ></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="./images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
document.onmousemove=positiontip;
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor= thecolor
tipobj.innerHTML=thetext
tipobj.style.position = "absolute"
tipobj.style.zIndex = 110
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
document.onmousemove=positiontip;
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
//end tooltip
// File Tooltip_thongke.js
document.write('<div id="dhtmltooltip_thongke" ></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer_thongke" src="./images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj_thongke=document.all? document.all["dhtmltooltip_thongke"] : document.getElementById? document.getElementById("dhtmltooltip_thongke") : ""

var pointerobj_thongke=document.all? document.all["dhtmlpointer_thongke"] : document.getElementById? document.getElementById("dhtmlpointer_thongke") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip_thongke(thetext, thewidth, thecolor){
document.onmousemove=positiontip_thongke;
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj_thongke.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj_thongke.style.backgroundColor= thecolor
tipobj_thongke.innerHTML=thetext
tipobj_thongke.style.position = "absolute"
tipobj_thongke.style.zIndex = 110
enabletip=true
return false
}
}

function positiontip_thongke(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj_thongke.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj_thongke.style.left=curX-tipobj_thongke.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj_thongke.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj_thongke.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj_thongke.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj_thongke.offsetHeight){
tipobj_thongke.style.top=curY-tipobj_thongke.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj_thongke.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj_thongke.style.top=curY+offsetfromcursorY+"px"
}
tipobj_thongke.style.visibility="visible"
if (!nondefaultpos)
pointerobj_thongke.style.visibility="visible"
else
pointerobj_thongke.style.visibility="hidden"
}
}

function hideddrivetip_thongke(){
document.onmousemove=positiontip;
if (ns6||ie){
enabletip=false
tipobj_thongke.style.visibility="hidden"
pointerobj_thongke.style.visibility="hidden"
tipobj_thongke.style.left="-1000px"
tipobj_thongke.style.backgroundColor=''
tipobj_thongke.style.width=''
}
}
//End tooltip_thongke
// Begin file events.js
var selectedRow = null;
var originalClass = "";

function markRow(row)
{
	selectedRow = row;
	originalClass = row.className;
	
	selectedRow.className = 'selectedRow';
}

function unmarkRow()
{
	if(selectedRow != null)
	{
		selectedRow.className = originalClass;
	}
}

/************************************************************************************************************/
/************************************************************************************************************/

function ChangeBGColor(row, className)
{
	if(row.className != "selectedRow")
		row.className = className;
}

/************************************************************************************************************/
/************************************************************************************************************/

function CustomAlert(message)
{
  if(DefineBrowser() == "IE")
	  ShowNotifyOk("Chọn đất", message);
  else if(DefineBrowser() == "FF" )
    return confirm(message);
}

function CustomConfirm(message)
{
  if(DefineBrowser() == "IE" )
	  return ShowConfirm("Chọn đất", message);
  else if(DefineBrowser() == "FF" ){
    return confirm(message);
  }
}

//end events.js
///////////////////////////////////////file tabcontent.js

////NO NEED TO EDIT BELOW////////////////////////

function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment
//end file tabcontent.js