var obj;
var maxDivCount=0;
var DivWidth;
var DivHeight;

var actionurl;
var html_leftof_clickableCaption;
var clickableCaption;
var html_rightof_clickableCaption;
var openingwidth;
var openingheight;


function OPENUP(href,clickableText,widthofiframe,heightofiframe,Seperator)

{

	DivWidth = widthofiframe 
	DivHeight = heightofiframe
	OPENUPSTEP2(href,clickableText,"MyClass",Seperator,widthofiframe,heightofiframe)	

	
}

function OPENUPADVANCED(href,nonclickabletextbegin,ClickableText,nonclickabletextend,widthofiframe,heightofiframe)

{

	DivWidth = widthofiframe 
	DivHeight = heightofiframe
	OPENUPADVANCEDSTEP2(href,nonclickabletextbegin,ClickableText,nonclickabletextend,"MyClass",widthofiframe,heightofiframe)	

	
}



function OPENUPSTEP2(URL,ClickableText,aclass,Seperator,widthofiframe,heightofiframe)
{
		var DivCatID;

		maxDivCount=maxDivCount+1
		DivCatID=maxDivCount-1
		
			document.write ("<style type='text/css'>")
			document.write ("<!--")
			document.write ("iframe#sortlist-insert"+DivCatID+" {")
			document.write ("width:"+widthofiframe+"px;")
			document.write ("height: "+heightofiframe+"px;")
			document.write ("margin: 0;")
			document.write ("padding: 0;")
			document.write ("border: 0px none;")
			document.write ("}")
			document.write ("-->")
			document.write ("</style>")

		document.write ("<a class="+aclass+" onclick='jav"+"ascript: return OPENUPSTEP3(" + DivCatID + ",\""+URL+"\",\""+""+"\");'  href='#'>"+ClickableText+"</a>")
		
		document.write ("<span id='divCategory"+DivCatID+"' style='display: none;'>")
		
		document.write ("<div style='width: "+widthofiframe+"px;'></div>")
		
		document.write ("<iframe style='filter:chroma (color=00ff80)' allowtransparency='true'  name='frameCategory"+DivCatID+"' src='blank.htm' marginwidth='0' marginheight='0' scrolling='Auto' frameborder='0' id='sortlist-insert"+DivCatID+"'></iframe>")

		document.write ("</span>")
		document.write (Seperator)
		
}

function OPENUPADVANCEDSTEP2(URL,nonclickabletextbegin,ClickableText,nonclickabletextend,aclass,widthofiframe,heightofiframe)
{
		var DivCatID;

		maxDivCount=maxDivCount+1
		DivCatID=maxDivCount-1
		
			document.write ("<style type='text/css'>")
			document.write ("<!--")
			document.write ("iframe#sortlist-insert"+DivCatID+" {")
			document.write ("width:"+widthofiframe+"px;")
			document.write ("height: "+heightofiframe+"px;")
			document.write ("margin: 0;")
			document.write ("padding: 0;")
			document.write ("border: 0px none;")
			document.write ("}")
			document.write ("-->")
			document.write ("</style>")

		document.write (nonclickabletextbegin)	

		document.write ("<a class="+aclass+" onclick='jav"+"ascript: return OPENUPSTEP3(" + DivCatID + ",\""+URL+"\",\""+""+"\");'  href='#'>"+ClickableText+"</a>")
		
		document.write (nonclickabletextend)	
		
		document.write ("<span id='divCategory"+DivCatID+"' style='display: none;'>")
		
		document.write ("<iframe style='filter:chroma (color=00ff80)' allowtransparency='true'  name='frameCategory"+DivCatID+"' src='blank.htm' marginwidth='0' marginheight='0' scrolling='Auto' frameborder='0' id='sortlist-insert"+DivCatID+"'></iframe>")

//document.write ("<hr color=green><div style='width: "+widthofiframe+"px;'></div><hr color=red>")		

		document.write ("</span>")

		
}





