// JavaScript For Add/Edit Products
function myVal(){
$("#txtCounter").val(0);
//GENERAL TAB

if ($("#txtCompanyOrDeveloper").val() == "" || $("#txtAuthorEmail").val() == "" || $("#txtProductType").val() == ""){
$("#GenTab").slideDown('fast');

if ($("#txtCompanyOrDeveloper").val() == ""){
$("#vCoDev").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vCoDev").slideUp('fast');
}
if ($("#txtAuthorEmail").val() == ""){
$("#vEA").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vEA").slideUp('fast');
}
if ($("#txtProductType").val() == ""){
$("#vPT").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vPT").slideUp('fast');
}
}else{
$("#GenTab").slideUp('fast');
}

//PRODUCT TAB

if ($("#txtProductName").val() == "" || $("#txtItemTitle").val() == "" || $("#txtCurrentVersion").val() == "" || $("#txtVersionDate").val() == "" || $("#txtLicenseType").val() == "" || $("#txtRequirements").val() == ""){
$("#ProdTab").slideDown('fast');
if ($("#txtProductName").val() == ""){
$("#vProdNam").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vProdNam").slideUp('fast');
}
if ($("#txtItemTitle").val() == ""){
$("#vShortProdNam").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vShortProdNam").slideUp('fast');
}
if ($("#txtCurrentVersion").val() == ""){
$("#vVN").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vVN").slideUp('fast');
}
if ($("#txtVersionDate").val() == ""){
$("#vVD").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vVD").slideUp('fast');
}
if ($("#txtLicenseType").val() == ""){
$("#vLicTyp").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vLicTyp").slideUp('fast');
}
if ($("#txtRequirements").val() == ""){
$("#vRL").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vRL").slideUp('fast');
}
}else{
$("#ProdTab").slideUp('fast');
}

//DESCRIPTION TAB
var oEditor2 = FCKeditorAPI.GetInstance( 'txtShortStory' ) ;
var DDC = oEditor2.GetXHTML('txtShortStory');	

var oEditor3 = FCKeditorAPI.GetInstance( 'txtDetailStory' ) ;
var DDC3 = oEditor3.GetXHTML('txtDetailStory');	

if (DDC == ""){
$("#DescTab").slideDown('fast');
$("#vShortProdDesc").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vShortProdDesc").slideUp('fast');
$("#DescTab").slideUp('fast');
}
if (DDC3 == ""){
var oEditorA = FCKeditorAPI.GetInstance( 'txtDetailStory' ) ;
oEditorA.SetHTML(DDC);	
}





//TRIAL TAB
if ($('#txtDemoVersion:checked').val() != null) {
	
var oEditorTT = FCKeditorAPI.GetInstance( 'txtTrialText' ) ;
var TT = oEditorTT.GetXHTML('txtTrialText');	
var oEditorTRT = FCKeditorAPI.GetInstance( 'txtTrialRequestText' ) ;
var TRT = oEditorTRT.GetXHTML('txtTrialRequestText');		

if ($("#txtTrialRequestEmail").val() == "" || $("#txtTrialTitle").val() == "" || TT == "" || TRT == ""){
$("#TrialTab").show('fast');
if ($("#txtTrialRequestEmail").val() == ""){
$("#vERN").show('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vERN").hide('fast');
}
if ($("#txtTrialTitle").val() == ""){
$("#vTPTitle").show('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vTPTitle").hide('fast');
}
if (TT == ""){
$("#vTPT").show('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vTPT").hide('fast');
}
if (TRT == ""){
$("#vTPSuc").show('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vTPSuc").hide('fast');
}
}else{
$("#TrialTab").hide('fast');
}
}

// PURCHASE TAB
if ($('#txtBuyOnline:checked').val() != null) {

var oEditorPP = FCKeditorAPI.GetInstance( 'txtPurchaseParagraph' ) ;
var PP = oEditorPP.GetXHTML('txtPurchaseParagraph');	
var oEditorPOP = FCKeditorAPI.GetInstance( 'txtPrice_OrderingParagraph' ) ;
var POP = oEditorPOP.GetXHTML('txtPrice_OrderingParagraph');	
var oEditorSP = FCKeditorAPI.GetInstance( 'txtSatisfactionParagraph' ) ;
var SP = oEditorSP.GetXHTML('txtSatisfactionParagraph');	

if ($("#txtPurchaseTitle").val() == "" || PP == "" || POP == "" || SP == "" || $("#txtPriceDescription1").val() == "" || $("#txtPrice1").val() == ""){
$("#PurchTab").slideDown('fast');
if ($("#txtPurchaseTitle").val() == ""){
$("#vPPT").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vPPT").slideUp('fast');
}
if (PP == ""){
$("#vPPW").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vPPW").slideUp('fast');
}
if (POP == ""){
$("#vPPI").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vPPI").slideUp('fast');
}
if (SP == ""){
$("#vPPSP").slideDown('fast');
$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
}else{
$("#vPPSP").slideUp('fast');
}
	if($("#txtPriceDescription1").val() == "" && $("#txtPrice1").val() == ""){
	$("#vPPPM").slideDown('fast');
	$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
	}else{
	$("#vPPPM").slideUp('fast');
	}
}else{
$("#PurchTab").slideUp('fast');
}
}
	
//SUPPORT TAB
if ($('#txtOfferSupport:checked').val() != null) {
var oEditorTST = FCKeditorAPI.GetInstance( 'txtSupportText' ) ;
var TST = oEditorTST.GetXHTML('txtSupportText');		
	
	
//if ($('#txtOfferSupport').attr('checked')) {
if ($("#txtSupportEmail").val() == "" || $("#txtSupportTitle").val() == "" || TST == ""){
$("#SuppTab").slideDown('fast');
	if($("#txtSupportEmail").val() == "" && $("#txtSupportPhone").val() == ""){
	$("#vSPS").slideDown('fast');
	$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
	}else{
	$("#vSPS").slideUp('fast');
	}

	if($("#txtSupportTitle").val() == ""){
	$("#vSPT").slideDown('fast');
	$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
	}else{
	$("#vSPT").slideUp('fast');
	}

	if(TST == ""){
	$("#vSPTXT").slideDown('fast');
	$("#txtCounter").val(parseFloat($("#txtCounter").val())+1);
	}else{
	$("#vSPTXT").slideUp('fast');
	}
}else{
$("#SuppTab").slideUp('fast');
}
}

if($("#txtCounter").val() > 0){
$(".vMSG").text("There are " + $("#txtCounter").val() + " errors that need to be fixed before this product can be saved. Fix the listed errors, and then try again!");
$(".vMSG").css("color","red");
$("#Saver").slideUp('fast');
$("#saver2").slideDown('fast');
}else{
$(".vMSG").text("Congratulations! You have successfully validated.  You may now choose to save and exit or proceed to the attachments manager to add a logo and other attachments to complete your new product entry.");
$(".vMSG").css("color","green");
$("#Saver").slideDown('fast');
$("#saver2").slideUp('fast');
}
}

function ItsOther(){
if($("#txtProductType").val()=="Other"){
$("#othHide").slideDown();
}else{
$("#othHide").slideUp();
}
}
function populateFolder(){
//var fdrName = myVal.replace(" ", "");
$("#txtProductFolder").val($("#txtItemTitle").val());
var myFolder = replaceAll($("#txtItemTitle").val()," ", "");
$("#txtProductFolder").val(myFolder);
}

function replaceAll(OldString,FindString,ReplaceString) {
  	var SearchIndex = 0;
  	var NewString = ""; 
  	while (OldString.indexOf(FindString,SearchIndex) != -1)    {
    	NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
    	NewString += ReplaceString;
    	SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
 	}
  	NewString += OldString.substring(SearchIndex,OldString.length);
  	return NewString;
}
function copyTo(){
var oEditor = FCKeditorAPI.GetInstance( 'txtDetailStory' ) ;
oEditor.SetHTML($("#txtShortStory").val());	
}



function SRST(){
var oEditor = FCKeditorAPI.GetInstance( 'txtTrialRequestText' ) ;
oEditor.SetHTML('<p align="justify">Your request for a trial/evaluation copy of <strong>' + $("#txtItemTitle").val() + '</strong> has been submitted.  Please be patient while we process your request!</p>');
}
function SRSTClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtTrialRequestText' ) ;
oEditor.SetHTML('');
}
function TPT(){
var oEditor = FCKeditorAPI.GetInstance( 'txtTrialText' ) ;
oEditor.SetHTML('<p align="justify">Get your free trial of <strong>' + $("#txtItemTitle").val() + '</strong> today! Simply fill in the form below (all fields are required). Then click the request button. You will be sent a free, no obligation trial copy of <strong>' + $("#txtItemTitle").val() + '</strong>. Then when you are ready, come back and buy a copy of your own.</p>');
}
function TPTClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtTrialText' ) ;
oEditor.SetHTML('');
}
function SWP(){
var oEditor = FCKeditorAPI.GetInstance( 'txtPurchaseParagraph' ) ;
oEditor.SetHTML( '<p align="justify">Thank you for your interest in purchasing <strong>' + $("#txtItemTitle").val() + '</strong>. Below you will find price information. Payments are made online using the PayPal service, to ensure a safe web transaction.</p>' ) ;
}
function SWPClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtPurchaseParagraph' ) ;
oEditor.SetHTML( '' ) ;
}
function SuWP(){
var oEditor = FCKeditorAPI.GetInstance( 'txtSupportText' ) ;
oEditor.SetHTML('<p align="justify">Need some help with <strong>' + $("#txtItemTitle").val() + '</strong>? No Problem! Simply fill in the form below (all fields are required). Include a detailed description of your question. Click on the Submit Request button. Your question will be delivered to our support staff. Please note that this request form is solely for questions regarding <strong>' + $("#txtItemTitle").val() + '</strong>, not for questions this website or other products. We may need to request further information from you in order to help with your support question.</p> ');
}
function SuWPClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtSupportText' ) ;
oEditor.SetHTML('');
}
function PBOI(){
var oEditor = FCKeditorAPI.GetInstance( 'txtPrice_OrderingParagraph' ) ;
oEditor.SetHTML('<p align="justify">All pricing is based on One User/One Computer. Please enter the number of licenses that you would like to purchase. Click the Buy Now button at the bottom of the screen. You will be sent via email <strong>' + $("#txtItemTitle").val() + '</strong> and a registration key, if necessary to activate license. Further instructions will be sent with the software.</p>');
}
function PBOIClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtPrice_OrderingParagraph' ) ;
oEditor.SetHTML('');
}
function PSP(){
var oEditor = FCKeditorAPI.GetInstance( 'txtSatisfactionParagraph' ) ;
oEditor.SetHTML('<p align="justify">Your satisfaction is very important to us! If you have not tried a trial version of ' + $("#txtItemTitle").val() + ' we urge you to do so before making a purchase.</p>');
}
function PSPClear(){
var oEditor = FCKeditorAPI.GetInstance( 'txtSatisfactionParagraph' ) ;
oEditor.SetHTML('');
}
function ClearSamplePrice(){
$("#txtPriceDescription1").val("");
$("#txtPrice1QTY1").val("1");
$("#txtPrice1QTY2").val("");
$("#txtPrice1").val("");
$("#txtPriceDescription2").val("");
$("#txtPrice2QTY1").val("");
$("#txtPrice2QTY2").val("");
$("#txtPrice2").val("");
$("#txtPriceDescription3").val("");
$("#txtPrice3QTY1").val("");
$("#txtPrice3").val("");

}
function SingleLevel(){
ClearSamplePrice();
$("#txtPriceDescription1").val($("#txtItemTitle").val() + " License (Each License)");
$("#txtPrice1QTY1").val("1");
$("#txtPrice1QTY2").val("");
$("#txtPrice1").val("50.00");

}
function DoubleLevel(){
ClearSamplePrice();
$("#txtPriceDescription1").val($("#txtItemTitle").val() + " License (1-2 Users-Each)");
$("#txtPrice1QTY1").val("1");
$("#txtPrice1QTY2").val("2");
$("#txtPrice1").val("50.00");

$("#txtPriceDescription2").val($("#txtItemTitle").val() + " License (3-19 Users-Each)");
$("#txtPrice2QTY1").val("3");
$("#txtPrice2").val("45.00");

}
function TripleLevel(){
ClearSamplePrice();
$("#txtPriceDescription1").val($("#txtItemTitle").val() + " License (1-2 Users-Each)");
$("#txtPrice1QTY1").val("1");
$("#txtPrice1QTY2").val("2");
$("#txtPrice1").val("50.00");

$("#txtPriceDescription2").val($("#txtItemTitle").val() + " License (3-19 Users-Each)");
$("#txtPrice2QTY1").val("3");
$("#txtPrice2QTY2").val("19");
$("#txtPrice2").val("45.00");

$("#txtPriceDescription3").val($("#txtItemTitle").val() + " License (20+ Users-Each)");
$("#txtPrice3QTY1").val("20");
$("#txtPrice3").val("40.00");

}
function promoOnOff(){

if ($('#txtProvidePromos').attr('checked')) {
  $(".PrCode1").text("Promotional Code "); 
  $(".PrCode2").show('fast')
  $(".PDesc").slideDown();
}else{
  $(".PrCode1").text("Promo Option Unavailable");
  $(".PrCode2").hide('fast');  
  $(".PDesc").slideUp();
}
}
function supportOnOff(){
if ($('#txtOfferSupport').attr('checked')) {
  $("#support").show('fast')
}else{
  $("#support").hide('fast');  
}
}
function trialOnOff(){
if ($('#txtDemoVersion').attr('checked')) {
  $("#trial").show('fast')
}else{
  $("#trial").hide('fast');  
}
}
function purchaseOnOff(){
if ($('#txtBuyOnline').attr('checked')) {
  $("#purchaseS").show('fast')
}else{
  $("#purchaseS").hide('fast');  
}
}
function ClearIt(){
$("#purchase").val("");
$("#qty").val("");
}
function Calcu(){
$("#promoamt").val("");
$(".PDesc").slideUp();
if(!$("#txtPriceDescription1").val()){var d1 = "E"}else{var d1 = "F"}
if($("#txtPrice1QTY1").val()=="1"){var p1 = "F"}else{var p1 = "E"}
//if(!$("#txtPrice1QTY1").val()){var p1 = "E"}else{var p1 = "F"}
if(!$("#txtPrice1QTY2").val()){var p1a = "E"}else{var p1a = "F"}
if(!$("#txtPrice1").val()){var pr1 = "E"}else{var pr1 = "F"}

if(!$("#txtPriceDescription2").val()){var d2 = "E"}else{var d2 = "F"}
if(!$("#txtPrice2QTY1").val()){var p2 = "E"}else{var p2 = "F"}
if(!$("#txtPrice2QTY2").val()){var p2a = "E"}else{var p2a = "F"}
if(!$("#txtPrice2").val()){var pr2 = "E"}else{var pr2 = "F"}

if(!$("#txtPriceDescription3").val()){var d3 = "E"}else{var d3 = "F"}
if(!$("#txtPrice3QTY1").val()){var p3 = "E"}else{var p3 = "F"}
if(!$("#txtPrice3").val()){var pr3 = "E"}else{var pr3 = "F"}


var Q = parseFloat($("#qty").val());
var p1_1 = parseFloat($("#txtPrice1QTY1").val());
var p1_2 = parseFloat($("#txtPrice1QTY2").val());
var p2_1 = parseFloat($("#txtPrice2QTY1").val());
var p2_2 = parseFloat($("#txtPrice2QTY2").val());
var p3_1 = parseFloat($("#txtPrice3QTY1").val());





if(d1=="F" && p1=="F" && p1a=="E" && pr1=="F" && d2=="E"){
// This is a single Price Point w/no Qty discounts
$("#typeMSG").text("( This is a single Price Point model with no quantity discounts. )");
var preval = Q * $("#txtPrice1").val();



}else if(d1=="F" && p1=="F" && p1a=="F" && pr1=="F" && d2=="F" && p2=="F" && p2a=="E" && pr2=="F" && d3=="E"){
// This is a multiple qty model with only 2 levels
$("#typeMSG").text("( This is a Multiple Price Point model with only 2 levels. )");
if(Q >= 1 && Q >= p1_1 && Q <= p1_2 ){
var preval = Q * $("#txtPrice1").val();
}else if(Q >= p2_1){
var preval = Q * $("#txtPrice2").val();
}





}else if(d1=="F" && p1=="F" && p1a=="F" && pr1=="F" && d2=="F" && p2=="F" && p2a=="F" && pr2=="F" && d3=="F" && p3=="F" && pr3=="F"){
// This is a multiple qty model with all 3 levels utilized
$("#typeMSG").text("( This is a Multiple Price Point model with all 3 levels utilized. )");
if(Q >= 1 && Q <= p1_2 ){
var preval = Q * $("#txtPrice1").val();

}else if( Q >= p2_1 && Q <= p2_2 ){
var preval = Q * $("#txtPrice2").val();

}else if(Q >= p3_1){
var preval = Q * $("#txtPrice3").val();
}


}else{
$("#typeMSG").text("( There is a problem with your pricing model. )");
}


if(d1=="E"){
alert("You will need to establish your pricing model, above, before testing.  Please enter your model, and then try again.");
$("#qty").val("");
}else{


if($("#qty").val() == "" || $("#qty").val() == 0){
$("#purchase").val("");
$("#total").val("");


}else{
$("#purchase").val(preval + ".00");
$("#total").val(preval + ".00");
}
}
}

function GetIt(){
if($("#qty").val().length==0 ){ 
$(".PDesc").css("color","red");
$(".PDesc").text("Please enter a quantity before applying your promotional code."); 
}else{
$(".PDesc").slideDown('fast');
$(".PDesc").css("color","green");
$(".PDesc").text("$10.00 promo discount applied to each item purchased.");
var PromoDollars = 10;
var ttlPromo = PromoDollars*$("#qty").val();
$("#promoamt").val("-" + ttlPromo + ".00");
var theTTL = $("#purchase").val()-ttlPromo;
$("#total").val(theTTL + ".00");
}}
function fillTitles(){
$("#txtPurchaseTitle").val("Purchase " + $("#txtItemTitle").val());
$("#txtTrialTitle").val("Request A Free Trial Of " + $("#txtItemTitle").val());
$("#txtSupportTitle").val("Need Help With " + $("#txtItemTitle").val() + "?");
}
function checkEmail(str) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(str)) {
alert("[ " + str + " ] appears to be an invalid email address.  Please check the address, and reenter.");
return false;
}
}

