function LTrim(str)
        {
               var whitespace = new String(" \t\n\r");
               var s = new String(str);
                if (whitespace.indexOf(s.charAt(0)) != -1) {

                    var j=0, i = s.length;
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;
                    s = s.substring(j, i);
                }

                return s;
        }
function RTrim(str)
       {
                var whitespace = new String(" \t\n\r");
                var s = new String(str);
                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    var i = s.length - 1;       
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;
                    s = s.substring(0, i+1);
                }

                return s;
        }


function Trim(str)
        {
                return RTrim(LTrim(str));
        }

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_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_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 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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//AJAX function
function GetXmlHttpObject()
{ 
    var objXMLHttp =null
    if (window.XMLHttpRequest){
        objXMLHttp =new XMLHttpRequest()
    }
    else if (window.ActiveXObject){
        objXMLHttp =new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
} 

function Cmoney(num)
{
	if (isNaN(num))
	{
		num="0.00";
	}
	else
   	{
		num = "" + ((Math.round(num * 100)) / 100);
		var dec1 = num.substring(num.length-3, num.length-2);
		var dec2 = num.substring(num.length-2, num.length-1);

		if (dec1 != '.') 
		{ // adds trailing zeroes if necessary
			if (dec2 == '.') num += "0";
			else num += ".00";
		}
	}
	return num;	
}

function checkValidDate(dateStr) {
    // dateStr must be of format month day year with either slashes
    // or dashes separating the parts. Some minor changes would have
    // to be made to use day month year or another format.
    // This function returns True if the date is valid.
    var slash1 = dateStr.indexOf("/");
    if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
    // if no slashes or dashes, invalid date
    if (slash1 == -1) { return false; }
    var dateMonth = dateStr.substring(0, slash1)
    var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
    var slash2 = dateMonthAndYear.indexOf("/");
    if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
    // if not a second slash or dash, invalid date
    if (slash2 == -1) { return false; }
    var dateDay = dateMonthAndYear.substring(0, slash2);
    var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
    if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
    // if any non-digits in the month, invalid date
    for (var x=0; x < dateMonth.length; x++) {
        var digit = dateMonth.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text month to a number
    var numMonth = 0;
    for (var x=0; x < dateMonth.length; x++) {
        digit = dateMonth.substring(x, x+1);
        numMonth *= 10;
        numMonth += parseInt(digit);
    }
    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
    // if any non-digits in the day, invalid date
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text day to a number
    var numDay = 0;
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        numDay *= 10;
        numDay += parseInt(digit);
    }
    if ((numDay <= 0) || (numDay > 31)) { return false; }
    // February can't be greater than 29 (leap year calculation comes later)
    if ((numMonth == 2) && (numDay > 29)) { return false; }
    // check for months with only 30 days
    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
        if (numDay > 30) { return false; } 
    }
    // if any non-digits in the year, invalid date
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text year to a number
    var numYear = 0;
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        numYear *= 10;
        numYear += parseInt(digit);
    }
    // Year must be a 2-digit year or a 4-digit year
    if ( (dateYear.length != 2) && (dateYear.length != 4) ) { return false; }
    // if 2-digit year, use 50 as a pivot date
    if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
    if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
    if ((numYear <= 0) || (numYear > 9999)) { return false; }
    // check for leap year if the month and day is Feb 29
    if ((numMonth == 2) && (numDay == 29)) {
        var div4 = numYear % 4;
        var div100 = numYear % 100;
        var div400 = numYear % 400;
        // if not divisible by 4, then not a leap year so Feb 29 is invalid
        if (div4 != 0) { return false; }
        // at this point, year is divisible by 4. So if year is divisible by
        // 100 and not 400, then it's not a leap year so Feb 29 is invalid
        if ((div100 == 0) && (div400 != 0)) { return false; }
    }
    // date is valid
    return true;
}

function initFade() {
	testObj = document.getElementById("divContent");
	for (var i=0;i<11;i++)
		setTimeout('setOpacity('+i+')',100*i);
	return false;
}