function OPENUPSTEP3(num,URL)
{

	var section = document.getElementById("divCategory" + num);
	var isopen = (section.style.display != "none");
	HideAll();
	var frame = document.getElementById("frameCategory" + num);
	//frames[num].location.href=URL
	frames[num].location.href=URL
	section = document.getElementById("divCategory" + num);
	if (!isopen)
	{
		section.style.display = "";
	}
	else
	{
		section.style.display = "none";
	}
	return false;
}




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 HideSection(sectionName)
{
	var section = document.getElementById(sectionName);
   section.style.display = "none";
}
function ShowSection(sectionName)
{
	var section = document.getElementById(sectionName);
   section.style.display = "";
}
var idClickOnEnter;
var lastKeyPressed;
function keyPressed(e)
{
   if (window.Event)
	  lastKeyPressed = e.which
   else
	  lastKeyPressed = event.keyCode

   if (idClickOnEnter != null && lastKeyPressed == 13) {
	  var el = document.getElementById(idClickOnEnter);

	  if (el != null) {
		 el.click();
		 return false;
	  }
   }

   return true;
}
if (window.Event)
window.captureEvents(Event.KEYPRESS)
document.onkeypress = keyPressed;
function ClickOnEnter(id)
{
   idClickOnEnter = id;
   return true;
}

 function HideAll()
 {
	for (i = 0; i < maxDivCount; i++) {
	 section = document.getElementById("divCategory" + i);
	   section.style.display = "none";
	}
 }





function instr(iStartingFrom,lrgstring,smstring,bolNotCaseSensitive) {
	//returns a number indicating the spot where smstring appears in lrgstring.
    //behaves exactly like vb's instr function

   //this is how to use 
    /*
	var sString;
	var sSearch;
	var iStartingFrom;
	var vbTextCompare;
	vbTextCompare=true;
	sString='hello World this is a simple string. ';
	sSearch='hello';
	iStartingFrom=1;
	alert(instr(iStartingFrom,sString,sSearch,vbTextCompare)) ;
    */
	lrgstring=lrgstring.substring(iStartingFrom-1,lrgstring.length)
	//alert('after the cut' + lrgstring)
	if ( bolNotCaseSensitive ) {
		lrgstring=lrgstring.toLowerCase();	
		smstring=smstring.toLowerCase();
	}	
    // this function has a bug, when the searched word is found at the beginning of the large word , it returns 0!..
    //following fix is just for that !...
   	if ( smstring == lrgstring.substring(0,smstring.length) ) {
   	   //set foundat to 1 and return immediately since smstring is found at the beginning of the lrgstring already !...
   	   foundat=1;
   	   return foundat;
   	}
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	foundat = 0
	for (i=0;i<=strlen2;i++) {
		comp=lrgstring.substring(i-1,strlen2)
		comp = comp.substring(0,strlen1)		
		if (comp == smstring) {
			foundat = i
			break
		}
	}
	if ( iStartingFrom != 1 ) {
	    return foundat-(iStartingFrom-1);
	}
	else{
		return foundat;	
	}
}



function getinbetween2(sContents, sBeginningKey, sEndingKey) {
     //this is not case sensitive
	//? GetInBetween2("<1>ddd<2>jjj", "<1>", "<2>")
	//ddd
	//? getinbetween2("<1>ddd<1>jjj","<1>","<1>")
	//ddd
	var sText;
	var iBeginningKeyStartsAt;
	var sEndingKeyStartsAt;
	var vbTextCompare;
	var sCapturedResult;
	vbTextCompare=true;
	sText = sContents
	iBeginningKeyStartsAt = instr(1, sContents, sBeginningKey, vbTextCompare);
	sEndingKeyStartsAt = instr(1, sContents, sEndingKey, vbTextCompare);
	if (iBeginningKeyStartsAt > 0 && sEndingKeyStartsAt > 0) {
	   sText = right(sText, (len(sText) - (iBeginningKeyStartsAt + (len(sBeginningKey) - 1))));
	   sText = left(sText, (instr(1, sText, sEndingKey, vbTextCompare) - 1))
	   if ( sText == "" ) {
	      sCapturedResult = ""
	   }
	   else{
	      sCapturedResult = sText
	   }
	}
	else{
	  sCapturedResult = ""
	}
    return sCapturedResult;
}




function trim(str)   {

	if (str.length==0) {return "";} 

	while (str.charAt(0)==" ")
             {str=str.substring(1,str.length);}	

	while (str.charAt(str.length-1)==" ")
             {str=str.substring(0,str.length-1);}

    return str;      
}



function ReplaceString(sFull, sOld, sNew) {
  var sData = "";
  for (var i=0; i<sFull.length; i++) { 
  if (sFull.substring(i,i+sOld.length) == sOld) {
      sData = sData + sNew;
      i = i + sOld.length - 1;
  } else { sData = sData + sFull.substring(i,i+1) }
  }
  return sData;
}

