var partnername1 = "";
var partnername2 = "";

var your_date_month = 0;
var your_date_date = 0;
var your_date_year = 0;

var partner_date_month = 0;
var partner_date_date = 0;
var partner_date_year = 0;

var resultstr1 = "";
var resultstr2 = "";

var marks = 0;

var counter = 0;

//localStorage.counters = 0;

$(document).ready(function() {
	$('#vserv_advt_slide, #vserv_advt_slide_popup').click(function(){
		localStorage.counters = 0;
	});
});

$(document).ready(function() {
	var height = parseInt(($(document).innerHeight() * 2)/3);
	
	$("#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",height-50);
	});
});


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



$(document).ready(function() {
	$('#clear').click(function()
	{
		document.getElementById('partnername1').value = null;
		document.getElementById('your_date_month').value = "";
		document.getElementById('your_date_date').value = "";
		document.getElementById('your_date_year').value = "";

		document.getElementById('partnername2').value = "";
		document.getElementById('partner_date_month').value = "";
		document.getElementById('partner_date_date').value = "";
		document.getElementById('partner_date_year').value = "";

		partnername1 = "";
		partnername2 = "";

		your_date_month = 0;
		your_date_date = 0;
		your_date_year = 0;

		partner_date_month = 0;
		partner_date_date = 0;
		partner_date_year = 0;

		resultstr1 = "";
		resultstr2 = "";

		marks = 0;
	});
});

