function viewBigImage(name,w,h)
{
    var delta_h = isNaN(window.screenY) ? 30 : 55;
    var delta_w = 10;

    var Settings = "toolbar=no, directories=no, location=no, width="+w+", height="+h+", left=200, top=150, status=no, scrollbars=no, resize=yes, resizable=yes";
    var myWindow = window.open ("",null,Settings);
    myWindow.focus();
    
    myWindow.document.write ('<html><head><title>Pro Tec</title><script>'+
    'function ResizePopup(obj,dw,dh){'+
    'var rw = obj.width + dw;'+
    'var rh = obj.height + dh;'+
    'window.resizeTo(rw + 30, rh + 50);' +
    '}</script></head><body style="margin:0px" onClick="window.close();"><center>'+
      '<img src="'+name+'" border="0" onload="ResizePopup(this,'+delta_w+','+delta_h+')">' +
      '</center></body></html>');
    myWindow.document.close();
}

function openPopup(url, name, width, height)
{
	var oTarget = window.open(url, name, 'scrollbars=no, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
	oTarget.focus();
	return false;
}

function openScrolledPopup(url, name, width, height)
{
	var oTarget = window.open(url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
	oTarget.focus();
	return false;
}

function HideControl( id )
{
	document.getElementById( id ).style.display = 'none';
}

function ShowControl( id )
{
	document.getElementById( id ).style.display = 'inline';
}

function nextFieldFocus(curObj, prevObj, nextObj, length, event)
{
	if( event.keyCode == '37' || event.keyCode == '39' )
	{
		return;
	}
  if(nextObj != null && curObj.value.length == length && event.keyCode != '9' && event.keyCode != '16')
  {
    nextObj.focus();
    nextObj.select();
  }
  if(event.keyCode == '8' && curObj.value.length == 0)
  {
    prevObj.focus();
    rng = prevObj.createTextRange(); 
    rng.collapse(false); 
    rng.select(); 
    prevObj.click(); 
  }
}


function newImage(arg)
{
	if (document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages()
{
	if (document.images)
	{
		for (var i=0; i<changeImages.arguments.length; i+=2)
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

//************************************************************* 
function Trim (str)  
{ 
	return RTrim(LTrim(str)); 
} 
//************************************************************* 	
function LTrim (str) { 
var ret_str = str; 
for (var i=0; i<str.length; i++){ 
	if (str.charAt(i) == ' ') {;} 
	else  
	{ 
		ret_str = str.substring(i); 
		return ret_str; 
	} 
} 
ret_str=''; 
return ret_str; 
} 
//************************************************************* 
function RTrim (str) { 
	var ret_str = str; 
	for (var i=(str.length-1); i>=0; i--) 
	{ 
		if (str.charAt(i) == ' ') {;} 
		else  
		{ 
			ret_str = str.substring(0,(i+1)); 
			return ret_str; 
		} 
	} 
	ret_str=''; 
	return ret_str; 
} 
//************************************************************* 
function RowIllyminate(obj, Class)
{
	obj.className = Class;
}

//**************************************************

/********************** AJAX XMLHttp **************************/
function createXMLHttp() {
  if(typeof XMLHttpRequest != "undefined") { // for Mozilla
    //alert("XMLHttpRequest library for mozilla!");
    return new XMLHttpRequest();
  } 
  else if(window.ActiveXObject) { // for Internet Explorer (all versions)
    var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
    for (var i = 0; i < aVersions.length; i++) {
      try { //
        var oXmlHttp = new ActiveXObject(aVersions[i]);
        //alert(aVersions[i]); 
        return oXmlHttp;
      } 
      catch (oError) { }
    }
    throw new Error("Cannot create object XMLHttp.");
  }
}
// how to use
//var oXmlHttp = createXMLHttp();


function reposition(id, text)
{
			if (!text) text = 'Loading...';
				
			var tblLoader = document.getElementById(id);  
			if (!tblLoader) return;
			
			var lblLoader = tblLoader.getElementsByTagName("label");
			if (lblLoader.length>0){
				lblLoader = lblLoader[0];
				lblLoader.innerHTML = text;
			}
			
			tblLoader.style.top = document.body.clientHeight/2 + document.body.scrollTop + "px"; 
			//alert(document.body.clientHeight);
			//alert(tblLoader.style.top);
			//tblLoader.style.left = elem.clientWidth/2 + document.documentElement.scrollLeft + "px";
			
			if (isie)
			{
				if (document.documentElement.offsetWidth > document.body.clientWidth)
					tblLoader.style.left = "50%";
				else
					tblLoader.style.left = document.documentElement.offsetWidth/2 + document.documentElement.scrollLeft + "px";
			}
			else
			{
					var elem = document.getElementById('content');
					tblLoader.style.top = window.innerHeight/2 - elem.offsetTop + document.documentElement.scrollTop + "px"; 
					tblLoader.style.left = window.innerWidth/2 - elem.offsetLeft + document.documentElement.scrollLeft + "px";
			}
			//alert(tblLoader.style.top);
}



/*****************************************************/
/*
function hide_send_request(btn)
{
	if (typeof(Page_ClientValidate) == 'function') 
		Page_ClientValidate('');

	if (!Page_BlockSubmit)
	{
		$("#buttons").hide();
		
		var loading = $("#divLoading");
		loading.css("left", $(".main").get(0).offsetLeft + 200 + "px");
		loading.css("top", "350px");
		$("#divLoading").fadeIn(100);
		
		var form = $("#frmRequest");
		form.fadeOut("slow",
			function(){
					SendRequest(get_result);
			} );
	}
}
function get_result(ret)
{
		$("#divLoading").hide();
		
		if(ret.error)
		{
			alert(ret.error);
			$("#buttons").show();
			form.show();
			return;
		}
		
		if (!ret.value)
		{
			$("#divStatus").show();
		}
		else
		{
			alert(ret.value);
			$("#buttons").show();
			form.show();
		}
		
}
*/

function getRequestParams(context) {
	var aParams = new Array();
  $(":input[type=text],:hidden,textarea", context).each(function (i) {
			var obj = $(this);
			var sParam = obj.attr("id") ? obj.attr("id") : obj.attr("name");
			if (sParam){
				sParam += "=" + this.value;
				aParams.push(sParam);
			}
    });	
  aParams.push("submit=Submit");
  return aParams;// aParams.join("&");
}


function post_click2(btn, action)
{
	action = action ? action : "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
	
	$("#divStatus").text("").hide();	
	
	$("#divLoading").bind("ajaxSend", function(){
		$(this).fadeIn("slow");
		$("#frmRequest").fadeOut("slow");
		$("#buttons").hide();
	}).bind("ajaxComplete", function(){
		$(this).fadeOut("slow");
		$("#frmRequest").fadeIn("slow")
		$("#buttons").show();
	});
	
		if (typeof(Page_ClientValidate) == 'function') 
			Page_ClientValidate('');
		
		if (!Page_BlockSubmit)
		{
				var params = {};

				var form = $("#frmRequest");
				$("input:text,input:hidden,input:submit",form).each(function() {
					var obj = $(this);
					params[ encodeURIComponent(obj.attr("attr") ? obj.attr("attr") : this.name) ] = this.value;
				});
				
				$("#divLoading").css("left", $(".main").get(0).offsetLeft + 200 + "px").css("top", "350px");
				
				try 
				{
					//$.post(action, params,
					$.get(action, params,
						function(data, textStatus){
							//alert(textStatus);
							//alert("Data Loaded: " + data);
							if (textStatus=='success')
							{
								;//__doPostBack(btn.name,data);
							}
							else
							{
								$("#divStatus").text(data).show();
							}
						});
				
				} 
				catch (e) 
				{
							$("#divLoading").hide();
							$("#frmRequest").show();
							
							$("#divStatus").text(e.message).show();
							$("#buttons").show();	
					return;
	      }
		}
}
function post_click(btn, action)
{
	action = action ? action : "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
	
	$("#divStatus").text("").hide();
		if (typeof(Page_ClientValidate) == 'function') 
			Page_ClientValidate('');
		
		if (!Page_BlockSubmit)
		{
				$("#buttons").hide();

				var form = $("#frmRequest");
				var sBody = getRequestParams(form);
				var oXmlHttp = createXMLHttp();
			  
			  
			 // alert(action);
			  
				try 
				{
					oXmlHttp.open("POST",action, true);
					//oXmlHttp.open("POST",action, true);
					oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				  
					oXmlHttp.onreadystatechange = function() {
						if(oXmlHttp.readyState == 4) {
							if(oXmlHttp.status == 200) {
								getResult(oXmlHttp.responseText, btn, 0);
							} else {
								getResult("Error: " + oXmlHttp.statusText, btn, 1);
							}
						}
					};
					
					oXmlHttp.send(sBody);
				} 
				catch (e) 
				{
					getResult("Error: " + e.message, btn, 1);
					return;
	      }
		  
				var loading = $("#divLoading");
				loading.css("left", $(".main").get(0).offsetLeft + 200 + "px");
				loading.css("top", "350px");
				loading.fadeIn(100);
				$("#frmRequest").fadeOut(100);
		}
}



function getResult(sText, btn, isError) {
	$("#divLoading").fadeOut("slow");
	$("#frmRequest").fadeIn("slow");
	
	if (!isError)
	{
		if (btn)	__doPostBack(btn.name,'');
	}
	else
	{
		$("#divStatus").text(sText).show();
	}
	
	$("#buttons").show();	
	
  //var sElem = document.getElementById("divStatus");
  //sElem.innerHTML = sText;
}
/***************************************************/
