function preload(images) {
    if (document.images) {
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
            imageObj.src=images[i];
        }
    }
}

//-------------------------------------
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}


//-----------------------
function onloading(div) {
	document.getElementById(div).style.display = "inline";
}

//-----------------------
function stoploading(div) {
	document.getElementById(div).style.display = "none";
}



//-------------------------------------
function AJAX(){

	try {
		xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		return xmlHttp;
		
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
			return xmlHttp;
			
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			} catch (e) {
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
}


//----------------------------------
function checknsend() {
	
	onloading('spinner');
	
	var xmlHttp_one = AJAX();
	
	xmlHttp_one.onreadystatechange = function(){
		if(xmlHttp_one.readyState == 4){
			data = xmlHttp_one.responseText.split('[]');
			document.getElementById('error').innerHTML = data[0];
			document.getElementById('caution1').innerHTML = data[1];
			document.getElementById('caution2').innerHTML = data[2];
			document.getElementById('caution3').innerHTML = data[3];
			document.getElementById('caution4').innerHTML = data[4];
			document.getElementById('caution5').innerHTML = data[5];
			
			if(data[0] == 'good') {
				document.getElementById('thanks').innerHTML = data[6];
			}
			
			stoploading('spinner');
		}
	}
	
	var ct_name = document.getElementById('ct_name').value;
	var ct_email = document.getElementById('ct_email').value;
	var ct_subject = document.getElementById('ct_subject').value;
	var ct_enquiry = document.getElementById('ct_enquiry').value;
	var veri_user = document.getElementById('veri_user').value;
	var veri_ori = document.getElementById('veri_ori').value;
	
	var url = 'contact_send.php';
	var param = '?name=' + ct_name + '&email=' + ct_email + '&subject=' + ct_subject + '&enquiry=' + ct_enquiry + '&veri_user=' + veri_user + '&veri_ori=' + veri_ori;
	
	xmlHttp_one.open('GET', url+param, true);
	xmlHttp_one.send(null);
	
	event.preventDefault();
}

//-----------------------
function checkajax() {
	
	alert("READY SUCKER!");
	
}


