/* SOS JAVASCRIPT */
/*Written by Jared Crossley, © SOS Web Services 2011 and beyond*/

//====MENU FADE IN'S====

//about us
$("#about-li").mouseenter(function() {
	$("#menu-selected").css("background-image","none");
	$("#about").css("background-image","url(images/menu-on-bg.png)");
	$("#about-dropdown").fadeIn(300, function() {
		// Animation complete
		});
});
$("#about-li").mouseleave(function() {
	$("#about-dropdown").css("display","none");
	$("#about").css("background-image","none");
	$("#menu-selected").css("background-image","url(images/menu-on-bg.png)");
});

//products
$("#products-li").mouseenter(function() {
	$("#menu-selected").css("background-image","none");
	$("#products").css("background-image","url(images/menu-on-bg.png)");
	$("#products-dropdown").fadeIn(300, function() {
		// Animation complete
		});
});
$("#products-li").mouseleave(function() {
	$("#products-dropdown").css("display","none");
	$("#products").css("background-image","none");
	$("#menu-selected").css("background-image","url(images/menu-on-bg.png)");
});
	
//support
$("#support-li").mouseenter(function() {
	$("#menu-selected").css("background-image","none");
	$("#support").css("background-image","url(images/menu-on-bg.png)");
});
$("#support-li").mouseleave(function() {
	$("#support").css("background-image","none");
	$("#menu-selected").css("background-image","url(images/menu-on-bg.png)");
});

//services
$("#services-li").mouseenter(function() {
	$("#menu-selected").css("background-image","none");
	$("#services").css("background-image","url(images/menu-on-bg.png)");
	$("#services-dropdown").fadeIn(300, function() {
		// Animation complete
	});
});
$("#services-li").mouseleave(function() {
	$("#services-dropdown").css("display","none");
	$("#services").css("background-image","none");
	$("#menu-selected").css("background-image","url(images/menu-on-bg.png)");
});
	
//support
$("#contact-li").mouseenter(function() {
	$("#menu-selected").css("background-image","none");
	$("#contact").css("background-image","url(images/menu-on-bg.png)");
});
$("#contact-li").mouseleave(function() {
	$("#contact").css("background-image","none");
	$("#menu-selected").css("background-image","url(images/menu-on-bg.png)");
});

//search bar
$("#searchtext").click(function() {
	$("#search").css("background-image","url(images/search-bg-over.png)"); 
	$("#searchtext").css("color","#ffffff"); 
});
$("#searchtext").blur(function() {
	$("#search").css("backgroundImage","url(images/search-bg.png)");
	$("#searchtext").css("color","#cccccc");
});
	
	
//==== HOME WEBMAIL BOX ====

$("#accountusername").change(function() {
	//Check if ... is selected
	if (!($("#accountusername").val() == "..."))
	{
		$("#poll-hp").hide(); //hide away poll box
		$("#hp-webmail-first").slideUp(); //hide away the box for selecting what account looks like
		$("#hp-webmail-next").delay(200).slideDown(); //bring up box with the login form
		
		switch ($("#accountusername").val())
		{
			case "ct": //Cape Town
				$("#form-webmail").attr("action","http://webmail.storm.co.za/source/index_ct.php");
				$("#username-end").html("@ct.stormnet.co.za");
				$("#webmail-user").attr("name","user");
				$("#webmail-user").attr("style","width: 100px");
				$("#webmail-host").attr("value","ct.stormnet.co.za");
				$("#webmail-port").attr("value","110");
				break;
			case "dbn": //Durban
				$("#form-webmail").attr("action","http://webmail.storm.co.za/source/index_dbn.php");
				$("#username-end").html("@dbn.stormnet.co.za");
				$("#webmail-user").attr("name","user");
				$("#webmail-user").attr("style","width: 89px");
				$("#webmail-host").attr("value","dbn.stormnet.co.za");
				$("#webmail-port").attr("value","110");
				break;
			case "jhb": //Johannesburg
				$("#form-webmail").attr("action","http://webmail.storm.co.za/source/index_jhb.php");
				$("#username-end").html("@jhb.stormnet.co.za");
				$("#webmail-user").attr("name","user");
				$("#webmail-user").attr("style","width: 89px");
				$("#webmail-host").attr("value","jhb.stormnet.co.za");
				$("#webmail-port").attr("value","110");
				break;
			case "sosdns": //SOS DNS Accounts
				$("#form-webmail").attr("style","font-size: 12px;");
				$("#form-webmail").html("To view your webmail, please <a href=\"http://webmail.sosdns.co.za/\" target=\"_blank\">click here</a>.");
				$("#incorrect-account-username").attr("style","margin-top: 20px;");
				break;
			default: 
				break;
		}
	}
});

