//\//////////////////////////////////////////////////////////////////////////////////
//\  Pausing up-down scroller
//\//////////////////////////////////////////////////////////////////////////////////
//

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%; text-align: right" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden; text-align: right" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


//\//////////////////////////////////////////////////////////////////////////////////
//\  Hidden Expandable Content (FAQ, etc)
//\//////////////////////////////////////////////////////////////////////////////////
//

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='<img src="images/collapsebtn.gif" width="11" height="11" border="0" class="bottom"> ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='<img src="images/expandbtn.gif" width="11" height="11" border="0" class="bottom"> ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
for (i=0; i<rootobj.length; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){

var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}

if (enablepersist=="on" && document.getElementById)
{
	saveswitchstate()
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 

var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){

var final_url=""
var url1 = window.location.href.split("?");
var url2 = url1[1].split("&");


for (i=1; i<url2.length-1; i++)
{
	var url3 = url2[i].split("=");
	if(url3[0] == "cid")
	{
		final_url+=url3[0]+url3[1];
	}
}

if (get_cookie(url1[0]+"?"+final_url) != ""){
selectedItem=get_cookie(url1[0]+"?"+final_url)
return selectedItem
}
else
return ""
}

function saveswitchstate(){

var today = new Date();
var expire = new Date();
var nDays = 7;
expire.setTime(today.getTime() + 3600000*24*nDays);

var inc=0, selectedItem="", final_url=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

var url1 = window.location.href.split("?");
var url2 = url1[1].split("&");


for (i=1; i<url2.length-1; i++)
{
	var url3 = url2[i].split("=");
	if(url3[0] == "cid")
	{
		final_url+=url3[0]+url3[1];
	}
}


//document.cookie=window.location.pathname+"="+selectedItem
document.cookie=url1[0]+"?"+final_url+"="+selectedItem+";expires="+expire.toGMTString();
//alert('Cookie should be set' + selectedItem);
}

function do_onload(){
//uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
//if (enablepersist=="on" && ccollect.length>0){
//document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
//firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
//if (!firsttimeload)
//revivecontent()
//}

if (ccollect.length>0 && statecollect.length>0)
revivecontent()
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload


//\//////////////////////////////////////////////////////////////////////////////////
//\  Form Action Confirm -- 
//\//////////////////////////////////////////////////////////////////////////////////
//

function formConfirm(question,url)
{
	var prompt = confirm(question)
	if (!prompt)
	{ 
		return false;
	}
 	else 
	{
		if (url != "")
		{
			top.window.location=url;
		}
	}
	return prompt;
}
//<a href="#nothing" onclick="formConfirm('Are you sure you want to go to Google?','http://www.google.com');">Look</a>

//\//////////////////////////////////////////////////////////////////////////////////
//\  Clear Text Field Once Only --  
//\//////////////////////////////////////////////////////////////////////////////////
//

var isclicked = false;

function clearinput(callingElement)
{
	if (!isclicked)
	{
		callingElement.value = '';
		isclicked = true;
	}
}

//\//////////////////////////////////////////////////////////////////////////////////
//\  Window Opener  --  
//\//////////////////////////////////////////////////////////////////////////////////
//

function openWindow(theURL, wname, W, H, X, Y) {

	var isie = false
	var iswin= false

	if ( navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4 ) {
		isie=true
	}

	if ( navigator.userAgent.toLowerCase().indexOf("win")!=-1 ) iswin=true

	if (X==null) var X = Math.ceil( (window.screen.width  - W) / 2 );
	if (Y==null) var Y = Math.ceil( (window.screen.height - H) / 2 );

	//if (isie) { H=H+20+3; W=W+2; }
	var s = ",width="+ W +",height="+ H ;

	if (isie && iswin) {
		
		var CWIN = window.open(theURL, wname, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
		CWIN.moveTo  ( Math.ceil( X ) , Math.ceil( Y ) );

	}
	//This else is for browsers other than msie
	else    {
		var CWIN = window.open(theURL, wname, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
		CWIN.moveTo  ( Math.ceil( X ) , Math.ceil( Y ) );
	}

	CWIN.focus();

	return CWIN
}                                                                               
                                                                                
function openIT(theURL,W,H,X,Y, wname) {
	return openWindow(theURL, wname, W, H, X, Y)
}


//\//////////////////////////////////////////////////////////////////////////////////
//\  Window Cookie Once Opener--  
//\//////////////////////////////////////////////////////////////////////////////////
//

var expHours = 6; // number of hours the cookie should last

//var page = "only-popup-once.html";
//var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date(); 
exp.setTime(exp.getTime() + (expHours*60*60*1000));
//Changed to hours rather than days expiration
//exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
   }
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

myadminwin01=openIT('http://www.myadhan.com/rewardpointspopup.html', 200, 200, 100, 100, 'myadhanwine01');

}
//else {
//count++;
//SetCookie('count', count, exp);
//}
}

//\//////////////////////////////////////////////////////////////////////////////////
//\  Submit once script  --  
//\//////////////////////////////////////////////////////////////////////////////////
//
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}