/**
 * When document full loaded and ready
 */
$(document).ready(function() {
    // Modified exernal links
 	$('[rel=external]').each(function() {
  		$(this).attr('target','_blank');
  	});           
});

/**
 * Cookie function
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
 * Generate a random email alias
 */
function getRandomPassword() {
	var arrCo      = new Array("1","2","3","4","5","6","7","8","9","b","c","d","f","g","h","j","k","l","m","n","p","r","s","t","v","w","x","y","z");
 	var arrVo      = new Array("a","e","i","o","u");
 	var intC,intV;
    var strRetVal  = '';
 	for (var i=0; i<5; i++) {
        intC = Math.ceil(Math.random() * 1000) % 25;
        intV = Math.ceil(Math.random() * 1000) % 5;
        strRetVal+= arrCo[intC] + arrVo[intV];
	}
    return strRetVal;
}

/**
 * Show loading icon
 */ 
function loading(booShow) {
    if (booShow) {
        $('#iconLoading').css('display', 'block');    
    } else {
        $('#iconLoading').css('display', 'none');    
    }
}

/**
 * Set no payment
 */ 
function setPaymentView(element) {
    if ($(element+':checked').val() == 'on') {
        $(element).attr('checked', true);
    } else {
        $(element).attr('checked', false);
    }
    if ($(element).attr('checked')) {
        $.cookie("noPayment", 1 , { expires: 1 });
    } else {
        $.cookie("noPayment", null);
    }
}

