var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);
}
var IE  = ((iePos!=-1));
var IE6 = (IE && is_major == 6);

function checkDebateForm(comment_id)
{	
	xajax_checkDebateForm(xajax.getFormValues('addcomment_' + comment_id), comment_id);
	return false;
}

function checkInviteFriendsLogin() 
{
    xajax_checkInviteFriendsLogin(xajax.getFormValues('invite_friends_login_form'));
    return false;
}

function checkInviteFriendsSelectContacts() 
{
    document.getElementById('cancelBtn').disabled = true;
    xajax_checkInviteFriendsSelectContacts(xajax.getFormValues('formlist'));
    return false;
}

function sendInvitations() 
{
    document.getElementById('cancelBtn').disabled = true;
    xajax_sendInvitations(xajax.getFormValues('mailForm'));
    return false;
}

function cancelInviteImport()
{
    xajax_cancelInviteImport();
    window.location = '/main.php?a=invite.send_invitation';
    return false;
}

function cancelInviteProcess(username)
{
    xajax_cancelInviteProcess();
    window.location ='/' + username + '/';
    return false;
}

/**
 *
 */
function deleteUserPhoto(photo_id) {
	if ( photo_id ) {
		if ( !confirm('Are you sure you want to delete this photo?') ) {
			return false;
		}
	}
	xajax_deleteUserPhoto(photo_id);
	return false;
}


/********************************************************************************
 * BEGIN: FRIEND / FOE LINKS
 *******************************************************************************/

function showLoginWarning()
{
    $('#loginWarning').show();
    return false;
}

/********************************************************************************
 * END: FRIEND / FOE LINKS
 *******************************************************************************/

/**
 *
 */
function addUserFavorite(favorite_id, favorite_type, rating) {

    theID = "favorite_" + favorite_type + "_" + favorite_id;

    $("a.s").each(function() {
        if($(this).attr("id") == theID) {
            $(this).html("Delete From Favorites");
            $(this).attr("href", "javascript:delUserFavorite('" + favorite_id + "', '" + favorite_type + "', 1);");
        }
    });

    xajax_addUserFavorite(favorite_id, favorite_type, rating);
    return void(null);
}

/**
 *
 */
function delUserFavorite(favorite_id, favorite_type, rating) {

    theID = "favorite_" + favorite_type + "_" + favorite_id;

    $("a.s").each(function() {
        if($(this).attr("id") == theID) {
            $(this).html("Add To Favorites");
            $(this).attr("href", "javascript:addUserFavorite('" + favorite_id + "', '" + favorite_type + "', 1);");
        }
    });

    xajax_delUserFavorite(favorite_id, favorite_type, rating);
    return void(null);
}

/**
 *
 */
function showEditPhoto(photo_id) {
    if ( photo_id ) {
        document.getElementById(photo_id).style.display='block';
    }
}


/**
 * Document Height
 */
var client = { // Test� FF/IE
        getPage: function() {
            var pageWidth = 720;
            var pageHeight = 576;
            var scrollArr = this.getScroll();
            var winArr = this.getWindow();
            pageWidth = winArr.width + scrollArr.left;
            pageHeight = winArr.height;// + scrollArr.top;
            return {
                scrollX: scrollArr.left,
                scrollY: scrollArr.top,
                winW: winArr.width,
                winH: winArr.height,
                pageW: pageWidth,
                pageY: pageHeight };
        },

        getScroll: function() {
            return {
                left: this.scrollLeft(), top: this.scrollTop()
            };
        },

        getWindow: function() {
            return {
                width: this.windowWidth(), height: this.windowHeight()
            };
        },

        scrollLeft: function() {
            var xScroll = 0;
            if (self.pageXOffset) xScroll = self.pageXOffset;
            else if (document.documentElement && document.documentElement.scrollLeft) xScroll = document.documentElement.scrollLeft;
            else if (document.body) xScroll = document.body.scrollLeft;
            return xScroll;
        },

        scrollTop: function() {
            var yScroll = 0;
            if (self.pageYOffset) yScroll = self.pageYOffset;
            else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
            else if (document.body) yScroll = document.body.scrollTop; return yScroll;
        },

        windowWidth: function() {
            var xWin = 720;
            if (self.innerHeight) xWin = self.innerWidth;
            else if (document.documentElement && document.documentElement.clientWidth) xWin = document.documentElement.clientWidth;
            else if (document.body) xWin = document.body.clientWidth;
            return xWin;
            },

        windowHeight: function() {
            var yWin = 576;
            if (self.innerHeight) yWin = self.innerHeight;
            else if (document.documentElement && document.documentElement.clientHeight) yWin = document.documentElement.clientHeight;
            else if (document.body) yWin = document.body.clientHeight; return yWin; }
};

