function getHTTPObject()
{
var http = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http = new XMLHttpRequest();
if (http.overrideMimeType) {
http.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return http;
}
var base_url = "http://www.alpenacvb.com/";
var base_photo_cat = "http://www.alpenacvb.com/photo-gallery-53/";
function update( id )
{
dhtmlHistory.add("photoId", id);
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-photo-get.js";
http.open("GET",base_url + id + url,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText.split("|");
document.getElementById('photo-description').innerHTML = results[0];
document.getElementById('photo-title').innerHTML = results[1];
document.getElementById('main-photo').src = results[2];
document.getElementById('sendPhoto').style.display = '';
}
}
http.send(null);
}
function reset_gallery( photo_id )
{
dhtmlHistory.remove("mainPhotoGroup");
dhtmlHistory.add("mainPhotoGroup", photo_id);
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-photo-category.js";
http.open("GET",base_url + photo_id + url,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText.split("|");
document.getElementById('photo-description').innerHTML = '
How to use the gallery blah blah blah!
';
document.getElementById('photo-title').innerHTML = 'Photo Gallery';
document.getElementById('main-photo').src = base_url + 'assets/photo-default.jpg';
document.getElementById('sendPhoto').style.display = 'none';
document.getElementById('photo-gallery-thumbnails').innerHTML = results[3];
}
}
http.send(null);
}
function send_photo()
{
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-postcard.js";
var imageString = document.getElementById('main-photo').src;
http.open("GET",base_url + url + '?image=' + imageString,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText;
document.getElementById('photo-gallery').innerHTML = results;
}
}
http.send(null);
}
var chkDot = true;
var usEmail = true;
function validEmail(eAddr)
{
var lenSuffix = (usEmail) ? 4: 3;
var goodAddr = false;
var ndxAt = ndxDot = 0;
ndxAt = eAddr.indexOf("@");
ndxDot = eAddr.indexOf(".");
ndxDot2 = eAddr.lastIndexOf(".");
if ( (ndxDot < 0) || (ndxAt < 0) )
return(goodAddr);
else if (chkDot && (ndxDot < ndxAt) )
return(goodAddr);
else if ( (ndxDot2 - 3) <= ndxAt)
return(goodAddr);
else if ( eAddr.length < (ndxDot2 + lenSuffix) )
return(goodAddr);
else
goodAddr = true;
return (goodAddr);
}
function goBack()
{
var pForm = document.getElementById('fPreview');
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-postcard.js";
var url_query = '?image=' + pForm.image.value;
url_query += '&s_email=' + pForm.s_email.value;
url_query += '&r_email=' + pForm.r_email.value;
url_query += '&s_name=' + pForm.s_name.value;
url_query += '&r_name=' + pForm.r_name.value;
url_query += '&subject=' + pForm.subject.value;
url_query += '&message=' + pForm.message.value;
url_query += '&rmethod=' + pForm.rmethod.value;
http.open("GET",base_url + url + url_query,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText;
document.getElementById('photo-gallery').innerHTML = results;
}
}
http.send(null);
}
function sendPostcard()
{
var pForm = document.getElementById('fSend');
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-send-postcard.js";
var url_query = '?image=' + pForm.image.value;
url_query += '&s_email=' + pForm.s_email.value;
url_query += '&r_email=' + pForm.r_email.value;
url_query += '&s_name=' + pForm.s_name.value;
url_query += '&r_name=' + pForm.r_name.value;
url_query += '&subject=' + pForm.subject.value;
url_query += '&message=' + pForm.message.value;
url_query += '&rmethod=' + pForm.rmethod.value;
http.open("GET",base_url + url + url_query,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText;
document.getElementById('photo-gallery').innerHTML = results;
}
}
http.send(null);
}
function preview()
{
var pForm = document.getElementById('postcard');
var mess = '';
// check to see if the email addresses are filled in and correct format
if( pForm.s_email.value == '' )
{
mess += 'Senders Email address is empty!\n';
}
else if( !validEmail(pForm.s_email.value) )
{
mess += 'Senders Email address is not in email format!\n';
}
if( pForm.r_email.value == '' )
{
mess += 'Recipient Email address is empty!\n';
}
else if( !validEmail(pForm.r_email.value) )
{
mess += 'Recipient Email address is not in email format!\n';
}
if( mess )
{
alert('Form not Submitted for following reasons:\n' + mess);
return( false );
}
var http = getHTTPObject(); // We create the HTTP Object
var url = "ajax-preview.js";
var url_query = '?image=' + pForm.image.value;
dhtmlHistory.add("preview", pForm.image.value);
url_query += '&s_email=' + pForm.s_email.value;
url_query += '&r_email=' + pForm.r_email.value;
url_query += '&s_name=' + pForm.s_name.value;
url_query += '&r_name=' + pForm.r_name.value;
url_query += '&subject=' + pForm.subject.value;
url_query += '&message=' + pForm.message.value;
if( pForm.rmethod[0].checked == true )
{
url_query += '&rmethod=' + pForm.rmethod[0].value;
}
else if ( pForm.rmethod[1].checked == true )
{
url_query += '&rmethod=' + pForm.rmethod[1].value;
}
http.open("GET",base_url + url + url_query,true);
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
var results = http.responseText;
document.getElementById('photo-gallery').innerHTML = results;
}
}
http.send(null);
}
function addLoadListener(fn)
{
if (typeof window.addEventListener != 'undefined')
{
window.addEventListener('load', fn, false);
}
else if (typeof document.addEventListener != 'undefined')
{
document.addEventListener('load', fn, false);
}
else if (typeof window.attachEvent != 'undefined')
{
window.attachEvent('onload', fn);
}
else
{
var oldfn = window.onload;
if (typeof window.onload != 'function')
{
window.onload = fn;
}
else
{
window.onload = function()
{
oldfn();
fn();
};
}
}
}
function initialize() {
// initialize our DHTML history
dhtmlHistory.initialize();
// subscribe to DHTML history change
// events
dhtmlHistory.addListener( historyChange);
// if this is the first time we have
// loaded the page...
if (dhtmlHistory.isFirstLoad()) {
// start adding history
dhtmlHistory.add("mainPhotoGroup", "1");
}
}
/** Our callback to receive history change events. */
function historyChange(newLocation, historyData) {
var historyMsg = historyData;
if( newLocation == "mainPhotoGroup" || newLocation == '' )
{
document.location.href = base_photo_cat;
}
if( newLocation == "photoId" )
{
goBack();
}
//debugMsg( "A history change has " + "occured: " + "newLocation="+newLocation + ", historyData="+historyMsg);
}
function debugMsg(msg) {
var debugMsg = document.getElementById("debugMsg");
debugMsg.innerHTML = msg;
}
addLoadListener(initialize)