var intCurrentPostcard = -1;
var intCurrentPostcardPage;
var intCurrentQuote = -1;

function doLoading() {
	var objNav = document.getElementById('navone');
	objNav.setAttribute('oc',objNav.innerHTML,0);
	objNav.innerHTML = '<img src="images/space.gif" height="1" width="14" style="vertical-align: middle;">loading... hang in there!';
	objNav.style.display = '';
	

}

function doNavShow() {
	var objNav = document.getElementById('navone');
	objNav.innerHTML = objNav.getAttribute('oc');
	objNav = document.getElementById('navtwo');
	objNav.style.display = '';
}

function doPostcardsShow() {
	doTourWindowClose();
	doWorkWithUsHide();
	//Find the baseline of the Iframe, move top of post cards there
	if (bolScrolling) return;
	document.cookie = 'dateViewed=' + Date() + '; expires=31 Dec 2010 23:59:59 GMT;';
	
	var objPostCards = document.getElementById('postcards_frame');
	var objSiteFrame = document.getElementById('site');
	var intTop = posTop(objSiteFrame);
	var intHeight = objPostCards.offsetHeight;

	if (objPostCards.style.filter == 'alpha(opacity=100)') {

		doFade('postcards_frame',100);
	}
	else {

		if (intCurrentPostcard == -1) doPostcardLoadCard(objPostcard['Count']);

		window.parent.doLoginWindowClose();
		window.parent.doContactWindowClose();
		window.parent.doContactThankyouClose();
		window.parent.doPrivacyPolicyClose();
		objPostCards.style.top = (intTop + objSiteFrame.offsetHeight - 2) +  'px';
		objPostCards.style.left = '40px';
		objPostCards.style.filter = 'alpha(opacity=60)';
		objPostCards.style.opacity = .60;
		objPostCards.style.height = '0px';
		objPostCards.style.display = '';
		doMove('postcards_frame', intTop, intHeight);



	}
}

function doPostcardsHide() {
	var objPostCards = document.getElementById('postcards_frame');
	if (objPostCards.style.filter == 'alpha(opacity=100)') doFade('postcards_frame',100);
}

function doPostcardLoadCard(intID) {

	intCurrentPostcard = intID;
	intCurrentPostcardPage = 0;

	//Space the current image
	document.getElementById('postcard_image').src = '/images/space.gif';

	var objPostCard = objPostCardsAry[intID];
	document.getElementById('postcard_heading').innerHTML = objPostCard.Heading;
	document.getElementById('postcard_date').innerHTML = objPostCard.Date;
	document.getElementById('postcard_image').src = objPostCard.Images[0];
	document.getElementById('postcard_text1').innerHTML = objPostCard.Pages[0].Text1;
	document.getElementById('postcard_text2').innerHTML = objPostCard.Pages[0].Text2;

	var objPostcardButtons = document.getElementById('postcard_buttons');
	if (objPostCard.Pages.Count != 0)
		objPostcardButtons.style.display = '';
	 else
		objPostcardButtons.style.display = 'none';
		
	var objPostcardButBack = document.getElementById('postcard_button_back');
	if (intCurrentPostcardPage >= 1)
		objPostcardButBack.style.display = '';
	 else
		objPostcardButBack.style.display = 'none';
		
	var objPostcardButForward = document.getElementById('postcard_button_forward');
	if (intCurrentPostcardPage != objPostCard.Pages.Count)
		objPostcardButForward.style.display = '';
	 else
		objPostcardButForward.style.display = 'none';
		
		
}

function initPostcard(dateDate,strHeading) {
	//builds a postcard object
	var objCard = new Object;
	objCard.Heading = strHeading;
	objCard.Date = dateDate;
	objCard.Images = new Object;
	objCard.Pages = new Object;
	return objCard;
}

function doPostcardImageSwap(intPosToMove) {

	var objPostCards = document.getElementById('postcards_frame');
	if (objPostCards.style.filter == 'alpha(opacity=100)') {

		var objPostCard = objPostCardsAry[intCurrentPostcard];
		if (intPosToMove <= objPostCard.Images.Count) {
			document.getElementById('postcard_image').src = objPostCard.Images[intPosToMove];
			intPosToMove++;
		} else
			intPosToMove = 0;
	}

	setTimeout('doPostcardImageSwap(' + intPosToMove + ');',7000);
}