/**
 *
 */
String.prototype.ucwords = function() {
    return this.toLowerCase().replace(/\w+/g, function(s) {
        return s.charAt(0).toUpperCase() + s.substr(1);
    })
}

/**
 *
 */
function displayModalWindow(form_name) {

    var title, width, height, d = document;

    title = "Politics.com";

    width = client.getPage().pageW;
    height = client.getPage().pageY;

    xajax_displayModalWindow(form_name, height, width, document.body.clientHeight);
    return false;
}

/**
 *
 */
function displayModalDiv(origine,form_name) {
    xajax_displayModalDiv(origine, form_name);
    return false;
}

/**
 *
 */
function highlightComment(id) {

    var origColor = document.getElementById('comment_' + id).style.backgroundColor;

    document.getElementById('comment_' + id).style.backgroundColor = '#ffff99';
    setTimeout("unhighlightComment(" + id + ", '" + origColor + "');", 1500);
    return false;
}

/**
 *
 */
function unhighlightComment(id, origColor) {
    document.getElementById('comment_' + id).style.backgroundColor = origColor;
    return false;
}

/**
 *
 */
function hideModalWindow() {
    xajax_hideModalWindow();
    return false;
}

/**
 *
 */
function parseUrlHash() {

    var urlHash = document.location.hash;

    if(urlHash != '') {

        urlHash = urlHash.substr(1, urlHash.length);
        urlHash = urlHash.split(',');

        for(var key in urlHash) {

            if(urlHash[key].indexOf('tab=') != -1) {
                displayProfileTab(urlHash[key].substr(4, urlHash[key].length));
            }
        }
    }

    return false;
}

/**
 *
 */
function processAbuseForm(id) {

    $('#abuse_submit'+id).attr("disabled", "true");
    $('#abuse_submit'+id).attr("value", 'Reporting...');
 	$('#loader').show();

    xajax_processAbuseForm(xajax.getFormValues('abuse_form'+id),id);
    return false;
}

/**
 *
 */
function processLocaleForm() {

    document.getElementById('locale_submit').disabled = true;
    document.getElementById('locale_submit').value    = 'Processing...';

    xajax_processLocaleForm(xajax.getFormValues('locale_form'));
    return false;
}

/**
 *
 */
function processLoginForm() {

    document.getElementById('login_submit').disabled = true;
    document.getElementById('login_submit').value    = 'Processing...';

    xajax_processLoginForm(xajax.getFormValues('login_form'));
    return false;
}

/**
 *
 */
function processHeaderLoginForm() {

    document.getElementById('login_header_submit').disabled = true;
    document.getElementById('login_header_submit').value    = 'Processing...';

    xajax_processHeaderLoginForm(xajax.getFormValues('login_header_form'));
    return false;
}

/**
 *
 */
function processRegistrationForm() {

    document.getElementById('registration_submit').disabled = true;
    document.getElementById('registration_submit').value    = 'Registering...';

    xajax_processRegistrationForm(xajax.getFormValues('registration_form'));
    return false;
}

function processResendValidationEmail(user_id) {
    xajax_processResendValidationEmail(user_id);
    return false;
}

/**
 *
 */
