function gradient(id, level)
{
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	
	if(level<0.01)
	{
		   $("span[class^='err']").html("");
		   $("input[type='text']").val("");
		   //$("textarea").val("");
		   $("select").val("");
		   box.style.display='none';
	}
	
	return;
}


function fadein(id) 
{
	var level = 0;
	imgUrl = "captcha/imagebuilder.php?rand="+Math.random();
	var txtSelector = "#" + id + " img[id$='veri_image']";
	var newImage = new Image();
	newImage.src = imgUrl;
	newImage.id = $(txtSelector).attr("id");
	$(txtSelector).replaceWith(newImage);
	
	/*document.getElementById("quote").style.display = 'none';
	document.getElementById("contactusdiv").style.display = 'none';
	document.getElementById("representativeform").style.display = 'none';*/
	
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
	
}

function fadeout(id) 
{
	var level = 0;
	while(level <= 1)
	{
		invLevel = 1-level;
		setTimeout( "gradient('" + id + "'," + invLevel + ")", (level* 1000) + 10);
		level += 0.01;
	}
}

function fadeoutdata(id) 
{
	var level = 0;
	while(level <= 1)
	{
		invLevel = 1-level;
		if(invLevel<0.1)
		break;
		
		setTimeout( "gradient('" + id + "'," + invLevel + ")", (level* 1000) + 10);
		level += 0.01;
	}
}


// Close the lightbox

function closebox(id)
{
   fadeout(id);
}

function closeboxdata(id)
{
   fadeoutdata(id);
}


function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

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 getHTTPObject() {
  var xmlhttp;
  //&& typeof XMLHttpRequest != 'undefined'
  if (!xmlhttp ) {
  	//----------------------------
  	// branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) 
    {
    	try {
			xmlhttp = new XMLHttpRequest();
        } catch(e) {
			xmlhttp = false;
        }
    // branch for IE/Windows ActiveX version
     }
     else if(window.ActiveXObject)
     {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	    }
       catch(e) 
       {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
				}
     }

  	
  
  }
  return xmlhttp;
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getPixelsFromTop(obj){
	if(!obj)
	return;
	
	objFromTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		objParent = obj.offsetParent;
		objFromTop += objParent.offsetTop;
		obj = objParent;
	}
	return objFromTop;
}

function getRadioGroupValue(elm)
{
for( i = 0; i < elm.length; i++ )
{
if( elm[i].checked == true )
return elm[i].value;
}
}


function validate_quote(){
	var quote_name = document.getElementById('quote_name').value;
	quote_name = trim(quote_name);
	if(quote_name == '')
	{
		document.getElementById('quote_name').className = "errorbg";
		alert(quote_name);
	}

	return false;
    };