function replace(sFull, sOld, sNew) {
  //this is the same as the replastring function, ( just a wrapped up version with a different name ) 
  //included here so that copied and pasted vb code containing either replace or ReplaceString can work the same way...
  return ReplaceString(sFull, sOld, sNew);
}



function ltrim(sTxt) {
  var iSpaces = 0;
  var fQuit = false;
  var iPos = -1;
  while (fQuit == false) { 
    iPos = iPos + 1
    if (sTxt.substring(iPos, iPos + 1) == " ") {
      iSpaces =  iSpaces + 1;
    }
    else fQuit = true
  }
  return sTxt.substring(iSpaces, sTxt.length);
}


function rtrim(sTxt) {
var iSpaces = 0;
var fQuit = false;
var iPos = sTxt.length;
while (fQuit == false) { 
  iPos = iPos - 1
  if (sTxt.substring(iPos, iPos + 1) == " ") {
    iSpaces =  iSpaces + 1;
  }
  else fQuit = true
}
return sTxt.substring(0, sTxt.length - iSpaces);
}



function ucase(str) {
	//returns str in all uppercase letters.
	return str.toUpperCase()
}


function spot(smstring,lrgstring) {
	//returns a number indicating the spot where smstring appears in lrgstring.
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	foundat = 0
	for (i=0;i<=strlen2;i++) {
		comp=lrgstring.substring(i-1,strlen2)
		comp = comp.substring(0,strlen1)		
		if (comp == smstring) {
			foundat = i
			break
		}
	}
	return foundat
}

function rightof(smstring,lrgstring) {
	//returns the rightmost characters of lrgstring back to smstring.
	//If user passes an empty string, change that to a space.
	if (smstring == ""){smstring = " "}
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	foundat = 0
	for (i=strlen2;i>=0;i--) {
		comp=lrgstring.substring(i-1,strlen2)
		comp = comp.substring(0,strlen1)		
		if (comp == smstring) {
			foundat = i
			break
		}
	}
	return lrgstring.substring(foundat,255)
}



function right(str,n) {
	//returns the right n characters of str
	strlen = str.length
	return str.substring(strlen-n,strlen)
}


function pcase(str) {
	//returns str in proper-noun case (first letter uppercase)
	strlen = str.length
	jj = str.substring(0,1).toUpperCase()
	jj = jj + str.substring(1,strlen).toLowerCase()
	for (i = 2; i <= strlen; i++) {
		if (jj.charAt(i)==" ") {
			lefthalf = jj.substring(0,i+1)
			righthalf = jj.substring(i+1,strlen)
			righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
			jj=lefthalf+righthalf
		}
	}
	return jj
}


function mid(str,start,n) {
	//returns a substring of str starting at 'start' that's n characters long.
	//alert('mid param n is passed as ' + n);
	if ( (n == null) || n == "undefined" ) {
	   n = str.length;
	}
	strlen = str.length
	var jj = str.substring(start-1,strlen)
	jj = jj.substring(0,n)
	return jj
}

function leftof(smstring,lrgstring) {
	//returns leftmost characters of lrgstring up to smstring.
	//If user passes an empty string, change that to a space.
	if (smstring == ""){smstring = " "}
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	foundat = 0
	for (i=0;i<=strlen2;i++) {
		comp=lrgstring.substring(i-1,strlen2)
		comp = comp.substring(0,strlen1)		
		if (comp == smstring) {
			foundat = i
			break
		}
	}
	return lrgstring.substring(0,(foundat-1))
}


function lcase(str) {
	//returns str in all lowercase letters.
	return str.toLowerCase()
}

function left(str,n) {
	//returns the left n characters from str.
	return str.substring(0,n)
}


function trim(str)   {

	if (str.length==0) {return "";} 

	while (str.charAt(0)==" ")
             {str=str.substring(1,str.length);}	

	while (str.charAt(str.length-1)==" ")
             {str=str.substring(0,str.length-1);}

    return str;      
}


function contains(smstring,lrgstring) {
	//returns true if lrgstring contains smstring.
	//case insensitive
	smstring=smstring.toLowerCase();
	lrgstring=lrgstring.toLowerCase();
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	istrue = false	
	for (i=0;i<=strlen2;i++) {
		comp=lrgstring.substring(i-1,strlen2)
		comp = comp.substring(0,strlen1)		
		if (comp == smstring) {
			istrue = true
			break
		}
	}
	return istrue
}


function len(str) {
/***
        IN: str - the string whose length we are interested in

        RETVAL: The number of characters in the string
***/
  return String(str).length;  
}
 



