
// get domain host
var host = top.location.host;

// generic ajax form data capture object
var CapFormData = {
	
	FORM_ID: 'mobForm',
	AREA_TO_UPDATE_ID: 'mobSubmitStatus',
	SUBMIT_URL: 'http://'+ host+'/formsubmit?',
	PROCESSING_TEXT: 'Please wait...',
	SUCCESS_TEXT: 'You have successfully signed up for Hot Hits Alerts!',
	FAILURE_TEXT: 'Sorry, something went wrong! Try again?',
	
	getSubmitUrl: function () {
		var formparams = $(CapFormData.FORM_ID).toQueryString();
		var submiturl = CapFormData.SUBMIT_URL + formparams;
		// console.log('NEW URL YOYOYO', submiturl);
		return submiturl;
	},
	
	validate: function () {
		var data = $('mobInput').value;
		if (data.test(/04\d/)) {
			return true;
		} else {
			$(CapFormData.AREA_TO_UPDATE_ID).setText('Please enter a valid mobile number!');
			return false;
		}
	},
	
	submit: function () {
		
		if (!CapFormData.validate()) return false;
		
		var captureDataAjax = new Ajax (CapFormData.getSubmitUrl(), {
			method: 'get',
			getHeader: true,
			onRequest: function() {
				$(CapFormData.AREA_TO_UPDATE_ID).setText(CapFormData.PROCESSING_TEXT);
			},
			onComplete:	function(){
				$(CapFormData.AREA_TO_UPDATE_ID).setText(CapFormData.SUCCESS_TEXT);
			},
			onFailure: function() {
				$(CapFormData.AREA_TO_UPDATE_ID).setText(CapFormData.FAILURE_TEXT);
			}
		});	
		captureDataAjax.request();
	}
	
};

function hideFlashElements () {
    var items = $$('.flash');
    $each(items, function (item) {
      item.setStyle('visibility', 'hidden');
    }); 
}

function showFlashElements () {
  setTimeout(function () {
    var items = $$('.flash');
    $each(items, function (item) {
      item.setStyle('visibility', 'visible');
    });
  },500);
  
}

