var popupwin_360;
var popupwin_OTR;
var base_url = "http://dev.mtv2ontherise.com/";
//-----------------------------
// Public Functions
//	PopupOTR( "coxct" )
//  	PopupOTR_Navigate360( "coxct" )
//	PopupOTR_Popup360( "coxct")
//	Popup_Login( "coxct" )
//-----------------------------
function ExtractAffiliate_PopupOTR()
{	
	var args = getArgs();
	PopupOTR( args.affiliate );
}


function PopupOTR( affiliate_id )
{
	PopupOTR_QueryString( "affiliate=" + affiliate_id );	
}

function PopupOTR_Login( affiliate_id )
{
	PopupOTR_QueryString( "affiliate=" + affiliate_id + "&page=login" );
}

function PopupOTR_Navigate360( affiliate_id )
{
	PopupOTR( affiliate_id);
	Navigate360( affiliate_id );
}


function PopupOTR_Popup360( affiliate_id )
{
	Popup360( affiliate_id );
	PopupOTR( affiliate_id );
}

//-----------------------------------------
// Helper Functions
//-----------------------------------------
var popupwin_zip;
function PopupZip()
{
	popupwin_zip = PopupHelper( base_url + "ChangeZip.html", 298, 200, "popupwin_zip", "top", "right");
}

function Navigate360( affiliate_id )
{
	var url = base_url + "redirect/affiliateproxy.php?affiliate=" + affiliate_id;	
	Redirect( url );
}

function Popup360( affiliate_id )
{
	var _url = base_url + "redirect/affiliateproxy.php?affiliate=" + affiliate_id;
	return popupwin_360 = window.open( _url, "popupwin_360" );
}

function PopupOTR_QueryString( qs )
{
	var url = base_url + "popup.html?" + qs;
	popupwin_OTR = PopupHelper( url, 750, 565, "popupwin_otr", "center", "center" )
}

//
// PopupHelper()
//	Adjusts height based on browser type and opens popup
//
function PopupHelper( _url, _width, _height, _name, _vAlign, _hAlign )
{
	var _params = "toolbar=0, scrollbars=0, location=0, menubar=0, status=1, resizable=0";


	//What alignment does this represent?
	switch ( _vAlign )
	{
		case "top":
			_top = parseInt(( 0 - _height ));
			break;
			
		case "bottom":
			_top = parseInt(( window.screen.height - _height ));
			break;
			
		case "center":
		default:
			_top = parseInt(( window.screen.height - _height ) / 2);
	}
	
	switch (_hAlign )
	{
		case "left":
			_left = 0;
			break;
			
		case "right":
			_left = parseInt(( window.screen.width - _width ));
			break;
			
		case "center":
		default:
			_left = parseInt(( window.screen.width - _width ) / 2);
	}
	
	var _browser = window.navigator.appName;
	switch (_browser)
	{
		case "Microsoft Internet Explorer":
			break;

		case "Netscape":
			_top += 2;
			break;

	}
	_params += ", width=" + _width +", height=" + _height + ", left=" + _left + ", top=0" + _top;
	return window.open( _url, _name, _params );
}

function Redirect( _url )
{
	window.location.href = _url;
}

function getArgs()
{
         var args = new Object();
         var query = unescape(location.search.substring(1));
         var pairs = query.split("&");
         for (var i = 0; i < pairs.length; i++) {
             var pos = pairs[i].indexOf("=");
             if (pos == -1) {
                 continue;
             }
             var argname = pairs[i].substring(0, pos);
             var value = pairs[i].substring(pos + 1);
             args[argname] = unescape(value);
         }
         return args;
}
 

