// Multiple Inits

addOnload(rolloverInit);
addOnload(initNav);
addOnload(attach_file);
addOnload(initForms);
addOnload(initNotice);

function addOnload(newFunction){
    var oldOnload = window.onload;

    if(typeof oldOnload == "function"){
        window.onload = function(){
            if(oldOnload){
                oldOnload();
            }
            newFunction();
        }
    }else{
        window.onload = newFunction;
    }

}


////////////////////////////
/// TOPNAV DROPDOWN MENUS///
////////////////////////////

function initNav(){
    var allLinks = document.getElementsByTagName("A");
	
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	

	if (typeof document.body.style.maxHeight == "undefined")
	{
		
			if(document.getElementById('col_title_right_index')){
					var title1 = document.getElementById('col_title_right_index');
					title1.style.position='absolute';
					title1.style.top='385px';
					title1.style.left='480px';
				}
				
				if(document.getElementById('col_title_left_index')){
					var title2 = document.getElementById('col_title_left_index');
					title2.style.position='absolute';
					title2.style.top='385px';
					title2.style.left='0px';
				}
				
				
				if(document.getElementById('col_title_right_main')){
					var title1 = document.getElementById('col_title_right_main');
					title1.style.position='absolute';
					title1.style.top='385px';
					title1.style.left='485px';
				}
				
				if(document.getElementById('col_title_left_main')){
					var title2 = document.getElementById('col_title_left_main');
					title2.style.position='absolute';
					title2.style.top='385px';
					title2.style.left='0px';
				}
		


	}
	var browser=navigator.appName;
	
	if(browser == "Microsoft Internet Explorer"){
		document.getElementById('menu2').style.marginTop = "-2px";
		document.getElementById('menu5').style.marginTop = "-2px";
	}
	
    for(var i=0; i<allLinks.length; i++){
			if((allLinks[i].id == "navLink1")
			||(allLinks[i].id == "navLink4")){
            	allLinks[i].onclick = retFalse;
				allLinks[i].onmouseover = toggleMenu;
			}
    }
}

function toggleMenu(){
    var startMenu = this.href.lastIndexOf("/")+1;
    var stopMenu = this.href.lastIndexOf(".");
    var thisMenuName = this.href.substring(startMenu,stopMenu);

    document.getElementById(thisMenuName).style.display = "block";

	this.parentNode.className = thisMenuName;
	this.parentNode.onmouseout = toggleDivOff;
	this.parentNode.onmouseover = toggleDivOn;
}

function toggleDivOn(){
	document.getElementById(this.className).style.display = "block";	
}

function toggleDivOff(){
	document.getElementById(this.className).style.display = "none";	
}

function retFalse(){
	return false;	
}


/************************************/

// Rollover Function
/*
function rolloverInit() {

    for(var i=0; i<document.images.length; i++) {
        if(document.images[i].parentNode.className == "menuLink") {
            setupRollover(document.images[i]);
        }
		if(document.images[i].parentNode.className == "menuLink_optionless") {
            setupRollover(document.images[i]);
        }
    }
}
*/
function rolloverInit() {

    for(var i=0; i<document.images.length; i++) {
        if(document.images[i].parentNode.tagName == "A") {
			if((document.images[i].parentNode.id == "navLink")
			||(document.images[i].parentNode.id == "navLink1")
			||(document.images[i].parentNode.id == "navLink2")
			||(document.images[i].parentNode.id == "navLink3")
			||(document.images[i].parentNode.id == "navLink4")
			||(document.images[i].parentNode.id == "navLink5")
			||(document.images[i].parentNode.id == "navLink6")
			||(document.images[i].parentNode.id == "navLink7")){
            	setupRollover(document.images[i]);
			}
        }
    }
}

function setupRollover(thisImage) {
	
    thisImage.outImage = new Image();
    thisImage.outImage.src = thisImage.src;
    thisImage.onmouseout = rollOut;

    thisImage.overImage = new Image();
    thisImage.overImage.src = "./images/layout/btns_over/" + thisImage.id + ".gif";
    thisImage.onmouseover = rollOver;
	
	thisImage.downImage = new Image();
    thisImage.downImage.src = "./images/layout/btns_down/" + thisImage.id + ".gif";
    thisImage.onmousedown = rollDown;
}    

function rollOut() {
    this.src = this.outImage.src;
}

function rollOver() {
    this.src = this.overImage.src;
}

function rollDown() {
    this.src = this.downImage.src;
}


/************************************/






/************************************/

// Attach script functions


function attach_file(url) {
	// create new script element, set its relative URL, and load it
	
	
	script = document.createElement( 'script' );
	if(!url || url == ''){
		script.src = 'scripts/updateitem.php';
	}else{
		script.src = url;
	}

	document.getElementsByTagName( 'head' )[0].appendChild( script );
}





