/**
 * Cookie Policy
 */
function checkForCookie(destination) {
	chkcookie = 'cktest';
	
	if (document.cookie.indexOf(chkcookie, 0) < 0) {
		document.cookie = "chkcookie=" + chkcookie + "; path=/";
	}
	
	if (document.cookie.indexOf(chkcookie, 0) < 0) {
		cookieDialog();
	}
	else
	{
		window.location = destination;
	}
}

/**
 * Cookie Policy
 */
function mobileCheckForCookie(destination) {
	chkcookie = 'cktest';
	
	if (document.cookie.indexOf(chkcookie, 0) < 0) {
		document.cookie = "chkcookie=" + chkcookie + "; path=/";
	}
	
	if (document.cookie.indexOf(chkcookie, 0) < 0) {
		window.location = './cookie_policy';
	}
	else
	{
		window.location = destination;
	}
}

/**
 * Cookie Dialog
 */
function cookieDialog() {
	$("body").append("<div id='grayout'><div id='cookie-dialog'/></div>");
	$("#grayout").show();
	
	var cookiePolicyUrl = './cookie_policy';
	
	$("#cookie-dialog").load(cookiePolicyUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height: 300,
		width: 400,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
             $('#cookie-dialog').remove();
	         $('#grayout').remove();
		}
	});
}

/**
 * Large Video Dialog
 */
function largeVideoDialog(videoPath) {
	
	$("body").append("<div id='grayout'><div id='video-dialog'/></div>");
	$("#grayout").show();
	
	var videoUrl = './video-dialog/' + videoPath + '?format=large';
	
	$("#video-dialog").load(videoUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height: 530,
		width: 680,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
             $('#video-dialog').remove();
	         $('#grayout').remove();
		}
	});
}

/**
 * Video Dialog
 */
function videoDialog(videoPath) {
	
	$("body").append("<div id='grayout'><div id='video-dialog'/></div>");
	$("#grayout").show();
	
	var videoUrl = './video-dialog/' + videoPath;
	
	$("#video-dialog").load(videoUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height: 425,
		width: 400,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
             $('#video-dialog').remove();
	         $('#grayout').remove();
		}
	});
}

/**
 * Contact Us Pop-up
 */
function contactusDialog(cmd) {
	
	$("body").append("<div id='grayout'><div id='contactus-dialog'/></div>");
	$("#grayout").show();
	
	var contactusUrl = './'+cmd;
	var height = 640;
	var width = 660;
	if(cmd == 'contactussol')
	{
		height = 480;
		width = 630;
	}
	
	$("#contactus-dialog").load(contactusUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
                            //$("#contactus-dialog").replaceWith(responseText);
			}).dialog( {
		height : height,
		width : width,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
                 $('#contactus-dialog').remove();
	         $('#grayout').remove();
                 
		}
	});
}

function sendMail() {
}


/**
 * upsellDialog
 * @param upsellUrl: The URL to request the upsell details
 */
function upsellDialog(upsellUrl) {
	$("body").append("<div id='grayout'><div id='upsell-dialog'/></div>");
	$("#grayout").show();
	$("#upsell-dialog").load(upsellUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height :575,
		width : 800,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		close : function(ev, ui) {
			$(this).remove();
			$("#grayout").remove();
			$("#upsell-dialog").remove();
		}
	});
}

/**
 * androidDialog
 * @param androidUrl: The URL to request the android bar code image
 */
function androidDialog(upsellUrl) {
	$("body").append("<div id='grayout'><div id='android-dialog'/></div>");
	$("#grayout").show();
	$("#android-dialog").load(upsellUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height :575,
		width :690,
		draggable :false,
		close : function(ev, ui) {
			$(this).remove();
			$("#grayout").remove();
			$("#android-dialog").remove();
		}
	});
}

/**
 * Eula Pop-up
 */
function eulaDialog() {
	
	$("body").append("<div id='grayout'><div id='eula-dialog'/></div>");
	$("#grayout").show();
	
	var eulaUrl = './end_user_license_agreement';
	
	$("#eula-dialog").load(eulaUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height : 600,
		width : 600,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
                 $('#eula-dialog').remove();
	         $('#grayout').remove();
                 
		}
	});
}

/**
 * Security Codes Pop-up
 */
function securityCodesDialog() {
	
	$("body").append("<div id='grayout'><div id='security-codes-dialog'/></div>");
	$("#grayout").show();
	
	var scUrl = './security_codes';
	
	$("#security-codes-dialog").load(scUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height : 600,
		width : 600,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
                 $('#security-codes-dialog').remove();
	         $('#grayout').remove();
                 
		}
	});
}

/**
 * Privacy Policy Dialog
 */
function privacyDialog() {
	
	$("body").append("<div id='grayout'><div id='privacy-policy-dialog'/></div>");
	$("#grayout").show();
	
	var pvUrl = './privacy';
	
	$("#privacy-policy-dialog").load(pvUrl, {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height : 600,
		width : 600,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		closeOnEscape: false,
		close : function(ev, ui) {
                 $('#privacy-policy-dialog').remove();
	         $('#grayout').remove();
                 
		}
	});
}

/**
 * processPaymentDialog
 */
function processPaymentDialog() {
	
	$("body").append("<div id='grayout'><p class='payment-process'>Please wait while your order is processed.</p></div>");
	$("#grayout").show();
}

/**
 * Subscription Terms Dialog
 */
function subscriptionDialog() {
	$("body").append("<div id='grayout'><div id='subscription-terms-dialog'/></div>");
	$("#grayout").show();
	var url = './subscription_terms';
	
	$("#subscription-terms-dialog").load(url, {},
		function(responseText, textStatus, XMLHttpRequest) {
		}).dialog( {
			height : 600,
			width : 600,
			dialogClass : 'unbound-dialog',
			draggable :true,
			resizable :false,
			closeOnEscape: false,
			close : function(ev, ui) {
                 $('#subscription-terms-dialog').remove();
                 $('#grayout').remove();
			}
	});
}

function sendMail(id,cmd) {
	var args = "";
	$("#" + id + " input,#" + id + " select,#" + id + " textarea").each(function(arg){
		if($(this).attr("type") != 'radio')
		{
		    args += "&" + $(this).attr("name") + "=" + $(this).val();
	    }
		else if($(this).is(':checked'))
		{
			args += "&" + $(this).attr("name") + "=" + $(this).val();
		}
	});
	var url = "?cmd=" + cmd +  args;
	$.ajax( {
	  type : "POST",
	  url : url,
	  async : false,
	  data  : "",
	  success : function(data) {
	    var di = $("#" + id);
	    di.html(data);
	  }
	});
}



function multiYearPriceDialog() {
	$("body").append("<div id='grayout'><div id='myear-dialog'/></div>");
	$("#grayout").show();
	$("#myear-dialog").load("./multiyear", {},
			function(responseText, textStatus, XMLHttpRequest) {
			}).dialog( {
		height :500,
		width : 750,
		dialogClass : 'unbound-dialog',
		draggable :true,
		resizable :false,
		close : function(ev, ui) {
			$(this).remove();
			$("#grayout").remove();
			$("#myear-dialog").remove();
		}
	});
}

function updateMultiYearCart(years)
{
	
	$('span.activeprice').toggleClass('activeprice inactiveprice');
	$('span#' + years + 'YearMulti').toggleClass('activeprice inactiveprice');
	
	
   var url = "?cmd=multiyear&subcmd=update&duration=" + years;
	$.ajax( {
	  type : "POST",
	  url : url,
	  async : false,
	  data  : "",
	  success : function(data) {
	  }
	});
		
}
