﻿// $Id: portal.js,v 1.8 2006/02/07 14:37:38 karthik Exp $

///////////// Function to avoid Multiple button click ////////////////////
var TrapClicksForHowManySeconds = 60;

var AlertBoxMessage = "One click is sufficient. The server should respond momentarily.\n\n\nClick the \"OK\" button.";

var myImage = new Image();
myImage.src = "/images/button/processing.gif";

var TrapTime = 0;
var DoubleClickTrapperCounter = 0;
var submitButton;


function DoubleClickTrapperAction(thisButton) {
	submitButton = thisButton;
	DoubleClickTrapperCounter++;
	DoubleClickTrapperButton();
	var trapTheClick = false;
	if(DoubleClickTrapperCounter > 1 ) { trapTheClick = true; }
		if(trapTheClick == true) {
			if(TrapTime == 0) {
			var tDate = new Date;
			TrapTime = tDate.valueOf();
		}
		else {
			var tDate = new Date;
			var localTrapTime = tDate.valueOf();
			if((localTrapTime - TrapTime) > (TrapClicksForHowManySeconds * 1000)) {
				TrapTime = 0;
				trapTheClick = false;
				DoubleClickTrapperCounter = 0;
			}
		}
	}
	var valueToReturn = true;
	if(trapTheClick == true) {
		valueToReturn = false;
		//DoubleClickTrapperAlert();
	}
    //alert (valueToReturn);
    return valueToReturn;
} // end of function DoubleClickTrapperAction()


function DoubleClickTrapperButton() {
		submitButton.width= "109";
		submitButton.height= "19";
		submitButton.src = myImage.src;
} // end of function DoubleClickTrapperButton()

function DoubleClickTrapperAlert() {
	var message = StripSpaces(AlertBoxMessage);
	if(message.length > 0) { alert(AlertBoxMessage); }
} // end of function DoubleClickTrapperAlert()


function StripSpaces(s) {
	while(s.indexOf(' ') == 0) { s = s.substr(1); }
	return s;
} // end of function StripSpaces()


function zd_makeCookie( cName, cVal, eDate )  {

    var zp_domain=document.domain;

    if ( zp_domain.search(/^\d+\.\d+/) == -1 ) {
        if ( zp_domain.substr( zp_domain.length - 3, 1 ) == "." ) {
            var zl_dotpos=zp_domain.lastIndexOf('.');
            if ( zl_dotpos != -1 ) {
                zl_dotpos = zp_domain.lastIndexOf('.',zl_dotpos-1);
                if ( zl_dotpos != -1 ) {
                    zl_dotpos = zp_domain.lastIndexOf('.',zl_dotpos-1);
                    if ( zl_dotpos != -1 ) {
                        zp_domain = zp_domain.slice(zl_dotpos);
                    }
                }
            }
        }
        else {
            var zl_dotpos=document.domain.lastIndexOf('.');
            if ( zl_dotpos != -1 ) {
                zl_dotpos=document.domain.lastIndexOf('.',zl_dotpos-1);
                if ( zl_dotpos != -1 ) {
                    zp_domain=document.domain.slice(zl_dotpos);
                }
            }
        }
    }

    document.cookie = cName + '=' + cVal + ';expires=' + eDate.toGMTString() + ';domain=' + zp_domain +  ';path=/;';
}


//
// function: goToInputBox
// purpose:  get cursor to go to a particular input box in a form
// receives: input_box - the box that should have focus
// returns:  boolean indicating success or failure
//
function goToInputBox( input_box )
{
	var val = false;

	if (input_box)
	{
		input_box.focus();
		val = true;
	}

	return val;
}

//
// function: setSelected
// purpose:  set the "selected" property for the appropriate option in a
//           select box.
// receives: select_box    - select box object
//           selected_item - value of option to be selected
// returns:  boolean indicating success or failure
//
function setSelected( select_box, selected_item )
{
	var val = false;

	if (select_box) {
		var len = select_box.length;

		for (var i=0; i<len; i++)
		{
			if (select_box.options[i].value == selected_item)
			{
				select_box.options[i].selected = true;
				val = true;
			}
		}
	}

	return val;
}

//
// function: setChecked
// purpose:  set the "checked" property for a given checkbox form element.
// receives: check_box - check box object
//           set_value - turn it on or off
//
function setChecked( check_box, set_value )
{
	var val = false;

	if (check_box) {
		if (set_value == 'on') {
			check_box.checked = true;
			val = true;
		} else {
			check_box.checked = false;
			val = true;
		}
	}

	return;
}

function setRadioChecked( radio_list, set_value )
{
	if (radio_list) {
		for (var i=0; i < radio_list.length; i++) {
			if (radio_list[i].value == set_value) {
				radio_list[i].checked = true;
				return true;
			}
		}
	}

	return false;
}

var image_holder = '';

function swapImage( img_name, img_value, swap_type )
{
	var temp = eval( 'document.' + img_name );

	switch (swap_type)
	{
		case 'over':
			image_holder = temp.src;
			temp.src = img_value + '-over.gif';
			break;
		case 'off':
			temp.src = image_holder;
			break;
		case 'on':
			temp.src = img_value + '-on.gif';
			break;
		default:
			temp.src = img_value + '-over.gif';
			break;
	}
}

function swapMenuImage( img_name_p1, img_name_p2, swap_type )
{
	var img_name = '';
	var temp;

	if (img_name_p2 == '')
	{
		temp = eval( 'document.menu_' + img_name_p1 );
		img_name = img_name_p1;
	}
	else
	{
		temp = eval( 'document.menu_' + img_name_p2);
		img_name = img_name_p1 + '-' + img_name_p2;
	}

	switch (swap_type)
	{
		case 'over':
			image_holder = temp.src;
			temp.src = '/images/menu/' + img_name + '-over.gif';
			break;
		case 'off':
			temp.src = image_holder;
			break;
		case 'on':
			temp.src = '/images/menu/' + img_name + '-on.gif';
			break;
		default:
			temp.src = '/images/menu/' + img_name + '-over.gif';
			break;
	}

}

function numberValidation(objEvent)
    	{
          var iKeyCode =  objEvent.which ? objEvent.which : objEvent.keyCode;
    	  if(iKeyCode==8 || iKeyCode==0 || iKeyCode==37 || iKeyCode==39 || iKeyCode==46 ||(iKeyCode>47 && iKeyCode<=57)) return true;
    	  return false;
    	}

function rateValidation(rt,rate)
    	{
          var str = rt.value;

	//if(isNaN( parseInt(str) ) )
        if(isNaN(str) )
             {
               alert("Please enter valid Rate. The value entered should be a Positive number.");
               rt.value="0.0";
               return;
          }
          s = parseFloat(str);
          if(s < 0)
              {
                alert("Please enter valid Rate. The value entered should be a Positive number.");
                rt.value="0.0";
                return;
          }
     	str = ""+s;

        if(str.indexOf('.') <= -1)
	    {
		  str = str+".0";
	    }

    	  if(str.indexOf(".") == 0){
              if(str.length == 1)
                var s = "0"+str+"0";
              else
                var s = "0"+str;
              str = s;
    	  }
    	  //alert(rt.value);
    	  //alert(rt.value.length);
    	  if(rt.value == "")
    	     rt.value ="0.0";
	       else
		     rt.value =str;
    	}

function highlight(which,color)
{
if (document.all||document.getElementById)
which.style.backgroundColor=color
}



//
// End of File
//


