
/********************************************* FOR BANNER - SELL **********************************************/

///<summary>
/// THIS SCRIPT GENERATE BANNER ROTATION FOR BANNER SELL TYPE
///</summary>
///<CreatedBy>Rajesh Khunt</CreatedBy>
///<CreatedDate>11-05-2009</CreatedDate>

// BANNER OBJECT
function Banner(objName)
{
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner = 0;
	
};


// ADD NEW BANNER
Banner.prototype.add = function(bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt) 
{
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt);
};


// Node object
function Node(name, bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt) 
{
	this.name = name;
	this.bannerType = bannerType;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	this.height = height
	this.width = width;
	this.hyperlink = hyperlink;
	this.alt = alt;
};


// Outputs the banner to the page
Banner.prototype.toString = function() 
{
	var str = ""
	
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++)
	{
		str = str + '<span name="'+this.aNodes[iCtr].name+'" '
		str = str + 'id="'+this.aNodes[iCtr].name+'" ';
		str = str + 'class="m_banner_hide" ';
		str = str + 'bgcolor="#FFFCDA" ';	// CHANGE BANNER COLOR HERE
		str = str + 'align="center" ';
		str = str + 'valign="top" >\n';

		if (this.aNodes[iCtr].hyperlink != "")
		{
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'" target=_blank>';
		}
			
        if ( this.aNodes[iCtr].bannerType == "IMAGE" )
		{
			str = str + '<img src="'+this.aNodes[iCtr].bannerPath+'" ';
			str = str + 'border="0" ';
			//str = str + 'height="'+this.aNodes[iCtr].height+'" ';
			str = str + 'width="'+this.aNodes[iCtr].width+'"';
			str = str + 'alt="'+this.aNodes[iCtr].alt+'">';
		}

		if (this.aNodes[iCtr].hyperlink != "")
		{
			str = str + '</a>';
		}

		str += '</span>';
	}
	return str;
};


// START THE BANNER ROTATION
Banner.prototype.start = function()
{
    this.changeBanner();
    var thisBannerObj = this.obj;

	// CURRENT BANNER IS ALREADY INCREMENTED IN changeBanner() FUNCTION
	if(this.aNodes[this.currentBanner] != window.undefined)
	{
	    setTimeout(thisBannerObj+".start()", this.aNodes[this.currentBanner].bannerDuration * 1000);
	}

	if (this.currentBanner < this.aNodes.length - 1)
	{
		this.currentBanner = this.currentBanner + 1;
	}
	else
	{
		this.currentBanner = 0;
	}
	
	// SET COOKIES, IT WILL STORE NEXT BANNER INDEX ID
	setCookie('c_BannerLength', this.currentBanner);
}


// CHANGE BANNER
Banner.prototype.changeBanner = function()
{
	var thisBanner;
	var prevBanner = -1;
	
    // RETRIEVE NEXT BANNER INDEX ID FROM COOKIE
	var BannerLength = getCookie('c_BannerLength');
	
    if (BannerLength != null && BannerLength != "")
    {
        this.currentBanner = parseInt(BannerLength);
        prevBanner = parseInt(BannerLength) - 1;
    }
	
	if (this.currentBanner < this.aNodes.length )
	{
		thisBanner = this.currentBanner;
		
		if (this.aNodes.length > 1)
		{
			if ( thisBanner > 0 )
			{
				prevBanner = thisBanner - 1;
			}
			else
			{
				prevBanner = this.aNodes.length-1;
			}
		}
	}

	if (prevBanner >= 0)
	{
        for(var x=0; x<= this.aNodes.length; x++)
        {
            if(x != thisBanner)
            {
                if(this.aNodes[x] != null && this.aNodes.length != 1)
                {
                    document.getElementById(this.aNodes[x].name).className = "m_banner_hide";            
                }
            }
        }
	}

	if(thisBanner != null || (thisBanner == window.undefined && this.aNodes.length == 1) )
	{
	    if(thisBanner == window.undefined)
	    {
	        thisBanner = 0;
	    }
	
        document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
    }
}

/***************************************************************************************************************/








/********************************************* FOR BANNER - BARTER **********************************************/

///<summary>
/// THIS SCRIPT GENERATE BANNER ROTATION FOR BANNER BARTER TYPE
///</summary>
///<CreatedBy>Rajesh Khunt</CreatedBy>
///<CreatedDate>11-05-2009</CreatedDate>

// BANNER OBJECT
function BannerBarter(objName)
{
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner = 0;
	
};


// ADD NEW BANNER
BannerBarter.prototype.add = function(bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt) 
{
	this.aNodes[this.aNodes.length] = new BarterNode(this.obj +"_"+ this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt);
};


