// COPYRIGHT SITESPIRIT BLADERBROCHURE BROWCHURE

function showPassword(id)
{
    var i = document.getElementById(id);
    if(i) {
        var tp = i.type;
        if(tp && tp == 'password') {
            i.type = 'text';
        } else if(tp) {
            i.type = 'password';
        }
    }
}

function getFile(method, url, vars, goal, asyn) 
{
    if (url==''||url==self.location) return //[];
    switch(typeof ActiveXObject) {
    	case 'function':
      		httpRequest = new ActiveXObject('Microsoft.XMLHTTP'); 
      		break;
	    default:  
    		httpRequest = new XMLHttpRequest;  
  		}
    var link = '';
    if(method == 'GET') {
        url = url+'?'+vars;
        httpRequest.overrideMimeType("text/xml");
    }

    httpRequest.onreadystatechange = function() { getRespons(httpRequest, goal); };
    httpRequest.open(method, url, asyn); // third is for asynchronism...
    if(method == 'POST') {
        link = vars;
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        httpRequest.setRequestHeader("Content-Length", link.length);
    }
    httpRequest.send(link);
    if(!asyn) {
        return httpRequest.responseText;
    }
}

function getRespons(httpRequest, goal) 
{
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
			if(goal == 'jsvar') {
				return httpRequest.responseText;
			} else if(httpRequest.responseText.substr(0,6) == 'error:') {
                alert( httpRequest.responseText );
            } else if(goal.nodeName && goal.nodeName.toLowerCase()=='input') {
                goal.value = httpRequest.responseText;
            } else if(goal && goal.nodeName) {
                goal.innerHTML = httpRequest.responseText;
            } else if(httpRequest.responseText.substr(0,7) == 'alert: ') {
				var text = httpRequest.responseText.substr(7, httpRequest.responseText.length-7 );
				alert( text );
			} else return;
        } else {
            alert( 'There was a problem with the request.' );
        }
    }
}

 function walkbrochure()
 {
	var interval = setInterval(function(){
		k = document.getElementById('loadingbrochure');
		i = getFile('POST','/crupdax.php','', 'jsvar', 0);
	    if(i != '0') {
			var html = '';
			json = eval('(' + i + ')');
			// BUILD VIEW
			if(json.img) {
				json.img.pre = new Image();
				json.img.pre.src = json.img.src;
			}
			if(json.img.type == 'jpg') {
				html += '<a class="my-brochures-links" href="'+json.link+'" ><img src="'+json.img.src+'" style="width:100px" /></a><br />';
			} else if(json.img.type == 'swf')  {
				html += '<div class="thumbdiv" >';
				html += '<div id="'+json.img.rand+'"></div>';
				html += '</div><br /><br />';
			}
			html += '<p><a class="my-brochures-links" href="'+json.link+'" >'+json.name+'</a></p>';
			if(k.innerHTML != html) {
				k.innerHTML = html;
			
				if(json.img.type == 'swf') {
					var so = new SWFObject( '/swf2url.swf', '', json.img.width, json.img.height, '8', '');
					so.addVariable("mylink", json.link );
					so.addVariable("myswf", json.img.src);
					so.addVariable("mywidth", json.img.width );
					so.addVariable("myheight", json.img.height );
					so.write( json.img.rand );
				}
			}
			if(json.stat == 'ready') {
				clearInterval(interval);
			}
		}
	}, 1000);
}

function removeDefault(e) {
	if(window.event) {
		window.event.returnValue = false;
	} else if(e && e.preventDefault) {
		e.preventDefault();
	}
}

function cancelClickSafari() {
	return false;
}

function addListeners(e) {

}

function addEvent(elm, evType, fn, useCapture)
// cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew
{
	if(elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		eval(elm+'.on'+evType+' = fn');
	}
}

function getEventTarget(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) {
	    targ = e.target;
	} else if (e.srcElement) {
	    targ = e.srcElement;
	}
	if (targ.nodeType == 3) { // defeat Safari bug
		targ = targ.parentNode;
	}
	return targ;
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}