function delitem(itemid){
	
		if(confirm('Are you sure you wish to delete this menu item?')){

			url = '';
		
			url = "scripts/updateitem.php?action=del&item_id=" + itemid + "";
	
			attach_file(url);
			
		}else{
			return false;	
		}

	
}

function beginEdit (fieldname, id)
{
	field = document.getElementById(fieldname + id);
	
	field.style.backgroundColor = '#FFFFFF';
	field.style.border = 'inset blue 1px';	
}

function endEdit (fieldname, id, color, itemid)
{
	field = document.getElementById(fieldname + id);
	
	
	field.style.backgroundColor = '#EFEFEF';
	field.style.border = 'solid #EFEFEF 1px';
	

		url = "scripts/updateitem.php?field=" + fieldname + "&field_value=" + field.value + "&item_id=" + itemid + "";
		
		attach_file(url);
}

function addmenuitem(id){	
	
			if(document.getElementById("notice2")){

					document.onload = closeNotice;
					// close the div in 5 secs
					window.setTimeout('closeNotice2()', 1000);
			}
	
			url = '';
		
			url = "scripts/updateitem.php?addmenuitem=" + id + "";
			
			attach_file(url);

}

function remove_item(id){
			
			url = '';
		
			url = "scripts/updateitem.php?arr_remove=" + id + "";
	
			attach_file(url);
}


function beginQty (id)
{
	field = document.getElementById('qty' + id);
	field.value="";
	
	field.style.backgroundColor = '#FFFFFF';
	field.style.border = 'inset blue 1px';	
}

function endQty (id, color, itemid)
{
	field = document.getElementById('qty' + id);
	
	
	field.style.backgroundColor = '#EFEFEF';
	field.style.border = 'solid #EFEFEF 1px';
	
	
	url = "scripts/updateitem.php?qty=" + field.value + "&item_id=" + id + "";
		
	attach_file(url);
	

}

function paymenttype(type){
	
	var payment1 = document.getElementById('payment1');	
	var payment2 = document.getElementById('payment2');	
	
		if(type == 1){
			payment1.disabled = false;
			payment2.style.border="none";
			payment2.disabled = true;
			payment1.style.border="1px solid #666666";
			payment1.focus();
		}
		if(type == 2){
			payment1.disabled = true;
			payment1.style.border="none";
			payment2.disabled = false;
			payment2.style.border="1px solid #666666";
			payment2.focus();
		}
		if(type == 3){
			payment1.disabled = true;
			payment2.disabled = true;
			payment1.style.border="none";
			payment2.style.border="none";
		}
			
}

/************************************/

function initForms() {
    for (var i=0; i< document.forms.length; i++) {
        document.forms[i].onsubmit = function() {
            return validForm();		
        }
    }

}

function validForm() {
    var allGood = true;
    var allTags = document.getElementsByTagName("*");

    for (var i=0; i<allTags.length; i++) {
        if(!validTag(allTags[i])) {
            allGood = false;
        }
    }
    return allGood;
	

    function validTag(thisTag) {
        var outClass = "";
        var allClasses = thisTag.className.split(" ");
        
        for (var j=0; j< allClasses.length; j++) {
           outClass += validBasedOnClass(allClasses[j]) + " ";   
        }

        thisTag.className = outClass;

        if(outClass.indexOf("invalid") > -1) {
			invalidLabel(thisTag.parentNode);
            thisTag.focus();
            if(thisTag.nodeName == "INPUT") {
                thisTag.select();
            }
            return false;
        }
        return true;
        
        function validBasedOnClass(thisClass) {
            var classBack = "";

            switch(thisClass) {
                case "":
                case "invalid":
                     break;
                case "reqd":
                    if(allGood && thisTag.value == ""){
                        classBack = "invalid ";
                    }
                    classBack += thisClass;
                    break;
			
                case "radio":
                    if(allGood && !radioPicked(thisTag.name)){
                        classBack = "invalid ";
                    }    
                    classBack += thisClass;
                    break;
				
                case "email":
                    if(allGood && !validEmail(thisTag.value)){
                        classBack = "invalid ";
                    }
                    classBack += thisClass;
                    break;
					
			    case "phone":
                    if(allGood && !validPhone(thisTag.value)){
                        classBack = "invalid ";
                    }
                    classBack += thisClass;
                    break;
	
                default:
                   /* if(allGood && !crossCheck(thisTag,thisClass)){
						classBack = "invalid ";
					}*/
                    classBack += thisClass;
			}
            return classBack;
      }

		

           
               function validEmail(email){
                   var invalidChars = " /:,;";

                   if(email == ""){
                       return false;
                   }
                   for(var k=0; k<invalidChars.length; k++){
                       var badChar = invalidChars.charAt(k);
                       if(email.indexOf(badChar) > -1){
                           return false;
                       }
                   }
                   var atPos = email.indexOf("@",1);
                   if(atPos == -1){
                       return false;
                   }
                   if(email.indexOf("@", atPos+1) != -1){
                       return false;
                   }
                   var periodPos = email.indexOf(".",atPos);
                   if(periodPos == -1){
                       return false;
                   }
                   if(periodPos+3 > email.length){
                       return false;
                   }
                   return true;
               }
			   
			 
			    function validPhone(phone){

                  
                   if(phone.length < 10){
                       return false;
                   }
				   
                   return true;
               }
            
               /*
               function crossCheck(inTag,otherFieldID){     
                   if(!document.getElementById(otherFieldID)){
                       return false;
                   }
                   return(inTag.value == document.getElementById(otherFieldID).value);
               }
			   */

               function radioPicked(radioName){
                   var radioSet = "";
            
                   for(var k=0; k<document.forms.length; k++){
                       if(!radioSet){
                           radioSet = document.forms[k][radioName];
                       }
                   }
                   if(!radioSet){
                       return false;
                   }      
               
       
               for(k=0; k<radioSet.length; k++){
                   if(radioSet[k].checked){
                       return true;
                   }
               }
               return false;
            }


        function invalidLabel(parentTag){
            if(parentTag.nodeName == "LABEL"){
                parentTag.className += " invalid";
            }
        }
	}
}

