// ===================================================================
// Author: DNS, March 2010
// WWW: http://www.theshoppie.com/
//
// Javascript used for ajax style functions

function dnsastnc1(uri,divzone) {

YUI().use('io-base','node', function(Y) {

    function dnsupdate(id, o, args) {
	var id = id; // Transaction ID //
	var results = o.responseText;
	dnsdraw(results);
    };

    function dnsfailed(id, o, args) {
	var id = id; // Transaction ID //
	var results = o.responseText;
	dnsdraw('FAILED: ' + results);
    };


    function dnsdraw(results) {
	var node = Y.one('#' + divzone);
	node.set('innerHTML',results) ;
    };


    uri = uri + "&stamp=" + Math.random() ;

    Y.on('io:complete', dnsupdate, this);
    Y.on('io:failure', dnsfailed, this);

    var request = Y.io(uri);

    
});

}


//This is the call for the Voting function
//votevalue: 0=down, 1=up
function dnsastnc2(postid,votevalue) {

YUI().use('io-base','node', function(Y) {

    function dnsupdate(id, o, args) {
	var id = id; // Transaction ID //
	var returns = o.responseText.split(",",3);

	//update the voting numbers
	var nodeup = Y.one('#' + postid + 'u');
	var nodedown = Y.one('#' + postid + 'd');
	var nodetext = Y.one('#' + postid);
	
	nodeup.set('value', parseInt(nodeup.get('value')) + parseInt(returns[0]));
	nodedown.set('value', parseInt(nodedown.get('value')) + parseInt(returns[1]));
	dnsdraw(returns[2]);
    };

    function dnsfailed(id, o, args) {
	var id = id; // Transaction ID //
	var results = o.responseText;
	dnsdraw('Sorry something went wrong, please try later. (' + results + ')');
    };

    function dnsdraw(results) {
	var node = Y.one('#' + postid);
	node.set('innerHTML',results) ;
    };

    var uri = "/arbroath/forum/post_inline.asp?method=vote&VOTE=" + votevalue + "&SET=" + postid + "&stamp=" + Math.random() ;

    Y.on('io:success', dnsupdate, this);
    Y.on('io:failure', dnsfailed, this);

    var request = Y.io(uri);

    
});

}



function openWindow(url) {
	popupWin = window.open(url,'new_page','width=400,height=400')
}
function openWindow2(url) {
	popupWin = window.open(url,'new_page','width=400,height=450')
}
function openWindow3(url) {
	popupWin = window.open(url,'new_page','width=400,height=450,scrollbars=yes')
}
function openWindow4(url) {
	popupWin = window.open(url,'new_page','width=400,height=525')
}
function openWindow5(url) {
	popupWin = window.open(url,'new_page','width=450,height=525,scrollbars=yes,toolbars=yes,menubar=yes,resizable=yes')
}
function openWindow6(url) {
	popupWin = window.open(url,'new_page','width=500,height=450,scrollbars=yes')
}
function openWindowHelp(url)	{
	popupWin = window.open(url,'new_page','width=470,height=200,scrollbars=yes')
}
// ################## Poll Mod ##################
function openPollWindow(url,w,h) {
	popupWin = window.open(url,'new_page','width='+w+',height='+h+',scrollbars=yes')
}
function submitPoll(btnPressed) {
	btnPressed.disabled=true;
	if (btnPressed.name	== "results")	{
		document.Poll.Method_Type.value = "guest_vote";
	} else {
		document.Poll.Method_Type.value = "member_vote";
	}
	document.Poll.submit();
}