$("#webmail-submit").click(function() {
	//if using 'is' (sosdns) then must append '@sosdns.co.za' to the username.
	if ($("#accountusername").val() == "sosdns")
		$("#webmail-user").attr("value", ($("#webmail-user").attr("value") + "@sosdns.co.za"))
	//hide login form and display a message
	$("#hp-webmail-next").hide();
	$("#hp-webmail-last").show();
	$("#poll-hp").show(); //show poll box
});

$("#select-bad-webmail").click(function() {
	$("#hp-webmail-next").slideUp(); //hide away login form
	$("#hp-webmail-first").delay(200).slideDown(); //bring up the box for selecting what account looks like
	$("#poll-hp").delay(200).show(); //show poll box
});

//====HOMEPAGE NOTIFICATIONS SUBSCRIBE====//
$("#click-subscribe-alerts").click(function() {
	$("#prev-notifications").delay(200).slideToggle();
	$("#subscribe-notifications").delay(200).slideToggle();
	return false;
});

//====HOMEPAGE SOSLIST SUBSCRIBE====//
$("#soslist-email").keyup(function() {
	//check if there are at least 10 characters
	var length = $("#soslist-email").val().length + 1;
	var text = $("#soslist-email").val();
	
	if (length >= 9)
	{
		//also check if there is an @ symbol somewhere within the string
		if (text.lastIndexOf("@") != -1 & text.lastIndexOf(".") != -1)
		{
			$("#subscribe-link").fadeIn(300);
			$("#soslist-email").css("background-color","#ffffff");
		}
		else
		{
			$("#subscribe-link").fadeOut(300);
			$("#soslist-email").css("background-color","#fee1e1");
		}
	}
	else
	{
		$("#subscribe-link").fadeOut(300);
		$("#soslist-email").css("background-color","#ffffff");
	}
});

$("#subscribe-link").click(function() {
	//create the recaptcha
	Recaptcha.create("6LfGKwAAAAAAAP6GEFOP26cik1vcrwbiLj6C_qmN", "recaptcha-form", {
	theme: "red",
	callback: Recaptcha.focus_response_field});
	//show the overlay div
	$("#page-overlay").fadeIn(300);
	return false;
});

$("#recaptcha-button-close").click(function() {
	$("#page-overlay").fadeOut(300);
	return false;
});

$("#submit-recaptcha-soslist").click(function() {
	console.log('button was clicked'); 
	//hide the submit button, show the loading icon
	$("#recaptcha-button").hide();
	$("#recaptcha-loading").show();
	//first, check if recaptcha is correct - get the given recaptcha, and the user's response.
	challengeField = $("input#recaptcha_challenge_field").val(); //this is all gumbled
    responseField = $("input#recaptcha_response_field").val(); //this is clear text of what the user has writter
	//post the data to recaptcha.asp
	$.ajax({
		type: "POST",
		url: "include/recaptcha.asp",
		data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
		success: function(data) { //note the "data" - this will get the result from recaptcha.asp
			if (data == "success")
			{
				//captcha correct, submit the email address
				//get the various variables
				var email = $("#soslist-email").attr("value");
				var datastring = "email="+email;
				
				$.ajax({
					type: "POST",
					url: "process.asp?do=subscribesoslist",
					data: datastring,
					success: function(data) { //note the "data" - this will get the result from process.asp
						$("#page-overlay").fadeOut(300);
						$("#soslist-confirm").html(data);
						$("#soslist-dynamic").slideUp();
						$("#soslist-confirm").slideDown();
					}
				});
			}
			else
			{
				Recaptcha.reload();
				$("#recaptcha-infotext").attr("style","color: #970b0d");
				$("#recaptcha-infotext").html("Incorrect. Please try again.");
				$("#recaptcha-loading").hide();
				$("#recaptcha-button").show();
			}
		}
	});
	return false;
});

//====HOMEPAGE FLOATING NOTIFICATION WINDOW====//
$("#notification-button-close").click(function() {
	$("#notification-overlay").fadeOut(300);
	return false;
});

$("#notification-show-details").click(function() {
	$("#notification-overlay").fadeIn(300); //fade in notifications block
	var id = $("#notification-show-details").attr("issueid"); //get issue id
	//get notification details
	$.ajax({
		type: "POST",
		url: "process.asp?do=getnotificationdetails",
		data: "issueid="+id,
		success: function(data) { //note the "data" - this will get the result from process.asp
			$("#notification-filler").html(data);
			$("#notification-loading").hide();
			$("#notification-filler").slideDown();
		}
	});
	return false; //stop the page changing
});