function doPostcardText(intMod) {
	// move the text to the page indicated by mod

	if (intCurrentPostcard != -1) {
		var objPostCard = objPostCardsAry[intCurrentPostcard];
		var intNewPos;

		intNewPos = intCurrentPostcardPage + intMod ;

		if (intNewPos >= 0 && intNewPos <= objPostCard.Pages.Count) {

			document.getElementById('postcard_text1').innerHTML = objPostCard.Pages[intNewPos].Text1;
			document.getElementById('postcard_text2').innerHTML = objPostCard.Pages[intNewPos].Text2;

			intCurrentPostcardPage = intNewPos;
		}	
	}
	
		
	var objPostcardButBack = document.getElementById('postcard_button_back');
	if (intCurrentPostcardPage >= 1)
		objPostcardButBack.style.display = '';
	 else
		objPostcardButBack.style.display = 'none';
		
	var objPostcardButForward = document.getElementById('postcard_button_forward');
	if (intCurrentPostcardPage != objPostCard.Pages.Count)
		objPostcardButForward.style.display = '';
	 else
		objPostcardButForward.style.display = 'none';
}


function getCookie (name) {
  	var arg = name + "=";
  	var alen = arg.length;
  	var clen = document.cookie.length;
  	var i = 0;
  	while (i < clen) {
    	var j = i + alen;
    	if (document.cookie.substring(i, j) == arg)
      		return getCookieVal (j);
    	i = document.cookie.indexOf(" ", i) + 1;
    	if (i == 0) break; 
  	}
  	return 0;
}


function getCookieVal (offset) {
  	var endstr = document.cookie.indexOf (";", offset);
  	if (endstr == -1) endstr = document.cookie.length;
  	return unescape(document.cookie.substring(offset, endstr));
}

function doFade(strID,intOpacity) {
	intOpacity = intOpacity - 10;
	var objFade = document.getElementById(strID);
	if (intOpacity != 0) {
		objFade.style.filter = 'alpha(opacity=' + intOpacity + ')';
		objFade.style.opacity = intOpacity/100;
	 	setTimeout('doFade(\'' + strID + '\',' + intOpacity + ');',4);
	} else {
		//move it off canvas
		objFade.style.top = '-600px';
		objFade.style.left = '-250px';
	}
}

function doMove(strID, intTargetTop, intOH) {
	bolScrolling = true;
	var objMove = document.getElementById(strID);
	var intCurrentTop = posTop(objMove);
	if (intCurrentTop > intTargetTop) {
		objMove.style.top = (intCurrentTop - 5) + 'px';
		objMove.style.height =  (objMove.offsetHeight + 5) + 'px';
	}
	if ((intCurrentTop - 5) > intTargetTop )
		setTimeout('doMove(\'' + strID + '\',' + intTargetTop + ',' + intOH + ');', 1);
	else  {
		objMove.style.top = intTargetTop + 'px';
		objMove.style.height =  intOH + 'px';
		objMove.style.filter = 'alpha(opacity=100)';
		objMove.style.opacity = 1;
		bolScrolling = false;
	}
}

function doContactWindow(evt,strProduct) {
	doLoginWindowClose();
	doContactThankyouClose();
	var e = (window.event) ? window.event : evt;

	var objContactDiv = document.getElementById('contact_frame');
	var objContactProduct = document.getElementById('product');
	objContactDiv.style.top =  228 + 'px';
	objContactDiv.style.left = 70 + 'px';
	var intOW = objContactDiv.offsetWidth;
	objContactDiv.style.width = '0px';
	objContactDiv.style.display = '';
	objContactProduct.value = strProduct;
	switch(strProduct) {
		case 'campaignlogic':
			doColor('contact_frame','#00cc00');
			break;
		case 'adlogic':
			doColor('contact_frame','#ff00cc');
			break;
		case 'shopperlogic':
			doColor('contact_frame','#01a3d9');
			break;
		default: break;
	}
	doReveal(objContactDiv.id,intOW);
	e.cancelBubble = true;
}

function doContactWindowClose() { var objContactDiv = document.getElementById('contact_frame'); objContactDiv.style.top = '-500px'; objContactDiv.style.left = '-500px';}

