//**************************************************
// engine.js
//**************************************************
// Main Engine for cStore by Amethyst
// engine.js is Capsule Studio property
//**************************************************
var ajaxRequest;
function ajaxRequestCreate(){	
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
}
function getUrlVars(str){
    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[str];
}
onload=function(){
if (document.getElementsByClassName == undefined) {
	document.getElementsByClassName = function(className)
	{
		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = document.getElementsByTagName("*");
		var results = [];

		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
				results.push(element);
		}

		return results;
	}
}
}
function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
function statushide(){
	document.getElementById('status').style.display="none";
}
function toggleengine(id){
	if(getStyle(id,'display')=="none"){
		document.getElementById(id).style.display="inline";
	}
	else{
		document.getElementById(id).style.display="none";
	}
}
function resizeimage(image, maxwidth, maxheight)
{
     w = image.width;
     h = image.height;
                
    if( w == 0 || h == 0 ){
		image.width = maxwidth;
		image.height = maxheight;
	}
	else if (w > h){
		if (w > maxwidth) image.width = maxwidth;
	}
	else{
		if (h > maxheight) image.height = maxheight;
	} 
	//image.style.marginTop = Math.floor( (image.parentNode.offsetHeight - image.height) / 2 ) + 'px'; 
	//image.style.vertical-align='middle';
	//image.style.verticalAlign = 'middle';
}
function goto (page) {
	if (page != "" ) {
		if (page == "--" ) {
			resetMenu();
		} else {
			document.location.href = page;
		}
	}
	return false;
}
function getUrlContent(url,divid){
	ajaxRequestCreate();
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById(divid).innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}