function processRegistrationSmallForm(step) {

    if((step == 1) || (step == 2)) {
        document.getElementById('registration_small_submit'+step).disabled = true;
    }

    xajax_processRegistrationSmallForm(xajax.getFormValues('registration_small_form'+step), step);
    return false;
}

/**
 *
 */
function processShareItForm(id) {

    $('#shareit_submit'+id).attr("disabled","true");
    $('#shareit_submit'+id).attr("value",'Sharing...');
	$('#loader').show();
	 xajax_processShareItForm(xajax.getFormValues('shareit_form'+id));

	return false;
}

/**
 *
 */
function rateArticle(rating_data) {
    xajax_rateArticle(rating_data);
    return false;
}


/********************************************************************************
 * BEGIN: NEW COMMENTS
 *******************************************************************************/

/**
 *
 */
function showCommentQuote(comment_number, is_post) {

    var status = document.getElementById('parent_comment_' + comment_number).style.display;

    if(!is_post) { is_post = 0; }

    if(status == 'block') {
        xajax_hideCommentQuote(comment_number, is_post);
        return false;
    }
	$('#loader').show();
    xajax_showCommentQuote(comment_number);
    return false;
}

/**
 *
 */
function clearCommentSearchText() {

    if(document.getElementById('commentSearchText').value == 'Search the comments below') {
        document.getElementById('commentSearchText').value = '';
    }
    return false;
}

/**
 *
 */
function resetCommentSearchText() {

    if(document.getElementById('commentSearchText').value == '') {
        document.getElementById('commentSearchText').value = 'Search the comments below';
    }
    return false;
}

/**
 *
 */
function hideAddComment() {
    if(!IE6) $('#commentAdd').slideUp();
	else $('#commentAdd').hide();
    return false;
}

/**
 *
 */
function showAddComment() {
   if(!IE6) {$('.hid').slideUp();	
   			 $('#commentAdd').slideDown(); } 
    else {
			$('.hid').hide();
			$('#commentAdd').show();
	}
    return false;
}

/**
 *
 */
function hideConversation() {
    xajax.call('hideConversation', { mode: 'synchronous', parameters: [ arguments[0], arguments[1] ] });
    return false;
}

/**
 *
 */
function showConversation() {
    $('#loader').show();
	xajax.call('showConversation', { mode: 'synchronous', parameters: [ arguments[0], arguments[1], arguments[2], arguments[3] ] });
	return false;
}

/********************************************************************************
 * END: NEW COMMENTS
 *******************************************************************************/

/**
 *
 */
function updateUserStatusMsg(msg) {

    xajax.call('updateUserStatusMsg', { mode: 'synchronous', parameters: [ arguments[0] ] });
    return false;
}

/**
 *
 */
function addNetworkFriend(userid, username, status) {
    
	var isFoe = $("#isFoe").attr('value');
	
    if( isFoe == '1' )
    {
		if(!confirm(username + ' is currently your Foe. If you add ' + username + ' as a Friend, the user will be removed from your list of Foes.'))
        {
            return false;
        }
    }
    else
    {
        if(!confirm('Are you sure you want to add ' + username + ' to your list of Friends?'))
        {
            return false;
        }
    }
    xajax_addNetworkFriend(userid, username, isFoe);
    return false;
}

/**
 *
 */
function addNetworkFoe(userid, username) {
    var isFriend = document.getElementById("isFriend").value;
    if( isFriend == '1' )
    {
        if(!confirm(username + ' is currently your Friend. If you add ' + username + ' as a Foe, the user will be removed from your list of Friends.'))
        {
            return false;
        }
    }
    else
    {
        if(!confirm('Are you sure you want to add ' + username + ' to your list of Foes?'))
        {
            return false;
        }
    }
    xajax_addNetworkFoe(userid, username, isFriend);
    return false;
}

/**
 *
 */
function delNetworkFoe(userid, username) {
    /*if(!confirm('Are you sure you want to delete ' + username + ' from your Foes list?'))*/
    if(!confirm('Are you sure you want to remove this foe?'))
    {
        return false; 
    }
    xajax_delNetworkFoe(userid, username);
    return false;
}
