var clickcounter = 0;
//localStorage.clikccounters = 0;

var ad_height;


$(document).ready(function() {
	$("#vserv_advt_slide, #vserv_advt_slide_popup").click('pageshow', function(event) {
		localStorage.clikccounters = 0;
	});
});

$(document).ready(function() {
	$("#submit").click('pageshow', function(event) {
		clickcounter = Number(localStorage.clikccounters);

		if(isNaN(clickcounter))
			clickcounter = 0;
		
		if(clickcounter >= 5)
		{
			alert("Time to buy me a beer. \nKindly click and visit offers. \nYou will get 5 chances to test for compatibility.\n(If advt. not shown...plz check your internet connection and reload apps.)");
			$.mobile.changePage("#advt_page", { transition: "slide", changeHash: true});
		}
		else
		{
			if(localStorage.clikccounters)
				localStorage.clikccounters = Number(localStorage.clikccounters) + 1;
			else
				localStorage.clikccounters = 1;

			
			var strlen1 = 0;
			var strlen2 = 0;

			var count1 = 0;
			var count2 = 0;
			var len1 = 0;
			var len2 = 0;
			var totalchar = 0;
			var match = "";
			var result = "";

			var fname1 = document.getElementById('partner1').value;
			var fname2 = document.getElementById('partner2').value;

			var dummy1 = fname1.toUpperCase().trim().replace(/ /g, '');
			var dummy2 = fname2.toUpperCase().trim().replace(/ /g, '');

			if ((fname1.length < 2) || (fname2.length < 2) || fname1.indexOf("0")!= -1 || fname2.indexOf("0")!= -1  || fname1.indexOf("1")!= -1 || fname2.indexOf("1")!= -1  || fname1.indexOf("2")!= -1 || fname2.indexOf("2")!= -1  || fname1.indexOf("3")!= -1 || fname2.indexOf("3")!= -1  || fname1.indexOf("4")!= -1 || fname2.indexOf("4")!= -1  || fname1.indexOf("5")!= -1 || fname2.indexOf("5")!= -1  || fname1.indexOf("6")!= -1 || fname2.indexOf("6")!= -1  || fname1.indexOf("7")!= -1 || fname2.indexOf("7")!= -1  || fname1.indexOf("8")!= -1 || fname2.indexOf("8")!= -1  || fname1.indexOf("9")!= -1 || fname2.indexOf("9")!= -1  || fname1.indexOf(".")!= -1 || fname2.indexOf(".")!= -1  || fname1.indexOf(",")!= -1 || fname2.indexOf(",")!= -1  || fname1.indexOf("/")!= -1 || fname2.indexOf("/")!= -1  || fname1.indexOf(";")!= -1 || fname2.indexOf(";")!= -1  || fname1.indexOf("(")!= -1 || fname2.indexOf("(")!= -1  || fname1.indexOf(")")!= -1 || fname2.indexOf(")")!= -1  || fname1.indexOf("-")!= -1 || fname2.indexOf("-")!= -1  || fname1.indexOf("*")!= -1 || fname2.indexOf("*")!= -1  || fname1.indexOf("&")!= -1 || fname2.indexOf("&")!= -1  || fname1.indexOf("@")!= -1 || fname2.indexOf("@")!= -1  || fname1.indexOf("#")!= -1 || fname2.indexOf("#")!= -1  || fname1.indexOf("$")!= -1 || fname2.indexOf("$")!= -1  || fname1.indexOf("%")!= -1 || fname2.indexOf("%")!= -1 || fname1.indexOf("'")!= -1 || fname2.indexOf("'")!= -1 || fname1.indexOf("?")!= -1 || fname2.indexOf("?")!= -1 || fname1.indexOf("!")!= -1 || fname2.indexOf("!")!= -1 || fname1.indexOf("<")!= -1 || fname2.indexOf("<")!= -1 || fname1.indexOf(">")!= -1 || fname2.indexOf(">")!= -1 || fname1.indexOf("[")!= -1 || fname2.indexOf("[")!= -1 || fname1.indexOf("]")!= -1 || fname2.indexOf("]")!= -1 || fname1.indexOf("{")!= -1 || fname2.indexOf("{")!= -1 || fname1.indexOf("}")!= -1 || fname2.indexOf("}")!= -1 || fname1.indexOf("=")!= -1 || fname2.indexOf("=")!= -1 || fname1.indexOf("\"")!= -1 || fname2.indexOf("\"")!= -1 || fname1.indexOf("`")!= -1 || fname2.indexOf("`")!= -1 || fname1.indexOf("\\")!= -1 || fname2.indexOf("\\")!= -1 || fname1.indexOf("+")!= -1 || fname2.indexOf("+")!= -1 || fname1.indexOf("_")!= -1 || fname2.indexOf("_")!= -1 || fname1.indexOf("~")!= -1 || fname2.indexOf("~")!= -1 || fname1.indexOf("^")!= -1 || fname2.indexOf("^")!= -1 || fname1.indexOf(":")!= -1 || fname2.indexOf(":")!= -1 || fname1.indexOf("|")!= -1 || fname2.indexOf("|")!= -1)
			{
				alert("Plz enter name in alpha character only.");
			}
			else
			{
				strlen1 = fname1.length;
				strlen2 = fname2.length;

				for (var i = 0; i < strlen1; i++)
				{
					for (var j = 0; j < strlen2; j++)
					{
						if (dummy1.charAt(i) == dummy2.charAt(j))
						{
							dummy1 = dummy1.substring(0,i) + "*" + dummy1.substring(i+1);
							dummy2 = dummy2.substring(0,j) + "*" + dummy2.substring(j+1);
						}
					}
				}

				for (var k = 0; k < strlen1; k++)
				{
					if (dummy1.charAt(k) == '*') {
						count1++;
					}
				}
				for (var l = 0; l < strlen2; l++)
				{
					if (dummy2.charAt(l) == '*') {
						count2++;
					}
				}

				len1 = strlen1 - count1;
				len2 = strlen2 - count2;

				totalchar = len1 + len2;

				if(totalchar == 1)
					match = "ENMITY";

				else if(totalchar == 2)
					match = "AFFECTION";

				else if(totalchar == 3)
					match = "MARRIAGE";

				else if(totalchar == 4)
					match = "FRIEND";

				else if(totalchar == 5)
					match = "LOVE";

				else if(totalchar == 6)
					match = "MARRIAGE";

				else if(totalchar == 7)
					match = "MARRIAGE";

				else if(totalchar == 8)
					match = "FRIEND";

				else if(totalchar == 9)
					match = "LOVE";

				else if(totalchar == 10)
					match = "MARRIAGE";

				else if(totalchar == 11)
					match = "ENMITY";

				else if(totalchar == 12)
					match = "AFFECTION";

				else if(totalchar == 13)
					match = "LOVE";

				else if(totalchar == 14)
					match = "AFFECTION";

				else if(totalchar == 15)
					match = "FRIEND";

				else if(totalchar == 16)
					match = "AFFECTION";

				else if(totalchar == 17)
					match = "MARRIAGE";

				else if(totalchar == 18)
					match = "FRIEND";

				else if(totalchar == 19)
					match = "FRIEND";

				else if(totalchar == 20)
					match = "AFFECTION";

				else if(totalchar == 21)
					match = "MARRIAGE";

				else if(totalchar == 22)
					match = "FRIEND";

				else if(totalchar == 23)
					match = "LOVE";

				else if(totalchar == 24)
					match = "ENMITY";

				else if(totalchar == 25)
					match = "MARRIAGE";

				else if(totalchar == 26)
					match = "LOVE";		

				if(match == "FRIEND")
					document.getElementById('result').style.color = '#0000FF';

				else if(match == "LOVE")
					document.getElementById('result').style.color = '#F27CF0';

				else if(match == "AFFECTION")
					document.getElementById('result').style.color = '#e1e56F';

				else if(match == "MARRIAGE")
					document.getElementById('result').style.color = '#FF0000';

				else if(match == "ENMITY")
					document.getElementById('result').style.color = '#8D06BA';

				$("#resultpartner1").text(fname1.toUpperCase());
				$("#resultpartner2").text(fname2.toUpperCase());


				$('#result').text(match);

				$.mobile.changePage("#page_4", { transition: "slide", changeHash: true});
			}
		}
		
	});
});


