





function checkDivHeight(){
	var testScroll = $("#Content").attr("scrollHeight") - $("#Content").height();

		if(testScroll>0){
			$('#slider').show();
		}else{
			$('#slider').hide();
		}
		
}

var req;

function navigate(month,year,evt) {
	setFade(0);
	var url = "/includes/blocs.calendar.php?month="+month+"&year="+year+"&event="+evt;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}

function callback() {	
	if(req.readyState == 4) {
		var response = req.responseXML;	
		var resp = response.getElementsByTagName("response");
		getObject("calendar").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		
		fade(100);
	}
}

function getObject(obj) {
	var o;
	if(document.getElementById) o = document.getElementById(obj);
	else if(document.all) o = document.all.obj;	
	return o;	
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		//amt += 10;
		//setTimeout("fade("+amt+")", 5);
    }
}

function setFade(amt) {
	var obj = getObject("calendar");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
}

function showJump(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var jump = document.createElement("div");
	jump.setAttribute("id","jump");
	jump.style.position = "absolute";
	jump.style.top = curtop+15+"px";
	jump.style.left = curleft+"px";
	var output = '<select id="month">\n';
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var n;
	for(var i=0;i<12;i++) {
		n = ((i+1)<10)? '0'+(i+1):i+1;
		output += '<option value="'+n+'">'+months[i]+'  </option>\n';
	}
	output += '</select> \n<select id="year">\n';
	for(var i=0;i<=15;i++) {
		n = (i<10)? '0'+i:i;
		output += '<option value="20'+n+'">20'+n+'  </option>\n';
	}
	output += '</select> <a href="javascript:jumpTo()"><img src="/images/system/calGo.gif" alt="go" /></a> <a href="javascript:hideJump()"><img src="/images/system/calStop.gif" alt="close" /></a>';
	jump.innerHTML = output;
	document.body.appendChild(jump);
}

function hideJump() {
	document.body.removeChild(getObject("jump"));	
}

function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
}


function ShowOptionPanel_Site(Count,OptionID,uniqueID){
	
	for(i=1;i<=Count;i++){
		document.getElementById('PanelButton'+i+':'+uniqueID).className='PanelButton';
		document.getElementById('PanelOption'+i+':'+uniqueID).className='PanelOption';
	}

	document.getElementById('PanelButton'+OptionID+':'+uniqueID).className='PanelButtonOn';
	document.getElementById('PanelOption'+OptionID+':'+uniqueID).className='PanelOptionOn';
}


function ShowStoryPanel_Site(Count,OptionID,uniqueID){
	myHTML='Pages:  ';
	for(i=1;i<=Count;i++){
		document.getElementById('PanelStory'+i+':'+uniqueID).className='PanelStory';
	}
	document.getElementById('PanelStory'+OptionID+':'+uniqueID).className='PanelStoryOn';
	if(OptionID>1){
		myHTML += "<button class=MenuButton  onclick=\"StoryPanel_Control("+Count+",'Back','"+uniqueID+"');\">&nbsp;<&nbsp;</button>";
	}
	for(i=1;i<=Count;i++){
		myHTML += "<button   onclick=\"ShowStoryPanel_Site("+Count+","+i+",'"+uniqueID+"');\"  ";
		myHTML += (i==OptionID)?' class=MenuButtonActive ': ' class=MenuButton';
		myHTML += ">&nbsp;"+i+"&nbsp;</button>";
	}
	
	if(OptionID<Count){
	myHTML += "<button class=MenuButton onclick=\"StoryPanel_Control("+Count+",'Next','"+uniqueID+"');\">&nbsp;>&nbsp;</button>";
	}
	document.getElementById('storyButtons'+uniqueID).innerHTML=myHTML;
}

function StoryPanel_Control(Count,Direction,uniqueID){
	for(i=1;i<=Count;i++){
		if(document.getElementById('PanelStory'+i+':'+uniqueID).className=='PanelStoryOn'){
			currentID = i;
		}
		document.getElementById('PanelStory'+i+':'+uniqueID).className='PanelStory';
	}

	nextID = (currentID == Count)?1:currentID+1;
	backID = currentID-1;
	if(Direction=='Next'){
		ShowStoryPanel_Site(Count,nextID,uniqueID);
	}else{
		ShowStoryPanel_Site(Count,backID,uniqueID);
	}
}



function ShowAlertBox(message,closeit){
	if(!closeit){
	//document.getElementById('AlertTable').style.display='';
	document.getElementById('AlertWindow').style.width='40%';
	document.getElementById('AlertWindow').style.left='30%';
	document.getElementById('AlertWindow').style.top='50%';
	document.getElementById('AlertWindow').style.paddingTop='20px';
	document.getElementById('AlertWindow').style.paddingBottom='20px';
	
	document.getElementById('AlertWindow').style.border='10px solid gray';
	document.getElementById('AlertWindow').style.backgroundColor='#f1f1f1';
	document.getElementById('AlertWindow').style.textAlign='center';
	document.getElementById('AlertWindow').innerHTML = message;
	}else{
	document.getElementById('AlertWindow').style.width='0px';
	document.getElementById('AlertWindow').style.height='0px';
	document.getElementById('AlertWindow').style.border='0px solid gray';
	document.getElementById('AlertWindow').innerHTML = '';
	}
}





