//*****************MAIN GET OBJECT FUNCTION*****************************
function getXMLHttpObject() {
	var xmlHttp = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {xmlHttp = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {xmlHttp = new XMLHttpRequest();}
		catch (e) {xmlHttp = false;}
	}
	return xmlHttp;
}

//*****************SWAP IMAGE GET FUNCTION *****************************
function change_image(type,ajax_where,ajax_select,ajax_table)
{
  var xmlHttp = getXMLHttpObject();
  xmlHttp.onreadystatechange = function()
  {

	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (type == "mr")  {
   change_image_act(xmlHttp.responseText);
} else if (type == "rb_a")  {
   rb_change_image_act_a(xmlHttp.responseText);
} else if (type == "rb_b")  {
   rb_change_image_act_b(xmlHttp.responseText);
} else if (type == "rb_c")  {
   rb_change_image_act_c(xmlHttp.responseText);
} else if (type == "rb_d")  {
   rb_change_image_act_d(xmlHttp.responseText);
}

    }
  } 

	var url = "../O/inc/modules/mini_rotator/mr_get_image.php?mr_table=" + ajax_table + "&mr_where=" + ajax_where +  "&mr_select=" + ajax_select + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

//*****************STUPID JOINER FUNCTIONS *****************************
function tool_fade_over_a(php_data)  {
rotate_pause('interval_b');
build(this, php_data);
}
function tool_fade_out_a(php_data)  {
rotate_resume('interval_b');
hide(this, php_data);
}
function tool_fade_over_b(php_data)  {
rotate_pause('interval_c');
build(this, php_data);
}
function tool_fade_out_b(php_data)  {
rotate_resume('interval_c');
hide(this, php_data);
}
//*****************TOP SWAP IMAGE FUNCTION *****************************
function change_image_act(response)  {
var php_data = response.split(','); 
FadeInImage('mr_img_id',php_data[1],'mini_rotator_block_id');
	document.getElementById('mr_title_id').innerHTML = php_data[2];
}

//*****************RIGHTBAR a SWAP IMAGE FUNCTION *****************************
function rb_change_image_act_a(response)  {
var php_data = response.split(','); 
var sql_id = document.getElementById('last_id').innerHTML;
if (php_data[0] == sql_id)  {
change_image("rb_a");
} else {
FadeInImage('rb_image_id_a',php_data[1],'clear');
	document.getElementById('rb_title_id_a').innerHTML = php_data[2];
	document.getElementById('rb_caption_id_a').innerHTML = php_data[3];
	document.getElementById('rb_caption_id_a').innerHTML = php_data[3];
			document.getElementById('rb_link_id_a').onmouseover = function() {tool_fade_over_a(php_data[4]);};
			document.getElementById('rb_link_id_a').onmouseout = function() {tool_fade_out_a(php_data[4]);};
}
	document.getElementById('last_id').innerHTML = php_data[0];
}

//*****************RIGHTBAR b SWAP IMAGE FUNCTION *****************************
function rb_change_image_act_b(response)  {
var php_data = response.split(','); 
var sql_id = document.getElementById('last_id').innerHTML;
if (php_data[0] == sql_id)  {
change_image("rb_b");
} else {
FadeInImage('rb_image_id_b',php_data[1],'clear');
	document.getElementById('rb_title_id_b').innerHTML = php_data[2];
	document.getElementById('rb_caption_id_b').innerHTML = php_data[3];
//			document.getElementById('rb_link_id_b').onmouseover = function() {tool_fade_over_b(php_data[4]);};
//			document.getElementById('rb_link_id_b').onmouseout = function() {tool_fade_out_b(php_data[4]);};
}
	document.getElementById('last_id').innerHTML = php_data[0];
}


//*****************PAUSE IMAGE FUNCTION*****************************
function rotate_pause(interval)  {
if (interval == "interval_a")  {
clearInterval(interval_a);
}
if (interval == "interval_b")  {
clearInterval(interval_b);
}
if (interval == "interval_c")  {
clearInterval(interval_c);
}
}
//*****************RESUME IMAGE FUNCTION*****************************
function rotate_resume(interval)  {
if (interval == "interval_a")  {
interval_a = setInterval('change_image("mr","","id,title_text,thumbname","virtual_tour")', 9000);
}
if (interval == "interval_b")  {
interval_b = setInterval('change_image("rb_a","","id,title_text,body_textarea,thumbname,image_caption_text","retail_store")', 12000);
}
if (interval == "interval_c")  {
interval_c = setInterval('change_image("rb_b","","id,title_text,body_textarea,thumbname,image_caption_text","retail_store")', 12000);
}
}


//*****************PARSE JAVASCRIPT FROM AJAX RESPONSE*****************************
function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
 
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
 
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
 
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
			alert(source);	// do what you want here when a script fails
			}
		}
		// Return the cleaned source
		return source;
}

//*****************AJAX AUTO PAGINATION FOR MAIN_CONTENT*****************************
function format_content(set_table,set_where,set_order,set_sort,set_limit,content_type,set_perpage,current_page,p_container)
{
  var xmlHttp = getXMLHttpObject();

  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading_fc();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)  {
      load_content(xmlHttp.responseText,p_container);
    }
  } 

var url = "../O/inc/structure/shells/hoda_dark/main_content.php?set_table=" + set_table + "&set_order=" + set_order + "&set_sort=" + set_sort + "&set_limit=" + set_limit + "&set_perpage=" + set_perpage + "&set_where=" + set_where + "&content_type=" + content_type + "&page=" + current_page  + "&p_container=" + p_container + "&rnd=" + Math.random(); 
	
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

//*****************RELOAD CONTENT_LEFT USING MAIN_CONTENT AJAX RESPONSE*****************************
function load_content(response,p_container)  {
if (p_container == "") { p_container = 'content_left'; }
	document.getElementById(p_container).innerHTML = parseScript(response);
	document.getElementById('loading_mc_id').className="hidden_content";
    }
//*****************LOADING FOR MAIN_CONTENT*****************************
function loading_fc()  {
	document.getElementById('loading_mc_id').className="display_content";
}

//*****************SEARCH FUNCTION*****************************
function show_hide_search()  {
	document.getElementById('top_search').className="display_content";
}

//*****************FADE IN OUT FUNCTION*****************************
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage;
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,50)",10);
}

//RECAPTCHA SETTINGS
var RecaptchaOptions = {
   theme: 'blackglass',
   lang: 'en'
};