//====HOMEPAGE POLL VOTE====
$("#option1").click(function() {
	var id = $("#pollid").attr("value");
	$.ajax({
		type: "POST",
		url: "process.asp?do=pollvote",
		data: "option=1&id="+id,
		success: function(data) { //note the "data" - this will get the result from process.asp
			$("#lrg-webmail").hide(); //hide away webmail box
			$("#poll-results").html(data);
			$("#poll-options").slideUp();
			$("#poll-results").slideDown();
		}
	});
	return false; //stop the page changing
});
$("#option2").click(function() {
	var id = $("#pollid").attr("value");
	$.ajax({
		type: "POST",
		url: "process.asp?do=pollvote",
		data: "option=2&id="+id,
		success: function(data) { //note the "data" - this will get the result from process.asp
			$("#lrg-webmail").hide(); //hide away webmail box
			$("#poll-results").html(data);
			$("#poll-options").slideUp();
			$("#poll-results").slideDown();
		}
	});
	return false; //stop the page changing
});
$("#option3").click(function() {
	var id = $("#pollid").attr("value");
	$.ajax({
		type: "POST",
		url: "process.asp?do=pollvote",
		data: "option=3&id="+id,
		success: function(data) { //note the "data" - this will get the result from process.asp
			$("#lrg-webmail").hide(); //hide away webmail box
			$("#poll-results").html(data);
			$("#poll-options").slideUp();
			$("#poll-results").slideDown();
		}
	});
	return false; //stop the page changing
});
$("#option4").click(function() {
	var id = $("#pollid").attr("value");
	$.ajax({
		type: "POST",
		url: "process.asp?do=pollvote",
		data: "option=4&id="+id,
		success: function(data) { //note the "data" - this will get the result from process.asp
			$("#lrg-webmail").hide(); //hide away webmail box
			$("#poll-results").html(data);
			$("#poll-options").slideUp();
			$("#poll-results").slideDown();
		}
	});
	return false; //stop the page changing
});

//====HOME PAGE TWITTER CHANGE FONT SIZE
function twitterFontSize()
{
	setTimeout(
		function() 
		{
			//get the tweet
			var tweet = $("#tweet-text").html();
			var length = tweet.length;
			//0-80 - 12px
			//81-140 - default
			if (length <= 80) //if the tweet is less than 80 characters, increase the font size
				$("#tweet-text").css("font-size","12px");

		}, 3000); //delay 3 seconds
}


//====CONTACT PAGE - SUBMIT CONTACT FORM====
$("#submit-contact").click(function () {
	//first, check if required fields have been filled out
	var count = 0;
	if ($("#fname").attr("value") == "")
	{
		count++;
		$("#fname").css("background-color","#fee1e1");
	}
	if ($("#email").attr("value") == "")
	{
		count++;
		$("#email").css("background-color","#fee1e1");
	}
	if ($("#commsug").attr("value") == "")
	{
		count++;
		$("#commsug").css("background-color","#fee1e1");
	}
	if (count == 0)
	{
		//continue with recaptcha
		//create the recaptcha
		Recaptcha.create("6LfGKwAAAAAAAP6GEFOP26cik1vcrwbiLj6C_qmN", "recaptcha-form", {
		theme: "red",
		callback: Recaptcha.focus_response_field});
		//show the overlay div
		$("#page-overlay").fadeIn(300);
	}
	return false; //stop the page changing
});