function changeInputs()
	{
	var els = document.getElementsByTagName('input');
	var elsLen = els.length;
	var i = 0;
	for ( i=0;i<elsLen;i++ )
		{
			if ( els[i].getAttribute('type') )
			{
				if ( els[i].getAttribute('type') == "text" )
				els[i].className = 'text';
			else
				els[i].className = 'button';
			}
		}
	}



function ShowGalleryImage(ImageID,ModuleID){
	document.getElementById('PreviewImage'+ModuleID).innerHTML='<img style=\"border:2px solid white;\" id=GalImage name=GalImage src=\"/images/' + ImageID + '\">';
	//document.getElementById('GalImage').style.width = 150;
	//document.getElementById('GalImage').style.height = 75;
	
	
	var isIE = document.all?true:false;
	if (!isIE) document.captureEvents(Event.MOUSEMOVE);

  	var _x;
  	var _y;
	  if (!isIE) {
	    _x = e.pageX;
	    _y = e.pageY;
	  }
	  if (isIE) {
	    _x = event.clientX + document.body.scrollLeft;
	    _y = event.clientY + document.body.scrollTop;
	  }

	  document.getElementById('PreviewImage').style.left = _x;
	  document.getElementById('PreviewImage').style.top = _y;
}


function WriteGallery(galleryID,myType){
	if(myType=="h"){
	myFileID = '/includes/FlashGallery_H.swf?XMLURL=/includes/blocs.xml.gallery.php?galleryid='+galleryID;
	myWidth = '520px';
	myHeight = '320px';
	}else{
	myFileID = '/includes/FlashGallery.swf?XMLURL=/includes/blocs.xml.gallery.php?galleryid='+galleryID;
	myWidth = '640px';
	myHeight = '390px';
	}
	myVars = '';
	myObject='<br><center><object style="margin-top:5px;z-index:200;display:inline;width:' + myWidth +';height:' + myHeight +'"  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="150" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="middle">';
	myObject+='<param name="allowScriptAccess" value="sameDomain" />';
	myObject+='<PARAM NAME=wmode VALUE=transparent>';
	myObject+='<param name="movie" value="'+ myFileID +'" /><param name="quality" value="high" />';
	myObject+='<embed width="' + myWidth + '" height="' + myHeight +'"  wmode="transparent" src="'+ myFileID +'" quality="high" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	myObject+='</object>';
	document.write(myObject);
}

function MenuOver(DivID){
	//alert('boo');
	//alert(DivID);
	document.getElementById(DivID).style.display='block';
	
}
function MenuOut(DivID){
	document.getElementById(DivID).style.display='none';
	
}

function moveHandler(e){
      if (e == null) { e = window.event } 
      if (e.button<=1&&dragOK){
         savedObject.style.left=e.clientX-dragXoffset+'px';
         savedObject.style.top=e.clientY-dragYoffset+'px';
        
         return false;
      }
   }

   function cleanup(e) {
      document.onmousemove=null;
      document.onmouseup=null;
      savedObject.style.cursor=orgCursor;
      dragOK=false;
    
   }


function dragHandler(e){
   	
      var htype='-moz-grabbing';
      if (e == null) { e = window.event; htype='move';} 
      var target = e.target != null ? e.target : e.srcElement;
      orgCursor=target.style.cursor;
    // alert();
     if (target.className=="Movable"||target.id=="ImageGallery_Preview") {
        savedObject=target;

         dragOX =  parseInt(target.style.left);
         dragOY =  parseInt(target.style.top);
         dragOX = isNaN(dragOX) ? 0 : dragOX;
         dragOY = isNaN(dragOY) ? 0 : dragOY;
         
         target.style.zIndex=100;
         target.style.cursor=htype;
         dragOK=true;
       //  alert(e.clientX);
         dragXoffset=e.clientX-dragOX;//-parseInt(target.style.left);
         dragYoffset=e.clientY-dragOY;//-parseInt(target.style.top);
         //dragXoffset=0;
        //dragYoffset=0;
        document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      } else if (target.id=="ImageGallery_Preview") {
	savedObject=target;
	if(target.style.left){
		dragOX =  parseInt(target.style.left);
		dragOY =  parseInt(target.style.top);
		}else{
		dragOX = 0;
		dragOY = 10;    
		}
	dragOY =  parseInt(target.style.top);
	target.style.zIndex=100;
	target.style.cursor=htype;
	dragOK=true;
	dragXoffset=e.clientX-dragOX;
	dragYoffset=e.clientY-dragOY;
        document.onmousemove=SlideHandler;
	document.onmouseup=cleanupSlider;
	return false;
	}
     
   }
   