function doPrivacyPolicy(evt) {
	doLoginWindowClose();
	doContactThankyouClose();
	var e = (window.event) ? window.event : evt;

	var objPrivacyDiv = document.getElementById('privacypolicy_frame');

	objPrivacyDiv.style.top =  60 + 'px';
	objPrivacyDiv.style.left = 40 + 'px';
	var intOW = objPrivacyDiv.offsetWidth;
	objPrivacyDiv.style.width = '0px';
	objPrivacyDiv.style.display = '';
	doReveal(objPrivacyDiv.id,intOW);
	e.cancelBubble = true;
}

function doPrivacyPolicyClose() { var objContactDiv = document.getElementById('privacypolicy_frame'); objContactDiv.style.top = '-500px'; objContactDiv.style.left = '-500px';}


function doContactThankyouWindow(strProduct) {

	var objContactDiv = document.getElementById('contact_thankyou_frame');
	objContactDiv.style.top =  215 + 'px';

	objContactDiv.style.left = 317 + 'px';

	switch(strProduct) {
		case 'campaignlogic':
			doColor('contact_thankyou_frame','#00cc00');
			document.getElementById('contact_thankyou_button').src = 'images/misc/bullet_green.gif'
			break;
		case 'adlogic':
			doColor('contact_thankyou_frame','#ff00cc');
			document.getElementById('contact_thankyou_button').src = 'images/misc/bullet_pink.gif'
			break;
		case 'shopperlogic':
			doColor('contact_thankyou_frame','#01a3d9');
			document.getElementById('contact_thankyou_button').src = 'images/misc/bullet_blue.gif'
			break;
		default: break;
	}
}

function doContactThankyouClose() { var objContactDiv = document.getElementById('contact_thankyou_frame'); objContactDiv.style.top = '-500px'; objContactDiv.style.left = '-500px';}


function doLogin() {
	var stype,strError='', objUsername, objPassword;
	stype = eval("document.frmLogin.optSite");
	objUsername = document.getElementById('strUsername');
	objPassword = document.getElementById('strPassword');

	if (!stype[0].checked && !stype[1].checked && !stype[2].checked) strError = strError + '-Select a product first.\n';
	if (objUsername.value == '') strError = strError +  '-Enter a username first.\n';
	if (objPassword.value == '') strError = strError + '-Enter a password first.\n';

	if (strError == '') {
		if (stype[0].checked) {document.frmLogin.action = 'http://campaignlogic.truelogic.com.au/default.asp?stype=login'; eval(document.frmLogin.submit()); }
		else if (stype[1].checked) {document.frmLogin.action = 'http://shopperlogic.com/default.aspx?stype=exlogin'; eval(document.frmLogin.submit());}
		else if (stype[2].checked) {document.frmLogin.action = 'http://adlogic.truelogic.com.au/default.aspx?stype=login'; eval(document.frmLogin.submit());}
	}
	else
		alert(strError);
}

function doContact() {

	//Make sure we have fields
	var objFName = document.getElementById('strFirstName');
	var obJLname = document.getElementById('strLastName');
	var objEmail = document.getElementById('strEmailAddress');
	var objCName = document.getElementById('strCompanyName');
	var objPhone = document.getElementById('strTelephoneNumber');
	var objLocation = document.getElementById('strCountry');	
	var objInfo = document.getElementById('infofor');	
	var objIndustry = document.getElementById('yourindustry');	
	var objVolume = document.getElementById('volume');	
	
	var objProduct = document.getElementById('product'); 
	
	if (objFName.value == '') {
		alert('Please enter your first name.');
		return;
	}
	
	if (obJLname.value == '') {
		alert('Please enter your last name.');
		return;
	}
	
	if (objEmail.value == '') {
		alert('Please enter your email address.');
		return;
	}
	
	if (objCName.value == '') {
		alert('Please enter your company name.');
		return;
	}
	
	if (objPhone.value == '') {
		alert('Please enter your phone number.');
		return;
	}
	
	if (objLocation.value == '') {
		alert('Please enter your location.');
		return;
	}
	
	if (objProduct.value == 'campaignlogic') {
	
		
	
		//Tests specific to CL
		if (objInfo.value == 'Select...') {
			alert('Please enter who you are seeking information for.');
			return;
		}
		
		if (objIndustry.value == 'Select...') {
			alert('Please enter your industry.');
			return;
		}
		
		if (objVolume.value == 'Select...') {
			alert('Please enter your annual email volume.');
			return;
		}
	
	}
	
	var filter=/^.+@.+\..{2,3}$/
 	if (!filter.test(objEmail.value)) {
    alert("Please enter a valid email address!")
    return;
	}

	eval(document.frmContact.submit()); 
}