function resetclickcounter()
{
    clickcounter = 0;
}

$(document).ready(function() {
	$("#clear_btn").click('pageshow', function(event) {
		$('#partner1').val("");
		$('#partner2').val("");
	});
});


////////////////////////////
$(document).ready(function() {
	var height = $(document).innerHeight();
	height = (height - 120) + "px";
	ad_height = (height - 120);

	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height(height);



});


var advttimer = setInterval(function(){
	$.mobile.changePage('#popup_advt_page', {
		transition : 'pop',
			     role       : 'dialog'
	});
}, 180000);

$(document).ready(function() {
	var height = parseInt(($(document).innerHeight() * 2)/3);

	ad_height = parseInt($(document).innerHeight() * 0.6);

	$("#vserv_advt_slide li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",height-50);
	});
	
	$("#vserv_advt_slide_popup li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",height-50);
	});
	
	$("#clickbank_advt_popup li").each(function(){
		$(this).find("img").css("width","100%");
		$(this).find("img").css("height",ad_height);
	});
});

$(document).on("pageshow","#home",function(){
	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height("0px");
	$(".ui-content").height(height);
});

$(document).on("pageshow","#page_1",function(){
	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height("0px");
	$(".ui-content").height(height);
});

$(document).on("pageshow","#page_2",function(){
	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height("0px");
	$(".ui-content").height(height);
});

$(document).on("pageshow","#page_3",function(){
	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height("0px");
	$(".ui-content").height(height);
});


$(document).on("pageshow","#page_4",function(){
	var height = $(document).innerHeight();
	var headerhgt = $(".ui-header").innerHeight();
	height = height - headerhgt;
	$(".ui-content").height("0px");
	$(".ui-content").height(height);

	var glow = $('.glow');
	setInterval(function(){
		glow.hasClass('glow')? glow.removeClass('glow'):glow.addClass('glow');
	}, 1000);	
});

$(window).load(function(){
	$("#vserv_advt_slide").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

$(window).load(function(){
	$("#vserv_advt_slide_popup").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});

$(window).load(function(){
	$("#clickbank_advt_popup").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
	});	
});


$(window).load(function(){
	$("#clickbank_advt1").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"manualControls": "",
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
		"nav": true
	});
});

$(window).load(function(){
	$("#clickbank_advt2, #clickbank_advt2_result").responsiveSlides({
		"auto": true,
		"pause": false,
		"pauseControls": false,
		"namespace": "rslides",
		"nav": true,
		"maxwidth": 250,
		"maxheight": 250,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button

	});
});


$(document).ready(function() {
	$("#vserv_advt_slide_popup, #clickbank_advt_popup").find("img").css("height",ad_height);
});


///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