document.onmousedown=dragHandler;

function StopGallery(){
	clearInterval(myInterval);
}
function SlideGallery(direction){
	if(direction=='up'){
		myInterval = setInterval('MoveGallery(1)',10);
	}else{
		myInterval = setInterval('MoveGallery(0)',10);
	}
}

function MoveGallery(isUp){
	top_orgin = parseInt(document.getElementById('ImageGallery_Thumbs').style.top);
	if(isUp){
		document.getElementById('ImageGallery_Thumbs').style.top = (top_orgin+2)+'px';
	}else{
		document.getElementById('ImageGallery_Thumbs').style.top = (top_orgin-2)+'px';
	}
}

function Prod_AccOpts(showMe){

	if(showMe=='Options'){
		hideMe='Accessories';
		showBgImage = image_options_bg_url;
		showFloatImage = image_options_float_url;
	}else{
		hideMe='Options';
		showBgImage = image_access_bg_url;
		showFloatImage = image_access_float_url;
	}
	document.getElementById(hideMe+'EditButton').style.display='';
	document.getElementById(showMe+'EditButton').style.display='none';
	document.getElementById(hideMe+'Box').style.backgroundImage='url(/images/bg_optbox.png)';
	document.getElementById(showMe+'Box').style.backgroundImage='url(/images/bg_optbox_down.png)';

	document.getElementById('RightColumn').innerHTML ="<img src='/images/"+image_access_float_url +"'>";
	document.getElementById('Main').style.backgroundImage = "url(/images/"+showBgImage+")";
	
	if(document.getElementById(showMe).style.display=='none'){
		document.getElementById(showMe).style.display='';
		document.getElementById(hideMe).style.display='none';
		
	}else{
		document.getElementById(hideMe).style.display='';
		document.getElementById(showMe).style.display='none';
	}
}

function showInfoBox(labelTxt,infoTxt){

	document.getElementById('PreviewWindow').style.display='block';

	document.getElementById('PreviewMedia').style.display='block';
	document.getElementById('PreviewImage').innerHTML = "<h2>"+labelTxt+"</h2><br><br>"+infoTxt;
}

function hideInfoBox(){
	document.getElementById('PreviewWindow').style.display='none';
	document.getElementById('PreviewMedia').style.display='none';
}

function showHTML(productid){
	location.href='../includes/blocs.cart.processor.php?HTML=1&productid='+productid;
}

function showPDF(productid){
	location.href='../includes/blocs.cart.processor.php?PDF=1&productid='+productid;
}

function backButton(){
	parent.document.getElementById('CustomBuilt').style.display='none';
	parent.document.getElementById('ProductOptions').style.display='';
}
function searchKeyPress(e)
        {
                if (window.event) { e = window.event; }
                if (e.keyCode == 13)
                {
			value = document.getElementById('searchvalue').value;
			
			location.href='/?t=special&q='+value;
                }
		
        }
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function checkRequired(formID){
		var valid = true;
		var theform = document.getElementById(formID).elements;
		var myrequiredfields = '';
		var myradios = new Array();
		for(i=0;i<theform.length;i++){
			if(theform[i].getAttribute('required')=="1"){
				varType =  theform[i].type;
				varName = theform[i].name;
				varValue = theform[i].value;
				switch(varType){
					case 'text':
						if(varValue==''){
							valid = false;
							myrequiredfields +=varName +" is required \n";
						}
						
						break;
					case 'radio':
						var radiochecked = false;
						//alert(theform[i].checked);
						
						if(theform[i].checked==false){
							//alert('NOT CHECKED');
							for(y=0;y<theform.length;y++){
								if(theform[y].name==varName){
									//alert('found match');
									if(theform[y].checked==true){
										//alert('match checked');
										radiochecked = true;
									}else{
										//alert('match not checked');
										//radiochecked = false;
									}
								}else{
										// = false;
									}
							}
						}else{
							//alert('CHECKED');
							radiochecked = true;
						}
						
						
						if(!radiochecked){
							valid = false;
							myrequiredfields +=varName +" is required \n";
						}
						break;
					case 'textarea':
						if(varValue==''){
							valid = false;
							myrequiredfields +=varName +" is required \n";
						}
						break;
					case 'checkbox':
						var ischecked = theform[i].checked;
						if(!ischecked){
							valid = false;
							myrequiredfields +=varName +" is required \n";
						}
						break;
					default:
						alert(varType);
						break;
				}
			
			}
		}
		if(!valid){
			alert(myrequiredfields);
			return false;
		}else{
			return true;
		}
	}