$("#submit-recaptcha-contact").click(function() {
	//hide the submit button, show the loading icon
	$("#recaptcha-button").hide();
	$("#recaptcha-loading").show();
	//first, check if recaptcha is correct - get the given recaptcha, and the user's response.
	challengeField = $("input#recaptcha_challenge_field").val(); //this is all gumbled
    responseField = $("input#recaptcha_response_field").val(); //this is clear text of what the user has writter
	//post the data to recaptcha.asp
	$.ajax({
		type: "POST",
		url: "include/recaptcha.asp",
		data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
		success: function(data) { //note the "data" - this will get the result from recaptcha.asp
			if (data == "success")
			{
				//captcha correct, submit the contact form
				//get the various variables
				var fname = $("#fname").attr("value");
				var email = $("#email").attr("value");
				var telc = $("#telc").attr("value");
				var telno = $("#telno").attr("value");
				var faxc = $("#faxc").attr("value");
				var faxno = $("#faxno").attr("value");
				if (document.getElementById('accesschk').checked)
					var accesschk = "Yes";
				if (document.getElementById('macchk').checked)
					var macchk = "Yes";
				if (document.getElementById('netchk').checked)
					var netchk = "Yes";
				if (document.getElementById('pcchk').checked)
					var pcchk = "Yes";
				if (document.getElementById('webchk').checked)
					var webchk = "Yes";
				var commsug = $("#commsug").val();
	
				var datastring = "fname="+fname+"&email="+email+"&telc="+telc+"&telno="+telno+"&faxc="+faxc+"&faxno="+faxno+"&accesschk="+accesschk+"&macchk="+macchk+"&netchk="+netchk+"&pcchk="+pcchk+"&webchk="+webchk+"&commsug="+commsug;
	
				//post the data to process.asp
				$.ajax({
					type: "POST",
					url: "process.asp?do=submitcontact",
					data: encodeURI(datastring),
					success: function(data) { //note the "data" - this will get the result from process.asp
						$("#page-overlay").fadeOut(300);
						$("#contact-form-success").html(data);
						$("#contact-form-form").slideUp();
						$("#contact-form-success").slideDown();
					}
				});
				$("#contact-form-form").slideUp();
				$("#contact-form-success").slideDown();
			}
			else
			{
				Recaptcha.reload();
				$("#recaptcha-infotext").attr("style","color: #970b0d");
				$("#recaptcha-infotext").html("Incorrect. Please try again.");
				$("#recaptcha-loading").hide();
				$("#recaptcha-button").show();
			}
		}
	});
	return false;
});

//====PRODUCTS - WEB - PORTFOLIO====


//====SEARCH PAGE====
function loadSearch(search_query)
{
	datastring = "zoom_query="+search_query+"&zoom_per_page="+zoom_per_page+"&zoom_page="+zoom_page;
	//get the search results
	$.ajax({
		type: "GET",
		url: "zoom/search.asp",
		data: datastring,
		success: function(data) { //note the "data" - this will get the result from search.asp
			$("#search-results").html(data);
			$("#search-loader").slideUp();
			$("#search-results").slideDown();
		}
	});
}

//====SUPPORT PAGE - POP3 & SMTP DETAILS====
$("#support-pop3smtp").change(function() { //What does your email account username look like?
	if (!($("#support-pop3smtp").val() == "..."))
	{
		$("#support-process-1").slideUp(); //hide "support-process-1" (Support Step 1)
		$("#support-process-2").slideDown(); //show "support-process-2" (Support Step 2)
	}
});
$("#support-adsldialup").change(function() { //Do you have an ADSL or Dialup Account? (Support Step 2)
	if (!($("#support-adsldialup").val() == "..."))
	{
		if ($("#support-adsldialup").val() == "adsl") //person has adsl, move onto next step
		{
			$("#support-process-2").slideUp(); //hide "support-process-2" (Support Step 2)
			$("#support-process-3").slideDown(); //show "support-process-3" (Support Step 3)
		}
		else //person has dialup, no extra step needed, output result.
		{
			$("#support-process-2").slideUp(); //hide "support-process-2" (Support Step 2)
			$("#support-process-4").slideDown(); //show "support-process-4" (Support Step 4)
			switch($("#support-pop3smtp").val())
			{
				case "ct": //Cape Town
					$("#support-process-result").html("<p>National SAIX Dialup:<br />0860 00 7249</p><p>POP3 (Incoming Email) Server:<br />ct.stormnet.co.za</p><p>SMTP (Outgoing Email) Server:<br />ct.stormnet.co.za</p>");
					break;
				case "dbn": //Cape Town
					$("#support-process-result").html("<p>National SAIX Dialup:<br />0860 00 7249</p><p>POP3 (Incoming Email) Server:<br />dbn.stormnet.co.za</p><p>SMTP (Outgoing Email) Server:<br />dbn.stormnet.co.za</p>");
					break;
				case "jhb": //Cape Town
					$("#support-process-result").html("<p>National SAIX Dialup:<br />0860 00 7249</p><p>POP3 (Incoming Email) Server:<br />jhb.stormnet.co.za</p><p>SMTP (Outgoing Email) Server:<br />jhb.stormnet.co.za</p>");
					break;
				case "sosdns": //IS
					$("#support-process-result").html("<p>National SAIX Dialup:<br />0860 00 7249</p><p>POP3 (Incoming Email) Server:<br />vmail.dial-up.net</p><p>SMTP (Outgoing Email) Server:<br />vmail.dial-up.net</p>");
					break;
			}
		}
	}
});

