function getobject(id) {

	var curleft = curtop = 0;
	var curwidth = curheight = 0;

	var obj = document.getElementById(id);

	return getobj(obj);
}

function getobj(obj) {

	var curleft = curtop = 0;
	var curwidth = curheight = 0;

	if(obj.style.position=='absolute') {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		curwidth = obj.offsetWidth
		curheight = obj.offsetHeight
	}
	else{
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			curwidth = obj.offsetWidth
			curheight = obj.offsetHeight
			
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
	}

	return [curleft,curtop,curwidth,curheight];
}

function openHelpMenu(menu) {
	//menu.className='button_left_hover'; 
	
	var offset=0;
	if(navigator.userAgent.indexOf("Chrome")>-1) {
		offset=4;	
	}
	else if(navigator.userAgent.indexOf("Safari")>-1) {
		offset=5;	
	}
	
	var area=getobj(menu);
	var img=menu.getElementsByTagName('div').item(0).getElementsByTagName('img').item(0);
	img.src='images/submenu_help_rollover.jpg';
	var dropdown=menu.getElementsByTagName('div').item(1);
	dropdown.className='dropdown_visible';	
	dropdown.style.left=area[0]+25+"px";
	dropdown.style.top=((area[1] + area[3]) - offset) + "px";
}

function closeHelpMenu(menu) {
	//menu.className='button_left_normal'; 
	var img=menu.getElementsByTagName('div').item(0).getElementsByTagName('img').item(0);
	img.src='images/submenu_help_normal.jpg';
	menu.getElementsByTagName('div').item(1).className='dropdown_hidden';
}

function openMyAccountMenu(menu) {
	var offset=0;
	if(navigator.userAgent.indexOf("Chrome")>-1) {
		offset=-1;	
	}
	else if(navigator.userAgent.indexOf("Safari")>-1) {
		offset=2;	
	}
	
	var area=getobj(menu);
	var img=menu.getElementsByTagName('div').item(0).getElementsByTagName('img').item(0);
	var dropdown=menu.getElementsByTagName('div').item(1);
	dropdown.className='dropdown_visible';	
	dropdown.style.left=area[0]+78+"px";
	dropdown.style.top=((area[1] + area[3]) + offset -2) + "px";
}

function closeMyAccountMenu(menu) {
	var img=menu.getElementsByTagName('div').item(0).getElementsByTagName('img').item(0);
	menu.getElementsByTagName('div').item(1).className='dropdown_hidden';
}


// Removes leading whitespaces
function ltrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function rtrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return ltrim(rtrim(value));
	
}

function setcheckboxes() {
	var chkAll=document.getElementById("chkAll");
	var chkStatus=document.getElementsByTagName("input");
	var intPos;
	
	for(intPos=0;intPos<chkStatus.length;intPos++) {
		if(chkStatus[intPos].type=="checkbox") {
			if(chkStatus[intPos].name!="chkAll") {
				chkStatus[intPos].checked=chkAll.checked;
			}
		}
	}
}

function setlength(user_word,set_length) {
	if(user_word.length>set_length) {
		var new_word=user_word.substr(1,set_length-3);
		new_word=new_word+"...";
		return new_word;
	}
}

//check for numbers in a field
// if comma, period or hyphen has to be allowed: call function checkNumeric(this,-5,5000,',','.','-')
//if none of the above has to allowed: call function checkNumeric(this,5,60,'','','') 

function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
	// only allow 0-9 be entered, plus any values passed
	// (can be in any order, and don't have to be comma, period, or hyphen)
	// if all numbers allow commas, periods, hyphens or whatever,
	// just hard code it here and take out the passed parameters
	var checkOK = "0123456789" + comma + period + hyphen;
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	for (i = 0;  i < checkStr.value.length;  i++)
	{
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
			allNum += ch;
	}

	if (!allValid)
	{	
//		alertsay='Please enter only numeric values';
//		alertsay = "Please enter only these values \""
//		alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
//		alert(alertsay);
		return (false);
	}

			// set the minimum and maximum
//			var chkVal = allNum;
//			var prsVal = parseInt(allNum);
//			if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
//			{
//				alertsay = "Please enter a value greater than or "
//				alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
//				alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
//				alert(alertsay);
//				return (false);
//			}
}

function removedefaultlabel(parentObject, setlabel){
	var objects;
	if(!parentObject) { //within one document
		objects = document.getElementsByTagName("input");
	}
	else if(parentObject.elements) { //within form
		objects = parentObject.elements;
	}
	else {
		objects = parentObject.getElementsByTagName("input"); 
	}

	for(index=0;index<objects.length;index++){
		if(objects[index].type == "text"){
			if((objects[index].className == "hint1")||(objects[index].className == "hint2")){
				if(!setlabel){
					objects[index].value = "";
				}
				else{
				    objects[index].onblur();
				}
			} //if end
		} //if end
	} //for end
}// function end

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	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 getFlashUploader(){
	var Flash;
	if(document.embeds && document.embeds.length>=1 && navigator.userAgent.indexOf("Safari") == -1)
		Flash = document.getElementById("EmbedFlashFilesUpload");
	else
		Flash = document.getElementById("FlashFilesUpload");
	
	return Flash;
}

function getElement(aID)
	{
		return (document.getElementById) ?
			document.getElementById(aID) : document.all[aID];
	}
    
    
function getIFrameDocument(aID){ 
	var rv = null; 
	var frame=getElement(aID);
	// if contentDocument exists, W3C compliant (e.g. Mozilla) 

	if (frame.contentDocument)
		rv = frame.contentDocument;
	else // bad IE  ;)

		rv = document.frames[aID].document;
	return rv;
}


function ValidateEMail(objName)

{



     //Purpose     : This function is used to validate email. 

     //Arguments : Email object

          

     var sobjValue;

     var iobjLength;

     

     sobjValue=objName;

     iobjLength=sobjValue.length;

     iFposition=sobjValue.indexOf("@");

     iSposition=sobjValue.indexOf(".");

     iTmp=sobjValue.lastIndexOf(".");     

     iPosition=sobjValue.indexOf(",");

     iPos=sobjValue.indexOf(";");

     

     if (iobjLength!=0)

     {

          if ((iFposition == -1)||(iSposition == -1))

          {

               return false;

          }

          else if(sobjValue.charAt(0) == "@" || sobjValue.charAt(0)==".")

          {

               return false;                    

          }

          else if(sobjValue.charAt(iobjLength) == "@" ||

sobjValue.charAt(iobjLength)==".")

          {

               return false;                    

          }     

          else if((sobjValue.indexOf("@",(iFposition+1)))!=-1)

          {     

               return false;

          }

          else if ((iobjLength-(iTmp+1)<2)||(iobjLength-(iTmp+1)>3))

          {

               return false;

          }

          else if ((iPosition!=-1) || (iPos!=-1))

          {

               return false;

          }

          else

          {

               return true;

          }          

     }          

}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function checkHTMLText(obj) {
//	alert(obj.length);
	for (var i=0; i < obj.length; i++) {
//		alert(obj.elements[i].type);
		if(obj.elements[i].type == 'text' || obj.elements[i].type == 'textarea' || obj.elements[i].type == 'hidden') {
			var title = String(obj.elements[i].value); //text box content
			if(title.search(/>/)>=0 || title.search(/</)>=0) { //< or > found in title
				return false;
			}
		}
	}
	
	return true;
}



function alphanumeric(alphane)
{
	var numaric = new String;
	numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh > 31 && hh < 33) || (hh > 44 && hh < 46))
		  {
		  }
		  else{
             return false;
		  }
 		}
 
 return true;
}