function setOpacity(value)
{
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function ValidateContact()
{
	var errMsg="";
  	//----------------------------------------------------------------------------
    document.getElementById('FirstNameVal').style.color='';
	document.getElementById('LastNameVal').style.color='';
    document.getElementById('TitleVal').style.color='';
    document.getElementById('OrganizationVal').style.color='';
    document.getElementById('PhoneVal').style.color='';
    document.getElementById('EmailVal').style.color='';
    document.getElementById('EventDateVal').style.color='';
    document.getElementById('GroupSizeVal').style.color='';
    var FlagValid=0;
  	//----------------------------------------------------------------------------
    if (Trim(document.getElementById("FirstName").value)=='') {
        document.getElementById('FirstNameVal').style.color='red';
        FlagValid=1
    }
	if (Trim(document.getElementById("LastName").value)=='') {
        document.getElementById('LastNameVal').style.color='red';
        FlagValid=1
    }
    if (Trim(document.getElementById("Title").value)=='') {
        document.getElementById('TitleVal').style.color='red';
        FlagValid=1
    }
    if (Trim(document.getElementById("Organization").value)=='') {
        document.getElementById('OrganizationVal').style.color='red';
        FlagValid=1
    }
    if (Trim(document.getElementById("Phone").value)=='') {
        document.getElementById('PhoneVal').style.color='red';
        FlagValid=1
    }
  //---Email Start---------------------------------------------------------------
    var checkStr = document.getElementById("Email").value;
    var ch = checkStr.indexOf('@');
    if (ch==0 || ch==-1) {
        document.getElementById('EmailVal').style.color='red';
        FlagValid=1
    }
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzfSOZsozY&Agrave;&Aacute;&Acirc;&Atilde;ÄÅ¯&Ccedil;&Egrave;É&Ecirc;&Euml;&Igrave;&Iacute;&Icirc;&Iuml;&ETH;&Ntilde;&Ograve;Ó&Ocirc;ÕÖ¨&Ugrave;&Uacute;&Ucirc;Ü&Yacute;&THORN;ß&agrave;&aacute;&acirc;&atilde;äå¿&ccedil;&egrave;é&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&eth;&ntilde;&ograve;ó&ocirc;õö¸&ugrave;&uacute;&ucirc;ü&yacute;&thorn;0123456789@.-_'";
    var checkStr = document.getElementById("Email").value;
    var allValid = true;
    for (i=0; i<checkStr.length; i++) {
         ch = checkStr.charAt(i);
         for (j=0; j< checkOK.length; j++)
              if (ch==checkOK.charAt(j))
                  break;
              if (j==checkOK.length) {
                  allValid = false;
                  break;
              }
         }
         if (!allValid) {
             document.getElementById('EmailVal').style.color='red';
             FlagValid=1;
    }
  //---Email End---------------------------------------------------------------
    if (Trim(document.getElementById("EventDate").value)=='') {
        document.getElementById('EventDateVal').style.color='red';
        FlagValid=1
    }
    if (Trim(document.getElementById("GroupSize").value)=='') {
        document.getElementById('GroupSizeVal').style.color='red';
        FlagValid=1
    }

  //----------------------------------------------------------------------------
    if (FlagValid==1)
    {
        errMsg = "Please fill in the required fields in red.";
    }
    return (errMsg);
  //----------------------------------------------------------------------------
}
function Hide_Show_Details(box)
{ 
	var boxclassName = box.className;
	wr = box;
	if (boxclassName == 'css_details_ds_id')
	{
		wr.className  = 'css_details_ds_id_hide';					
	}
	else
	{
		wr.className  = 'css_details_ds_id';
		if (document.getElementById("p_id_search"))
			document.getElementById("p_id_search").focus();
	}				
	return false;
}	

function right_onload()
{
  setTimeout("floater_init();", 50);
}
function floater_init()
{
  sliderCell = document.getElementById("slidercell")
  if (sliderCell)
  {
	  floating_menu =
		document.getElementById
		? document.getElementById(fm_id)
		: document.all
		  ? document.all[fm_id]
		  : document.layers[fm_id];
	
	  if (floating_menu)
	  {
		  fm_height = floating_menu.offsetHeight;
		  compute_shifts();
		
		  if (document.layers)
		  {
			// Netscape 4 cannot perform init move
			// when the page loads.
			fm_next_x = 0;
			fm_next_y = 0;
		  }
		  else
		  {
			fm_next_x = fm_shift_x + target_x;
			fm_next_y = fm_shift_y + target_y;
			move_menu();
		  }
		
		  float_menu();
	   }
   }
}
function move_menu()
{
  if (document.layers)
  {
	if(isNaN(fm_next_y))
		fm_next_y=0;
	floating_menu.top = fm_next_y;
  }
  else
  {
	if(isNaN(fm_next_y))
		fm_next_y=0;
	floating_menu.style.top = fm_next_y + 'px';

  }
}
function pageHeight()
{
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function compute_shifts()
{
  //fm_shift_y = the middle of the screen (based on scroller) - the height of the floater/2
  sTop = document.body.scrollTop;
  if(pageHeight() >= sliderCell.offsetHeight-sTop + floating_menu.offsetHeight)
  {
	if (pageHeight() >=floating_menu.offsetHeight)
	{
		if (sTop - begin_top>=0)
			fm_shift_y = (sTop - begin_top + (20+popupOffset));
	}
	else
		fm_shift_y = sliderCell.offsetHeight - floating_menu.offsetHeight;
  }
  else if(sTop - begin_top >= 0)
  {
	fm_shift_y = (sTop - begin_top + (20+popupOffset));
  }
  else
  {
	fm_shift_y = 0;
  }
}

function float_menu()
{
  var step_x, step_y;

  compute_shifts();
  step_y = (fm_shift_y + target_y - fm_next_y) * .07;
  if (Math.abs(step_y) < .5)
	  step_y = fm_shift_y + target_y - fm_next_y;

  if (document.getElementById(fm_id))
  {
	  if (Math.abs(fm_next_y) > sliderCell.offsetHeight-document.getElementById(fm_id).offsetParent.offsetHeight)
	  {
		if (step_y < 0)
		{
		  fm_next_y += step_y;
		  move_menu();
		}
		else
		{
		  //fm_next_y += step_y;
		  move_menu();
//		  if (document.layers)
//		  {
//			floating_menu.top = sliderCell.offsetHeight-document.getElementById(fm_id).offsetParent.offsetHeight-begin_top;
//		  }
//		  else
//		  {
//			floating_menu.style.top = (sliderCell.offsetHeight-document.getElementById(fm_id).offsetParent.offsetHeight-begin_top) + 'px';
//		  }
		}
	  }
	  else if (Math.abs(step_x) > 0 || Math.abs(step_y) > 0)
	  {
		fm_next_y += step_y;
		move_menu();
	  }
	  setTimeout('float_menu()', 20);
  }
}
function validateNum(txt)
{
	var err = "";

	var checkOK = "0123456789";
	var checkStr = txt;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		err="Please enter only digit in this field."
	}  

	return (err);
}

function validateMaxItem(grandparentid,parent,MaxItem,i,origValue,flagMaxItem)
{
	var strID;
	var totalSubQuantity=0;
	if (grandparentid==0)
		grandparentid=parent;
	for(j=0; j<document.all.length; j++)
	{
		strID = document.all[j].id;
		if (flagMaxItem=1)
		{
			if (strID.indexOf("quantity_" + grandparentid + "_")>=0)
			{
				totalSubQuantity = totalSubQuantity+parseInt(document.getElementById(strID).value);
			}
		}
		else
		{
			if (strID.indexOf("quantity_" + grandparentid + "_"+parent+"_")>=0)
			{
				totalSubQuantity = totalSubQuantity+parseInt(document.getElementById(strID).value);
			}
		}
	}
	//alert(totalSubQuantity);
	//debugger;
	if ((totalSubQuantity>MaxItem*document.getElementById("quantity_" + grandparentid).value)&&MaxItem!=0)
	{
		document.getElementById("quantity_" + grandparentid + "_" + parent + "_" + i).value=origValue;
		document.getElementById("divErr").innerHTML="Only " + MaxItem + " item(s) allowed.";
		ShowError("divErr");
		return;
	}
}
//check/uncheck related items when removing from shoppingcart
function chkothers(fld,yn,cid,e,grndID)
{
	if (yn=="Yes")
	{
		for(j=0; j<document.all.length; j++)
		{
			strID = document.all[j].id;
			if (strID.indexOf("selected_" + e + "_" + cid + "_")>=0)
			{
				if (fld.checked)
					document.getElementById(strID).checked=true;
				else
					document.getElementById(strID).checked=false;
			}
		}
	}
	else if (fld.checked==false)
	{
		for(j=0; j<document.all.length; j++)
		{
			strID = document.all[j].id;
			if (strID.indexOf("selected" + grndID + "_" + e + "_")>=0)
			{
				document.getElementById(strID).checked=false;
			}
		}
	}
}