// Node object
function BarterNode(name, bannerType, bannerPath, bannerDuration, height, width, hyperlink, alt) 
{
	this.name = name;
	this.bannerType = bannerType;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	this.height = height
	this.width = width;
	this.hyperlink = hyperlink;
	this.alt = alt;
};


// Outputs the banner to the page
BannerBarter.prototype.toString = function() 
{
	var str = ""
	
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++)
	{
		str = str + '<span name="'+this.aNodes[iCtr].name+'" '
		str = str + 'id="'+this.aNodes[iCtr].name+'" ';
		str = str + 'class="m_banner_hide" ';
		str = str + 'bgcolor="#FFFCDA" ';	// CHANGE BANNER COLOR HERE
		str = str + 'align="center" ';
		str = str + 'valign="top" >\n';

		if (this.aNodes[iCtr].hyperlink != "")
		{
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'" target=_blank>';
		}
			
        if ( this.aNodes[iCtr].bannerType == "IMAGE" )
		{
			str = str + '<img src="'+this.aNodes[iCtr].bannerPath+'" ';
			str = str + 'border="0" ';
			//str = str + 'height="'+this.aNodes[iCtr].height+'" ';
			str = str + 'width="'+this.aNodes[iCtr].width+'"';
			str = str + 'alt="'+this.aNodes[iCtr].alt+'">';
		}

		if (this.aNodes[iCtr].hyperlink != "")
		{
			str = str + '</a>';
		}

		str += '</span>';
	}
	return str;
};


// START THE BANNER ROTATION
BannerBarter.prototype.startBarter = function()
{
    this.changeBanner();
    var thisBannerObj = this.obj;

	// CURRENT BANNER IS ALREADY INCREMENTED IN cahngeBanner() FUNCTION
	if(this.aNodes[this.currentBanner] != window.undefined)
	{
	    setTimeout(thisBannerObj+".startBarter()", this.aNodes[this.currentBanner].bannerDuration * 1000);
	}

	if (this.currentBanner < this.aNodes.length - 1)
	{
		this.currentBanner = this.currentBanner + 1;
	}
	else
	{
		this.currentBanner = 0;
	}
	
    // SET COOKIES, IT WILL STORE NEXT BANNER INDEX ID
	setCookie('c_BannerLengthBarter', this.currentBanner);
}


// CHANGE BANNER
BannerBarter.prototype.changeBanner = function()
{
	var thisBanner;
	var prevBanner = -1;
	
	// RETRIEVE NEXT BANNER INDEX ID FROM COOKIE
	var BannerLength = getCookie('c_BannerLengthBarter');
	
    if (BannerLength != null && BannerLength != "")
    {
        this.currentBanner = parseInt(BannerLength);
        prevBanner = parseInt(BannerLength) - 1;
    }
	
	if (this.currentBanner < this.aNodes.length )
	{
		thisBanner = this.currentBanner;
		
		if (this.aNodes.length > 1)
		{
			if ( thisBanner > 0 )
			{
				prevBanner = thisBanner - 1;
			}
			else
			{
				prevBanner = this.aNodes.length-1;
			}
		}
	}
	
	if (prevBanner >= 0)
	{
	    if(this.aNodes.length > 1)
	    {
		    for(var x=0; x<= this.aNodes.length; x++)
	        {
	            if(x != thisBanner)
	            {
	                if(this.aNodes[x] != null)
	                {
	                    document.getElementById(this.aNodes[x].name).className = "m_banner_hide";            
	                }
	            }
	        }
        }
	}
	
	if(thisBanner != null || (thisBanner == window.undefined && this.aNodes.length == 1) )
	{
	    if(thisBanner == window.undefined)
	    {
	        thisBanner = 0;
	    }
	
        document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
    }
}

/***************************************************************************************************************/









/**************************************** SET COOKIES AND GET COOKIES ******************************************/

///<summary>
/// THIS SCRIPT ALLOWS TO SET COOKIES FOR BANNER NODE'S NEXT NUMBER
///</summary>
///<CreatedBy>Rajesh Khunt</CreatedBy>
///<CreatedDate>11-05-2009</CreatedDate>

// SET COOKIES
function setCookie(c_name, value)
{
    var exdate = new Date();        
    exdate.setDate(exdate.getDate() + 1);
    document.cookie = c_name + "=" + escape(value)+((1==null) ? "" : "; expires="+exdate.toGMTString());
}

// GET COOKIES
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 ;
            c_end=document.cookie.indexOf(";",c_start);
            
            if (c_end==-1) 
                c_end=document.cookie.length
            
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    else
    {
        return ""
    }
}

/***************************************************************************************************************/