$("#support-issosdsl").change(function() { //What does you ADSL account ID look like? - Person has ADSL
	$("#support-process-3").slideUp(); //hide "support-process-2"
	$("#support-process-4").slideDown(); //show "support-process-4"
	var emailaccountid = $("#support-pop3smtp").val();
	var adslaccountid = $("#support-issosdsl").val();
	var html = "";
	
	//datapro capetown pop3
	if (emailaccountid == "ct")
		html = html + "POP3 (Incoming Email) Server:<br>ct.stormnet.co.za<p>";
	//datapro durban pop3
	if (emailaccountid == "dbn")
		html = html + "POP3 (Incoming Email) Server:<br>dbn.stormnet.co.za<p>";
	//datapro jhb pop3
	if (emailaccountid == "jhb")
		html = html + "POP3 (Incoming Email) Server:<br>jhb.stormnet.co.za<p>";
	//is sosdns pop3
	if (emailaccountid == "sosdns")
		html = html + "POP3 (Incoming Email) Server:<br>vmail.dial-up.net<p>";
	
	//isdsl
	if (adslaccountid == "isdsl")
		html = html + "SMTP (Outgoing Email) Server:<br>smtp.isdsl.net<p>";
	//isdsl
	if (adslaccountid == "sosdsl")
		html = html + "SMTP (Outgoing Email) Server:<br>smtp.saix.net<p>";
	
	$("#support-process-result").html(html);
	
});

//====REPORT AN ISSUE====
$("#submit-report-issue").click(function () {
	//first, check if required fields have been filled out
	var count = 0;
	if ($("#name").attr("value") == "")
	{
		count++;
		$("#name").css("background-color","#fee1e1");
	}
	if ($("#email").attr("value") == "")
	{
		count++;
		$("#email").css("background-color","#fee1e1");
	}
	if ($("#browser").attr("value") == "")
	{
		count++;
		$("#browser").css("background-color","#fee1e1");
	}
	if ($("#page").attr("value") == "")
	{
		count++;
		$("#page").css("background-color","#fee1e1");
	}
	if ($("#description").attr("value") == "")
	{
		count++;
		$("#description").css("background-color","#fee1e1");
	}
	if (count == 0)
	{
		//continue with recaptcha
		//create the recaptcha
		Recaptcha.create("6LfGKwAAAAAAAP6GEFOP26cik1vcrwbiLj6C_qmN", "recaptcha-form", {
		theme: "red",
		callback: Recaptcha.focus_response_field});
		//show the overlay div
		$("#page-overlay").fadeIn(300);
	}
	return false; //stop the page changing
});

$("#submit-recaptcha-issue").click(function() {
	//hide the submit button, show the loading icon
	$("#recaptcha-button").hide();
	$("#recaptcha-loading").show();
	//first, check if recaptcha is correct - get the given recaptcha, and the user's response.
	challengeField = $("input#recaptcha_challenge_field").val(); //this is all gumbled
    responseField = $("input#recaptcha_response_field").val(); //this is clear text of what the user has writter
	//post the data to recaptcha.asp
	$.ajax({
		type: "POST",
		url: "include/recaptcha.asp",
		data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
		success: function(data) { //note the "data" - this will get the result from recaptcha.asp
			if (data == "success")
			{
				//captcha correct, submit the contact form
				//get the various variables
				var name = $("#name").attr("value");
				var email = $("#email").attr("value");
				var browser = $("#browser").attr("value");
				var page = $("#page").attr("value");
				var description = $("#description").attr("value");
	
				var datastring = "name="+name+"&email="+email+"&browser="+browser+"&page="+page+"&description="+description;
	
				//post the data to process.asp
				$.ajax({
					type: "POST",
					url: "process.asp?do=reportissue",
					data: encodeURI(datastring),
					success: function(data) { //note the "data" - this will get the result from process.asp
						$("#page-overlay").fadeOut(300);
						$("#report-issue-success").html(data);
						$("#report-issue-form").slideUp();
						$("#report-issue-success").slideDown();
					}
				});
				$("#report-issue-form").slideUp();
				$("#report-issue-success").slideDown();
			}
			else
			{
				Recaptcha.reload();
				$("#recaptcha-infotext").attr("style","color: #970b0d");
				$("#recaptcha-infotext").html("Incorrect. Please try again.");
				$("#recaptcha-loading").hide();
				$("#recaptcha-button").show();
			}
		}
	});
	return false;
});