function doLoginWindow(evt) {
	doContactWindowClose();
	doContactThankyouClose();
	doPrivacyPolicyClose();
	var e = (window.event) ? window.event : evt;
	var objLoginDiv = document.getElementById('login_frame');
	var objLoginButton = document.getElementById('login');
	objLoginDiv.style.top =  (posTop(objLoginButton) - 11)  + 'px';
	objLoginDiv.style.left = (posLeft(objLoginButton) - 10)+ 'px';
	var intOW = objLoginDiv.offsetWidth;
	objLoginDiv.style.width = '0px';
	objLoginDiv.style.display = '';
	doReveal(objLoginDiv.id,intOW);
}

function doLoginWindowClose() { var objLoginDiv = document.getElementById('login_frame'); objLoginDiv.style.top = '-500px'; objLoginDiv.style.left = '-500px';}

function doReveal(strID,intOW) {
	var objSelDiv = document.getElementById(strID);
	if (objSelDiv.offsetWidth < intOW) objSelDiv.style.width = objSelDiv.offsetWidth + 20 + 'px';
	if ( objSelDiv.offsetWidth < intOW ) setTimeout('doReveal(\'' + strID + '\',' + intOW + ');', 25);
}

function doColor(strID,strColor) {
	var objDiv = document.getElementById(strID);
	objDiv.style.backgroundColor = strColor;
}

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
   		return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
   		return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else return null;
}

function posTop(e) {
	if(document.layers) return(e.pageY);
 	var i=e.offsetTop;
 	if(e.offsetParent!=null) i+=posTop(e.offsetParent);
 	return(i);
}

function posLeft(e) {
	if(document.layers) return(e.pageX);
 	var i=e.offsetLeft;
 	if(e.offsetParent!=null) i+=posLeft(e.offsetParent);
	return(i);
}

function getUserTimeZone(strProduct)
{
	var now = new Date();
	var offset = (now.getTimezoneOffset() / 60)*-1;	
	
	switch(strProduct) {
		case 'campaignlogic':
			if(-12 <= offset <= -4) {
				document.getElementById('phone').src = 'images/copy/campaignlogic_phone_us.gif';
				document.getElementById('phone').alt = 'EmailCampaigns is ideal for small businesses and individual proprietors, with affordable monthly pricing. 800 691 4995.  international: +61 2 9554 8863';
			} else {
				document.getElementById('phone').src = 'images/copy/campaignlogic_phone_au.gif';
				document.getElementById('phone').alt = 'EmailCampaigns is ideal for small businesses and individual proprietors, with affordable monthly pricing.';
			}
			document.getElementById('phoneLink').href = 'http://www.emailcampaigns.com';
			document.getElementById('brochure').src = 'images/copy/campaignlogic_brochure.gif';
			document.getElementById('brochure').alt = 'or enter your details below, and we\'ll contact you about campaignlogic, our enterprise-level system.';
			document.getElementById('close').src = 'images/misc/campaignlogic_close.gif';
			document.getElementById('contact_button').src = 'images/misc/bullet_green.gif'
			break;
		case 'adlogic':
			if(-12 <= offset <= -4) {
				document.getElementById('phone').src = 'images/copy/adlogic_phone_us.gif';
				document.getElementById('phone').alt = 'for more information call truelogic on: 800 691 4995.  international: +61 2 9554 8863';
			} else {
				document.getElementById('phone').src = 'images/copy/adlogic_phone_au.gif';
				document.getElementById('phone').alt = 'for more information call truelogic on: 1800 004 510.  international: +61 2 9554 8863';
			}
			document.getElementById('phoneLink').removeAttribute('href');
			document.getElementById('brochure').src = 'images/copy/adlogic_brochure.gif';
			document.getElementById('brochure').alt = 'or simply enter your details below and we\'ll send you an adlogic brochure in a jiffy.';
			document.getElementById('close').src = 'images/misc/adlogic_close.gif';
			document.getElementById('contact_button').src = 'images/misc/bullet_pink.gif'
			break;
		case 'shopperlogic':
			document.getElementById('phoneLink').removeAttribute('href');
			if(-12 <= offset <= -4) {
				document.getElementById('phone').src = 'images/copy/shopperlogic_phone_us.gif';
				document.getElementById('phone').alt = 'for more information call truelogic on: 800 691 4995.  international: +61 2 9554 8863';
			} else {
				document.getElementById('phone').src = 'images/copy/shopperlogic_phone_au.gif';
				document.getElementById('phone').alt = 'for more information call truelogic on: 1800 004 510.  international: +61 2 9554 8863';
			}
			document.getElementById('brochure').src = 'images/copy/shopperlogic_brochure.gif';
			document.getElementById('brochure').alt = 'or simply enter your details below and we\'ll send you a shopperlogic brochure in a jiffy.';
			document.getElementById('close').src = 'images/misc/shopperlogic_close.gif';
			document.getElementById('contact_button').src = 'images/misc/bullet_blue.gif'
			break;
		default: break;
	}
}