/************************/

function initNotice(){
	
	if(document.getElementById("notice")){
		document.onload = closeNotice;
		// close the div in 5 secs
		window.setTimeout('closeNotice()', 1000);
	
	}
}

function closeNotice(){

			var notice = document.getElementById("notice");
			opacity("notice", 0, 100, 2000)
			
}	

function closeNotice2(){
			
			var notice = document.getElementById("notice2");
			notice.style.display = 'block';
			opacity("notice2", 100, 0, 3000)
						
}	

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		
		
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
	
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	
} 
/***********************************************
* Ultimate Fade-In Slideshow (v1.51): � Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

// Slideshow
var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]=["./images/bannerquotes/quote1.gif", "", ""] //plain image syntax
fadeimages[1]=["./images/bannerquotes/quote2.gif", "", ""] //image with link syntax
fadeimages[2]=["./images/bannerquotes/quote3.gif", "", ""] //image with link and target syntax
fadeimages[3]=["./images/bannerquotes/quote4.gif", "", ""]
 
/*
var fadeimages2=new Array() //2nd array set example. Remove or add more sets as needed.
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages2[0]=["photo1.jpg", "", ""] //plain image syntax
fadeimages2[1]=["photo2.jpg", "http://www.cssdrive.com", ""] //image with link syntax
fadeimages2[2]=["photo3.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax
 */
 
var fadebgcolor="#524843"

// No need to edit below

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
 
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
	this.pausecheck=pause
	this.mouseovercheck=0
	this.delay=delay
	this.degree=10 //initial opacity degree (10%)
	this.curimageindex=0
	this.nextimageindex=1
	fadearray[fadearray.length]=this
	this.slideshowid=fadearray.length-1
	this.canvasbase="canvas"+this.slideshowid
	this.curcanvas=this.canvasbase+"_0"
	if (typeof displayorder!="undefined")
	theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
	this.theimages=theimages
	this.imageborder=parseInt(borderwidth)
	this.postimages=new Array() //preload images
	for (p=0;p<theimages.length;p++){
	this.postimages[p]=new Image()
	this.postimages[p].src=theimages[p][0]
}
 
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
	if (obj.degree<100){
	obj.degree+=10
		if (obj.tempobj.filters&&obj.tempobj.filters[0]){
		if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
			obj.tempobj.filters[0].opacity=obj.degree
		else //else if IE5.5-
			obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
		}
	else if (obj.tempobj.style.MozOpacity)
		obj.tempobj.style.MozOpacity=obj.degree/101
	else if (obj.tempobj.style.KhtmlOpacity)
		obj.tempobj.style.KhtmlOpacity=obj.degree/100
	else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
		obj.tempobj.style.opacity=obj.degree/101
	}
	else{
		clearInterval(fadeclear[obj.slideshowid])
		obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
		obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
		obj.populateslide(obj.tempobj, obj.nextimageindex)
		obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
		setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
	}
}
 
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
 
 
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
 
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
 
 
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}





/***********************************************
* Fixed ToolTip script- � Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='200px' //default tooltip width
var tipbgcolor=''  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="-53px" //horizontal offset of tooltip from anchor link
var horizontal_offset="70px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.height='30px';

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}



/*
// JavaScript Document
function popwindow (doc)
{

opener = window.open(doc,"Window1",
"menubar=yes,width=600,height=600,toolbar=yes,scrollbars=1");

opener.focus()
	
}
*/