jQuery(document).ready(function() {

	//Select all anchor tag with rel set to tooltip
	jQuery('a[rel=tooltip]').mouseover(function(e) {

			//Grab the title attribute's value and assign it to a variable
			var tip = jQuery(this).attr('name');

			//Append the tooltip template and its value
			jQuery(this).append('<div id="tooltip" style="display:none"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');

			//Set the X and Y axis of the tooltip
			jQuery('#tooltip').css('top', e.pageY + 5 );
			jQuery('#tooltip').css('left', e.pageX + 5 );

			//Show the tooltip with faceIn effect
			jQuery('#tooltip').fadeTo('10',0.95);

	});

	//Select all anchor tag with rel set to tooltip
	jQuery('a[rel=tooltip]').mouseout(function(e) {

			jQuery(this).children('div#tooltip').remove();

	});

	jQuery('.selectall').click(function(e) {
		jQuery(this).focus();
		jQuery(this).select();
	});

    // show existing AR
    showaroptions('cuslist_type',1);
});



function checkun()
{
    if(jQuery('#unsubscribe1').attr('checked'))
    {
        jQuery('#configure_unsubscribe').hide();
    }
    if(jQuery('#unsubscribe2').attr('checked'))
    {
        jQuery('#configure_unsubscribe').show();
    }
}


function checkwso()
{
    if(jQuery('#wsopro1').attr('checked'))
    {
        jQuery('#wsopro').hide();
    }
    if(jQuery('#wsopro2').attr('checked'))
    {
        jQuery('#wsopro').show();
    }
}

function checkclickbank()
{
    if(jQuery('#clickbank1').attr('checked'))
    {
        jQuery('#clickbank').hide();
    }
    if(jQuery('#clickbank2').attr('checked'))
    {
        jQuery('#clickbank').show();
    }
}

function checkdigiresults()
{
    if(jQuery('#digiresults1').attr('checked'))
    {
        jQuery('#digiresults').hide();
    }
    if(jQuery('#digiresults2').attr('checked'))
    {
        jQuery('#digiresults').show();
    }
}

function validateform()
{
    var valid = true;
//    alert(jQuery('#product_name').val());
    jQuery('.error').remove();

    var rfields = new Array("product_name","paypal_email",'access_code');
    var len = rfields.length;
    for(var i = 0; i<len; i++)
    {
        if(jQuery('#'+rfields[i]).val() == "")
        {
            var html = jQuery('#'+rfields[i]).parent().html();
            jQuery('#'+rfields[i]).parent().html(html+' <span class="error wpfl-error">Required field!</span>');
            valid = false;
        }
    }


    // verify email address
    var emailPattern = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
    var email = jQuery('#cuslist_email').val();
    if(email != "")
    {
        if(!emailPattern.test(email))
        {
            var html = jQuery('#cuslist_email').parent().html();
            jQuery('#cuslist_email').parent().html(html+' <span class="error wpfl-error">Must be the complete subscribe email list for you autoresponder.</span>');
            valid = false;
        }
    }

    if(!valid)
    {
        alert("Please fix the errors marked below!");
    }

    return valid;
}


function showaroptions(elem, id)
{
//    alert("here");
    jQuery('.ar_list_'+id).hide();
    var list = jQuery('#'+elem).val();
//    alert('#ar_list_'+list+'_'+id);
    jQuery('#ar_list_'+list+'_'+id).show();
    if(list == 'AW')
    {
        jQuery('#AR_list_AW_1_un').show();
    }
}