function doTourWindow(evt) {	
	doLoginWindowClose();
	var e = (window.event) ? window.event : evt;

	var objTourDiv = document.getElementById('tour_frame');
	objTourDiv.style.top =  60 + 'px';
	objTourDiv.style.left = 441 + 'px';
	var intOW = objTourDiv.offsetWidth;
	objTourDiv.style.width = '0px';
	objTourDiv.style.display = '';
	doReveal(objTourDiv.id,intOW);
	e.cancelBubble = true;
}

function doTourWindowClose() { var objTourDiv = document.getElementById('tour_frame'); objTourDiv.style.top = '-400px'; objTourDiv.style.left = '-400px';}

function doWorkWithUsShow() {
	doTourWindowClose();
	doPostcardsHide();
	//Find the baseline of the Iframe, move top of frame there
	if (bolScrolling) return;
	document.cookie = 'dateViewed=' + Date() + '; expires=31 Dec 2010 23:59:59 GMT;';
	
	var objWorkWithUs = document.getElementById('workwithus_frame');
	var objSiteFrame = document.getElementById('site');
	var intTop = posTop(objSiteFrame);
	var intHeight = objWorkWithUs.offsetHeight;

	if (objWorkWithUs.style.filter == 'alpha(opacity=100)') {

		doFade('workwithus_frame',100);
	}
	else {

		window.parent.doLoginWindowClose();
		window.parent.doContactWindowClose();
		window.parent.doContactThankyouClose();
		window.parent.doPrivacyPolicyClose();
		objWorkWithUs.style.top = (intTop + objSiteFrame.offsetHeight - 2) +  'px';
		objWorkWithUs.style.left = '40px';
		objWorkWithUs.style.filter = 'alpha(opacity=60)';
		objWorkWithUs.style.opacity = .60;
		objWorkWithUs.style.height = '0px';
		objWorkWithUs.style.display = '';
		doMove('workwithus_frame', intTop, intHeight);



	}
}

function doWorkWithUsHide() {
	var objWorkWithUs = document.getElementById('workwithus_frame');
	if (objWorkWithUs.style.filter == 'alpha(opacity=100)') doFade('workwithus_frame',100);
}



function doFeature(strContent,strID) {
	var objBenifit = document.getElementById(strID);

	//spilt on the |
	var aryParts = strContent.split('|');
	if (aryParts.length ==1) {
		objBenifit.innerHTML = strContent;
		objBenifit = document.getElementById(strID + '2');
		if (objBenifit != null) objBenifit.innerHTML = '';
	} else {
		objBenifit.innerHTML = aryParts[0];
		objBenifit = document.getElementById(strID + '2');
		objBenifit.innerHTML = aryParts[1];
	}
}

function doWorkSend(strContent,strId) {
	var objWorkSendLink = document.getElementById(strId);
	
	//change link subject to match area
	objWorkSendLink.href = strContent;
}

function changeImage(strPlace,intMode) {
	var strSrc = document.getElementById(strPlace).src;
 	aryParts = strSrc.split('.gif')
 	if (intMode ==1)
 		document.getElementById(strPlace).src = aryParts[0] + '_over.gif';
 	else
 		document.getElementById(strPlace).src = aryParts[0].replace('_over','') + '.gif';
}

function doQuoteSwap(intPosToMove) {

	var objWorkWithUs = document.getElementById('workwithus_frame');
	if (objWorkWithUs.style.filter == 'alpha(opacity=100)') {

		document.getElementById('divQuote' + intPosToMove).style.display = 'none';
		
		if (intPosToMove < 2) {
			intPosToMove++;
		} else
			intPosToMove = 0;
			
		document.getElementById('divQuote' + intPosToMove).style.display = '';
	}

	setTimeout('doQuoteSwap(' + intPosToMove + ');',7000);
}
