//==============================================================================
//==============================================================================
function GetXmlHttpObject(handler)
{
      var xmlHttp = null;
      if (window.XMLHttpRequest) 
      { // Mozilla, Safari,...
         xmlHttp = new XMLHttpRequest();
         if(xmlHttp.overrideMimeType) 
         {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            xmlHttp.overrideMimeType('text/html');
         }
      } 
      else if (window.ActiveXObject) 
      { // IE
         try 
         {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
         } 
         catch (e) 
         {
            try 
            {
               xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
            	
            }
         }
      }
      return xmlHttp;
}
//==============================================================================
//==============================================================================
function CalculateOneItemAnnotationHeight()
{
	var viewportwidth;
 	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		//viewportwidth  = window.innerWidth,
		viewportheight = window.innerHeight
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
			&& typeof document.documentElement.clientWidth !=
			'undefined' && document.documentElement.clientWidth != 0)
	{
		//viewportwidth  = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	
	// older versions of IE
	else
	{
		//viewportwidth  = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}

	var my_height = 150 + 2 + 2 + 2;
	var one_item_height = Math.floor((viewportheight - my_height)/2) - 2;
	
	return one_item_height;
}
//==============================================================================
//==============================================================================
function SetOneItemAnnotationHeight(short_id, num)
{
	var one_item_height = CalculateOneItemAnnotationHeight();
	
	for(var i = 1; i <= num; i++)
	{
		var element_id = short_id+'_'+i;
		
		if(document.getElementById(element_id) != null)
		{
			document.getElementById(element_id).style.height = one_item_height+'px';
		}
	}
}
//==============================================================================
//==============================================================================
function SwapImageSrc(img_name, img_src)
{
	if(document.images[img_name] != null)
	{
		document.images[img_name].src=img_src;
	}
}
//==============================================================================
function ChangeElementClassName(element_id, new_class_name)
{
	if(document.getElementById(element_id) != null)
	{
		document.getElementById(element_id).className = new_class_name;
	}
}
//==============================================================================
//==============================================================================
function ChangeOnlyAction(my_action)
{
	location = my_action;
}
//==============================================================================
//==============================================================================
function CreateMainPagePath(div_id, my_str)
{
	if(document.getElementById(div_id) != null)
	{
		document.getElementById(div_id).innerHTML = my_str;
	}
}
//==============================================================================
//==============================================================================
function ClearContactForm()
{
	var arr_element_id = new Array("full_name", "phone", "email", "message");
	var i = 0;
	
	for(i in arr_element_id)
	{
		if(document.getElementById(arr_element_id[i]) != null)
		{
			document.getElementById(arr_element_id[i]).value = "";
		}
	}
}
//==============================================================================
function SendContactForm()
{
	var arr_element_id   = new Array("full_name", "phone", "email", "message");
	var arr_element_data = new Array();
	var i = 0;
	
	for(i in arr_element_id)
	{
		if(document.getElementById(arr_element_id[i]) == null)
		{
			return;
		}
		else
		{
			var my_str = ''+arr_element_id[i]+'='+document.getElementById(arr_element_id[i]).value+'';
			arr_element_data.push(my_str);
		}
	}
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var params = arr_element_data.join("&");
	var my_url = 'objects/contact_us_ajax_inc.php';
	
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var temp_arr = xmlHttp.responseText.split("|");
			
			if(temp_arr.length == 1)
			{
				alert(temp_arr[0]);
			}
			else if(temp_arr.length == 2)
			{
				alert(temp_arr[1]);
				
				if(temp_arr[0] == '1')
				{
					ClearContactForm();
				}
			}
		}
	}
	
	xmlHttp.open('POST', my_url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
//==============================================================================
//==============================================================================