$(document).ready(function() {
	$('#calc').click(function(){
		partnername1 = $("#partnername1").val();
		partnername2 = $("#partnername2").val();

		your_date_month = $("#your_date_month").val();
		your_date_date = $("#your_date_date").val();
		your_date_year = $("#your_date_year").val();

		partner_date_month = $("#partner_date_month").val();
		partner_date_date = $("#partner_date_date").val();
		partner_date_year = $("#partner_date_year").val();
		

		
		if(partnername1 == null || partnername1 == "")
			alert("Plz enter your name !");

		else if(your_date_month == null || your_date_month == "")
			alert("Plz enter your month of birth !");

		else if(your_date_date == null || your_date_date == "")
			alert("Plz enter your date of birth !");

		else if(your_date_year == null || your_date_year == "")
			alert("Plz enter your year of birth !");

		else if(isNaN(your_date_month) || isNaN(your_date_date) || isNaN(your_date_year))
			alert("Plz enter your valid date of birth.");

		else if(parseInt(your_date_month) < 1 || parseInt(your_date_month) > 12)
			alert("Plz enter your month of birth between 1-12.");

		else if(parseInt(your_date_date) < 1 || parseInt(your_date_date) > 31)
			alert("Plz enter your date between 1-31.");

		else if(parseInt(your_date_year) < 1000 || parseInt(your_date_year) > 3000)
			alert("Plz enter your valid year.");

		else if(!isLeapYear(parseInt(your_date_year)) && parseInt(your_date_month) == 2 && parseInt(your_date_date) > 28)
			alert("In your date of birth February month days cannot be more than 28 days.");

		else if(isLeapYear(parseInt(your_date_year)) && parseInt(your_date_month) == 2 && parseInt(your_date_date) > 29)
			alert("In your date of birth February month days cannot be more than 29 days.");

		else if((parseInt(your_date_month) == 4 || parseInt(your_date_month) == 6 || parseInt(your_date_month) == 9 || parseInt(your_date_month) == 11) && parseInt(your_date_date) > 30)
			alert("In your date of birth in this month Day cannot be more than 30");

		else if((parseInt(your_date_month) == 1 || parseInt(your_date_month) == 3 || parseInt(your_date_month) == 5 || parseInt(your_date_month) == 7 || parseInt(your_date_month) == 8 || parseInt(your_date_month) == 10 || parseInt(your_date_month) == 12) && parseInt(your_date_date) > 31)
			alert("In your date of birth in this month Day cannot be more than 31");

		//*******		

		else if(partnername2 == null || partnername2 == "")
			alert("Plz enter your partner name !");

		else if(partner_date_month == null || partner_date_month == "")
			alert("Plz enter your partner month of birth !");

		else if(partner_date_date == null || partner_date_date == "")
			alert("Plz enter your partner date of birth !");

		else if(partner_date_year == null || partner_date_year == "")
			alert("Plz enter your partner year of birth !");

		else if(isNaN(partner_date_month) || isNaN(partner_date_date) || isNaN(partner_date_year))
			alert("Plz enter partner valid date of birth.");

		else if(parseInt(partner_date_month) < 1 || parseInt(partner_date_month) > 12)
			alert("Plz enter partner month of birth between 1-12.");

		else if(parseInt(partner_date_date) < 1 || parseInt(partner_date_date) > 31)
			alert("Plz enter partner date between 1-31.");

		else if(parseInt(partner_date_year) < 1000 || parseInt(partner_date_year) > 3000)
			alert("Plz enter partner valid year.");

		else if(!isLeapYear(parseInt(partner_date_year)) && parseInt(partner_date_month) == 2 && parseInt(partner_date_date) > 28)
			alert("In partner date of birth February month days cannot be more than 28 days.");

		else if(isLeapYear(parseInt(partner_date_year)) && parseInt(partner_date_month) == 2 && parseInt(partner_date_date) > 29)
			alert("In partner date of birth February month days cannot be more than 29 days.");

		else if((parseInt(partner_date_month) == 4 || parseInt(partner_date_month) == 6 || parseInt(partner_date_month) == 9 || parseInt(partner_date_month) == 11) && parseInt(partner_date_date) > 30)
			alert("In partner date of birth Day cannot be more than 30");

		else if((parseInt(partner_date_month) == 1 || parseInt(partner_date_month) == 3 || parseInt(partner_date_month) == 5 || parseInt(partner_date_month) == 7 || parseInt(partner_date_month) == 8 || parseInt(partner_date_month) == 10 || parseInt(partner_date_month) == 12) && parseInt(partner_date_date) > 31)
			alert("In partner date of birth Day cannot be more than 31");
		else
		{
			counter = Number(localStorage.counters);

			if(isNaN(counter))
				counter = 0;
			
			if(counter >= 5)
			{
				alert("Time to buy me a BEER. Kindly visit and click OFFERS..\nYou will get 5 chances to test 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.counters)
					localStorage.counters = Number(localStorage.counters) + 1;
				else
					localStorage.counters = 1;

				calculate();

				if(marks == 30)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(red, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(red, yellow)";
					document.getElementById("sign").src = "css/down.png";
					document.getElementById("percent").style.background = "#ff0000";

				}

				if(marks == 40)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(red, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(red, yellow)";
					document.getElementById("sign").src = "css/down.png";
					document.getElementById("percent").style.background = "#ff0000";
				}

				if(marks == 50)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(red, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(red, yellow)";
					document.getElementById("sign").src = "css/down.png";
					document.getElementById("percent").style.background = "#ff0000";
				}

				if(marks == 60)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(green, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(green, yellow)";
					document.getElementById("sign").src = "css/up.png";
					document.getElementById("percent").style.background = "#00aa00";
				}

				if(marks == 70)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(green, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(green, yellow)";
					document.getElementById("sign").src = "css/up.png";
					document.getElementById("percent").style.background = "#00aa00";
				}

				if(marks == 80)
				{
					document.getElementById("explain").style.background = "-moz-linear-gradient(green, yellow)";
					document.getElementById("explain").style.background = "-webkit-linear-gradient(green, yellow)";
					document.getElementById("sign").src = "css/ok.png";
					document.getElementById("percent").style.background = "#00aa00";
				}

				document.getElementById("names").innerHTML = "<h3 style='color:#ffffff;'>" + partnername1.toUpperCase() + " <br/>&<br/>" + partnername2.toUpperCase() + "</h3>";
				document.getElementById("percent").innerHTML = "<b>" + marks + "%" + "</b>";
				document.getElementById("explain").innerHTML = resultstr2;

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

function isLeapYear(year)
{
	if (year % 4 != 0)
	{
		return false;
	}
	else if (year % 400 == 0)
	{
		return true;
	}
	else if (year % 100 == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function sunsign(bmonth, bday)
{
	var sun = 0;

	if(bmonth == 1)
	{
		if(bday <21) sun = 10;
		else sun = 11;
	}
	else if(bmonth == 2)
	{
		if(bday <20) sun = 11;
		else sun = 12;
	}
	else if(bmonth == 3)
	{
		if(bday <21) sun = 12;
		else sun = 1;  
	}

	else if(bmonth == 4)
	{
		if(bday <21) sun = 1;
		else sun = 2;  
	}

	else if(bmonth == 5)
	{
		if(bday <22) sun = 2;
		else sun = 3;  
	}

	else if(bmonth == 6)
	{
		if(bday <22) sun = 3;
		else sun = 4;  
	}

	else if(bmonth == 7)
	{
		if(bday <22) sun = 4;
		else sun = 5;  
	}

	else if(bmonth == 8)
	{
		if(bday <23) sun = 5;
		else sun = 6;  
	}

	else if(bmonth == 9)
	{
		if(bday <23) sun = 6;
		else sun = 7;  
	}

	else if(bmonth == 10)
	{
		if(bday <23) sun = 7;
		else sun = 8;  
	}

	else if(bmonth == 11)
	{
		if(bday <21) sun = 8;
		else sun = 9;  
	}

	else if(bmonth == 12)
	{
		if(bday <22) sun = 9;
		else sun = 10;  
	}

	return sun;
}

function friendlyname(x, y)
{
	var res = 0;

	if(x==1){
		if(y == 2 || y == 3 || y == 4 || y == 5) res = 1;
	}
	else if(x==2){
		if(y == 3 || y == 4 || y == 6 || y == 7) res = 1;
	}
	else if(x==3){
		if(y == 2 || y == 3 || y == 5 || y == 9) res = 1;
	}
	else if(x==4){
		if(y == 1 || y == 4 || y == 6 || y == 8) res = 1;
	}
	else if(x==5){
		if(y == 1 || y == 3 || y == 5 || y == 6) res = 1;
	}
	else if(x==6){
		if(y == 4 || y == 5 || y == 6 || y == 9) res = 1;
	}
	else if(x==7){
		if(y == 1 || y == 2 || y == 4) res = 1;
	}
	else if(x==8){
		if(y == 4 || y == 6 || y == 8) res = 1;
	}
	else if(x==9){
		if(y == 3 || y == 6 || y == 9) res = 1;
	}

	return res;  
}

function calculate()
{
	resultstr1 = "Your Love Percentage is: ";
	resultstr2 = "";

	var namenum1 = calculate1(partnername1);
	var namenum2 = calculate1(partnername2);

	var count1 = friendlyname(namenum1, namenum2);

	var day1 = Math.floor(your_date_date);
	var bday1 = day1;
	var month1 = Math.floor(your_date_month);
	var bmonth1 = month1;
	var year1 = Math.floor(your_date_year);

	var day2 = Math.floor(partner_date_date);
	var bday2 = day2;
	var month2 = Math.floor(partner_date_month);
	var bmonth2 = month2;
	var year2 = Math.floor(partner_date_year);


	if(day1 >= 9)
		day1 = day1 % 9;

	if(day1 == 0)
		day1 = 9;

	if(day2 >= 9)
		day2 = day2 % 9;

	if(day2 == 0)
		day2 = 9;

	var compound1 = day1 + month1 + year1;

	var compound2 = day2 + month2 + year2;

	if(compound1 >=9) compound1 = compound1 % 9;
	if(compound1 == 0) compound1 = 9;

	if(compound2 >= 9) compound2 = compound2 % 9;
	if(compound2 == 0) compound2 = 9;

	var count2 = friendlyname(day1,day2);

		   //decide if compound numbers are friendly or not
	var count3 = friendlyname(compound1,compound2);

		   //decide if birth number to compound numbers are friendly or not
	var count4 = friendlyname(day1,compound2);
	var count5 = friendlyname(compound1,day2);

		   //calculate sunsigns of both
	var ssign1 = sunsign(bmonth1, bday1);
	var ssign2 = sunsign(bmonth2, bday2);

	var diff = 0;

		   //decide if sunsigns are compatible
	if(ssign1 > ssign2) diff = ssign1 - ssign2;
	else diff = ssign2 - ssign1; 

		   //for compatible sunsigns
	var count6 = 0;
	var count7 = 0;

	if(diff == 4 || diff == 0)
		count6 = 1;

	if(diff == 2)
		count7 = 1;

		   //now decide marks depending on counters.
	if(count1 == 1)
		marks=80;
	else if(count2 == 1 && count3 == 1)
		marks=80;
	else if(count4 == 1 && count5 == 1) 
		marks=70;
	else if(count2 == 1 && count4 == 1) 
		marks=60;
	else if(count2 == 1 && count5 == 1) 
		marks=60;
	else if(count6 == 1) 
		marks=60;
	else if(count2 == 1) 
		marks=50;
	else if(count7 == 1) 
		marks=50;
	else if(count3 == 1) 
		marks=40;
	else if(count4 == 1) 
		marks=40;
	else if(count5 == 1) 
		marks=40;
	else 
		marks=30;

		   //comment depending on marks
	if(marks==30) resultstr2 = resultstr2 + "Sorry, there is no love between you both. There is no compatibility at all. Hence there will be bad feelings developed and you may get separated from each other.";

	if(marks==40) resultstr2+="Probably you are continuing the relation with your lover in good hope that one day the things will turn into your favor. There will be misunderstandings and difference of opinion between you both. One of you will spoil the relation because of aggressiveness or mistrust.";

	if(marks==50) resultstr2+="Sorry, your love percentage is very low. There is psychological and physical incompatibility between you both. Since there is no mutual trust, one of you may change mind. It is better not to continue this relation.";

	if(marks==60) resultstr2+="Both of you love each other. That's fine! There is psychological and physical compatibility. But sometimes, misunderstandings will creep into your relation. Maintain coolness and never be aggressive. Then only your love will be successful.";

	if(marks==70) resultstr2+="That's good! You were born for each other. And hence there are chances of a long term relationship. There is psychological and physical compatibility. There is a very good understanding between you both which leads to a happy union.";

	if(marks==80) resultstr2+= "Wow, You got your soul mate! You will become an ideal couple. The way both of you think, the decisions you take and the way you react in different situations will be alike. Others envy your love. Try to make this relation a long lasting one.";

}

function calculate1(name)
{
	var arr1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
	var arr2 = [1,2,3,4,5,8,3,5,1,1,2,3,4,5,7,8,1,2,3,4,6,6,6,5,1,7];

	var str=name.toUpperCase();
	var msg;
	var num1=0;
	var n = str.length;

	for(var i=0; i<n; i++)
	{
		msg = str.charAt(i);
		for(var x=0; x<26; x++)
		{
			if(msg == arr1[x]) num1 = num1+ arr2[x];
		}

	}

	if(num1>=9) num1 = num1% 9;
	if(num1==0) num1 = 9;
	return num1;
}

////////////////////////////
$(document).on("pageshow","#advt_page",function(){
	$("#advt_div").find("img").css("width","100%");
	var height = $(document).innerHeight();
	height = (height - 120) + "px";
	$("#advt_div").find("img").css("height",height);
});



/*$(document).ready(function() {
	$("#donate_btn").click(function(event) {
		$("#donate_frm").submit();
	});
});
*/


$(document).on("pageshow","#page_5",function(){
	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": 300,
		"maxheight": 300,
		"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": 300,
		"maxheight": 300,
		"prevText": "< ",   // String: Text for the "previous" button
		"nextText": " >",       // String: Text for the "next" button
		
	});
});

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