﻿var path = "/App_Themes/Default/Images/";
var emailExt = "@winghouse.com";

function loadImages() {
    var img = new Image();
	img.src = path + "about-ov.png";
	img = new Image();
	img.src = path + "franchise-ov.png";
	img = new Image();
	img.src = path + "support-ov.png";
	img = new Image();
	img.src = path + "development-ov.png";
	img = new Image();
	img.src = path + "faq-ov.png";
	img = new Image();
	img.src = path + "apply-ov.png";
	img = new Image();
	img.src = path + "home-ov.png";
}

function swapImage(id, img) {
	document.getElementById(id).setAttribute('src', path + img);
}

function ajaxload(url, containerid, condition) {
	try { // Browser object detection
		
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");		
	}
	catch (e){alert(e.description)} // browser doesn't support ajax. handle however you want
	xmlhttp.onreadystatechange = function(){statuschanged(containerid,condition)}; // every time ready status changes, statuschanged() function executes
	xmlhttp.open("GET", url, true); // Usage: open(HTTP method, url, and asynchronous = true or false)
	xmlhttp.send(null); // send the request.
}

function statuschanged(containerid, condition){
	if((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { // readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 4=Completed; status code: 200=OK		
		if(xmlhttp.responseText != "") {
			if(condition == "h") { // populating a hidden field
				document.getElementById(containerid).value = xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'		
			}
			else if(condition == "a") { // if condition is append
				document.getElementById(containerid).innerHTML += xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'		
			}
			else {			
				var html = xmlhttp.responseText.split("[emailExt]");
				var temp = "";
				for(var i=0; i<html.length; i++) {				    
				    temp += html[i];
				    if(i < html.length-1) {
				        temp += emailExt;
				    }
				}
				document.getElementById(containerid).innerHTML = temp; // xmlhttp.responseText object contains the text of 'url'		
			}			
		}
	}
	else { // else, readyState is not yet Completed and status is not yet OK, so here we display loading text
		document.getElementById(containerid).innerHTML = 
		    "<div id='loading'>" +
		        "<div class='left'><img src='/App_Themes/Default/Images/loading.gif' alt='Loading...' /></div>" +
		        "<div class='right'>Loading...</div>" +
		        "<div class='clear'></div>" +
		    "</div>";
	}
}

function goTo(url) {   
    ajaxload(url,"main","");
	//document.getElementById("ctas").style.display = "none";
    if(url.toLowerCase() == "/faq") {
        document.getElementById("ctas").style.display = "block";        
    }
}

function writeEmail(name, domain, ext) {
    at = "@";
    dot = ".";    
    var email = name + at + domain + dot + ext;
    document.write('<a href="mailto:' + email + '" title="' + email + '">' + email + '<\/a>');
}