window.addEvent('load', function () { 
	
	if ($('txthelp')) {
		var txthelp = new AscDialog({ isModal:true, classPrefix: 'popup tc_', maskOpacity: 0.6 });
    txthelp.set_contents('<h2>Having Trouble</h2><p>Click on the link in the message to go straight to the action. If your message does not display a link some handsets will display "go to" at the base of the screen simply hit corresponding button on your keypad.</p>');
    $('txthelp').addEvent('click', function (e) {
      if(e) e = new Event(e).stop();
      hideFlashElements();
      txthelp.show();
    });
	}
	
	if ($('faqs')) {
		var faqs = new AscDialog({ isModal:true, classPrefix: 'popup tc_', maskOpacity: 0.6 });
	  faqs.set_contents('<h2>FAQ</h2><p><strong>Q: How do I to access Hot Hits on my mobile?</strong> SMS "HITS" to 966 or go to Optus Zoo on your handset then browse to Hot Hits.</p><p><strong>Q: Is my mobile compatible?</strong> To access Hot Hits you need a GRPS compatible phone, which will allow you to access Optus Zoo and the Hot Hits site.  To view the Hot Hits videos, your mobile must also be 3G and video capable. A list of compatible handsets is available <a href="http://mobile.optuszoo.com.au/cocoon/device/deviceselection.xml?feature=LiveTV" rel="external">here</a>.</p><p><strong>Q: How do I get Optus Zoo settings on my handset?</strong> Go to Optus Zoo and follow the <a href="http://mobile.optuszoo.com.au/cocoon/cgi-bin/info2you/static_file/display_file.cgi?file=mymobile-setup.html&node_id=30040" rel="external">steps</a>.</p><p><strong>Q: How do I get my alerts?</strong> Alerts are sent as WAP push messages, and they are usually received in your messaging inbox. However, this can differ with different handset models.</p><p><strong>Q: What time do I get my alerts?</strong> You can choose to get your alerts at two different times, at 7:30am in the morning and at 16:30pm in the afternoon.</p><p><strong>Q: What happens when I send "HITS" to 966?</strong> You get a service message which contains a link that you should select and click on. This will take you to the Hot Hits homepage.</p><p><strong>Q: How do I stop weekly and daily alerts? </strong><br /> You can visit the My Alerts section on the site and cancel your alerts from there Or alternatively you can send "STOP" + the following keyword to 19728364<br />1. "STOP AM"<br />2. "STOP PM"<br />3. "STOP WEEK"<br />Or "STOP" to cancel all their Hot Hits alerts subscriptions.</p><p><strong>Q: I cannot find the service message, where is it?</strong> Depending on the type of handset, you would get the service message either in the messaging inbox folder or in the service inbox folder.</p><p><strong>Q: Can I preview songs online before I buy them?</strong> Yes. You can listen to a preview of the song for free before you buy it.</p><p><strong>Q: Does the customer need to be in a particular coverage area to use these services?</strong> Yes they need to be within a 3G/HSPA coverage area to enjoy the Hot Hits video service.  For coverage details see www.optus.com.au/coverage. However for everything else, 2G coverage is sufficient.</p><p><strong>Q: Can I pause and resume play for any of the video and audio content?</strong> No you cannot pause and play any of the video and audio content. Once you stop the playing of the audio or video content, you will have to reconnect again and the content will start showing from the beginning.</p>');
    $('faqs').addEvent('click', function (e) {
      if(e) e = new Event(e).stop();
      hideFlashElements();
      faqs.show();
    });
	}
	
	if ($('features')) {
		var features = new AscDialog({ isModal:true, classPrefix: 'popup tc_', maskOpacity: 0.6 });
    features.set_contents('<h2>What content is available on my handset?</h2><table id="mobilePhonesTable" cellspacing="0" cellpadding="0"><tr><td></td><td>3G handset<br /> (Excludes iphone 3G)</td><td>2G handset</td></tr><tr><td>Daily Video Show</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><span style="float:left; margin-right:4px; margin-top:3px;"><img src="/images/mobile/icon_cross.gif" alt="Cross" /></span> (Audio Only)</td></tr><tr><td>Weekly Radio Show</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td>  <td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr><tr><td>The Hot Hits Chart - Top Ten</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr><tr><td>Entertainment News</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr><tr><td>Who\'s Hot</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr><tr><td>Artist Pics - Wallpapers</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr><tr><td>Purchase music tracks &amp; ringtones</td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td><td><img src="/images/mobile/icon_tick.gif" alt="Tick" /></td></tr></table></p>');
    $('features').addEvent('click', function (e) {
      if(e) e = new Event(e).stop();
      hideFlashElements();
      features.show();
    });
	}
		
	if ($('tcs')) {
		var tcs = new AscDialog({ isModal:true, classPrefix: 'popup tc_', maskOpacity: 0.6 });
   	tcs.set_contents('<h2>Terms &amp; Conditions</h2>SMS to 966: No charges apply to SMS 966.  Your handset must be compatible to receive a WAP push message.  When you SMS "HITS" to 966 you will automatically receive a free weekly alert to advise of new content available on the Hot Hits Mobile site.  There is no charge to receive the alert. Optus Pre-Paid mobile customer will be charged a Flagfall of 22c to  click on the link in the alerts and access the Hot Hits Mobile homepage  The Hot Hits Mobile site: Your handset must be 3G and video-capable to access The Hot Hits video service and GPRS compatible to access the remainder of the site.  Standard data browsing and downloading charges apply to access some areas of the Hot Hits Mobile site and to to navigate to Hot Hits from Optus Zoo main menu. Full terms and conditions available at <a href="http://www.optuszoo.com.au/mobile" rel="external">www.optuszoo.com.au/mobile</a>');
   	$('tcs').addEvent('click', function (e) {
     	if(e) e = new Event(e).stop();
     	hideFlashElements();
     	tcs.show();
   	});
	}
	
	if ($('txthelp')) {
		var txthelp = new AscDialog({ isModal:true, classPrefix: 'popup tc_', maskOpacity: 0.6 });
    txthelp.set_contents('<h2>Having Trouble</h2><p>Click on the link in the message to go straight to the action. If your message does not display a link some handsets will display "go to" at the base of the screen simply hit corresponding button on your keypad.</p>');
    $('txthelp').addEvent('click', function (e) {
      if(e) e = new Event(e).stop();
      hideFlashElements();
      txthelp.show();
    });
	}     

  $$('div[class$=_Close] a').addEvent('click', function (e) {
     showFlashElements();
   });

});