//-- WINDOW FUNCTIONS --
var win = new Array();
var winCount = 0;


//-- LAUNCH NEW WINDOW --
function win_open(url,name,winArgs,focus,timeout){

	if(winArgs == 'full'){winArgs = 'width='+document.body.clientWidth+',height='+document.body.clientHeight;}

	if(winArgs == 'half'){winArgs = 'width='+document.body.clientWidth/2+','+document.body.clientHeight;}

	eval('win['+winCount+'] = window.open(\''+url+'\',\''+name+'\',\'scrollbars=yes,resizable=yes,status=yes,'+winArgs+'\')');
	if(focus == 'self'){ self.focus(); }else{ eval('win['+winCount+'].focus()'); }
	if(timeout > 0){ setTimeout('win[winCount-1].close()',(timeout*1000)); }
	winCount++;
}

//-- CLOSE ALL OPEN WINDOWS --
function win_close(){
	for(x = 0; x < winCount; x++){win[x].close();}
}

//-- WRITE TO WINDOW --
function writeToWin(strText, intWidth, intHeight, intLeft, intTop){
	if(strText.length > 0){
		if(intWidth == ''){ intWidth = 580; }
		if(intHeight == ''){ intHeight = 400; }
		var newWin = window.open('', 'newWin', 'width='+ intWidth +',height='+ intHeight +',left='+ intLeft +',top='+ intTop +',resizable=yes,scrollbars=auto');
		newWin.document.open();
		newWin.document.write(strText);
		newWin.document.close();
	}else{
		return_error('writeToWin', 'Missing strText parameter.');
	}
}

//-- WRITE TO DIV --
function writeToDiv(strText, strDIV){
	if(strDIV != ''){
		var curDiv = getObj(strDIV);
		if(curDiv){
			curDiv.innerHTML = strText;
		}
	}else{
		return_error('writeToDiv', 'Missing strDIV parameter.');
	}
}

//-- OBJECT FUNCTIONS --
function getObj(objName){
	var thisObj;
	if(document.getElementById){
		thisObj = document.getElementById(objName);
	}else{
		if(document.all){
			thisObj = eval("document.all[\"" + objName + "\"]");
		}
	}
	return thisObj;
}

function positionObj(objName, leftVal, topVal){
	if((topVal != '') && (leftVal != '')){
		var curObj = getObj(objName);
		if(curObj){
			curObj.style.position = 'absolute';
			curObj.style.top = topVal;
			curObj.style.left = leftVal;
		}
	}
}

function loadHTML(divName){
	var divText = '';
	var curObj = getObj(divName);
	if(curObj){
		divText = curObj.innerHTML;
	}
	return divText;
}

function return_error(funcName, errMessage){
	alert('Error ('+ funcName +'):\n'+ errMessage);
}

//-- PRINT CONTAINER --
function printData(template, winTitle, containerName){
	var PageContents = loadHTML(containerName);
	if(PageContents != ''){
		PageContents = '<HTML><HEAD><TITLE>'+ unescape(winTitle) +'</TITLE><LINK rel="stylesheet" type="text/css" href="/templates/'+ template +'/styles.css"></HEAD><BODY onLoad="self.print();">'+ unescape(PageContents) +'</BODY></HTML>';
		writeToWin(PageContents, 620, 460);
	}
}

//-- FORM FUNCTIONS --
var errors = 0;
var formName = 'input';


//-- CLEAR FORM --
function clearForm(curForm){
	var fieldType = '';
	for(x = 0; x < curForm.length; x++){
		fieldType = curForm.elements[x].type;
		if((fieldType == 'text')||(fieldType == 'textarea')||(fieldType == 'password')){
			curForm.elements[x].value = '';
		}
		if((fieldType == 'select-one')||(fieldType == 'select-multiple')){
			curForm.elements[x].selectedIndex = 0;
		}
		if((fieldType == 'checkbox')||(fieldType == 'radio')){
			curForm.elements[x].checked = false;
		}
	}
}


//-- SET SELECT --
function set_select(field,value){
	for(x = 0; x < eval('document.'+formName+'.'+field+'.length'); x++){
		if(eval('document.'+formName+'.'+field+'['+x+'].value == '+ value)){
			eval('document.'+formName+'.'+field+'.selectedIndex = '+x)
		}
	}
}

function set_field(name,value){eval('document.'+formName+'.'+name+'.value = "'+ value +'"');}

//-- FORM VALIDATION ROUTINES --
function new_test(){errors = 0;}

function send_form(){
	if(errors == 0){eval('document.'+formName+'.submit()');}
}

function raiseError(field,errorTxt,type){
	errors++;
	if(type == 1){ alert('ERROR: You must enter a valid value for '+ errorTxt +'.'); }
	if(type == 2){ alert('ERROR: You must select a '+ errorTxt +' option.'); }
	if(type == 3){ alert('ERROR: '+ errorTxt +' is not a valid date.'); }
	if(type == 99){ alert('ERROR: '+ errorTxt); }
	eval('document.'+formName+'.'+field+'.focus()');
}

function check_text(field,errorTxt){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.value == ""')){raiseError(field,errorTxt,1);}
	}
}

function check_select(field,errorTxt){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.selectedIndex == 0')){raiseError(field,errorTxt,2);}
	}
}

function check_box(field,errorTxt){
	if(errors == 0){
		if(! eval('document.'+formName+'.'+field+'.checked')){raiseError(field,errorTxt,2);}
	}
}

function check_len(field,errorTxt,operator,length){
	if(errors == 0){
		var curFieldLength = eval('document.'+ formName +'.'+ field +'.value.length');
		errorTxt += ' cannot be '+ operator +' '+ length +' characters; the current field length is '+ curFieldLength +'.';
		if(eval(curFieldLength +' '+ operator +' '+ length)){raiseError(field,errorTxt,99);}
	}
}

function check_str(field,errorTxt,target){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr.indexOf(target) == -1){raiseError(field,errorTxt,1);}
	}
}

function check_chr(field,errorTxt,target){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr.indexOf(target) != -1){raiseError(field,errorTxt,1);}
	}
}

function check_value(field,errorTxt,operator,target){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.value '+ operator +' '+ target)){raiseError(field,errorTxt,1);}
	}
}

function check_email(field){
	if(errors == 0){
		var eStr = eval('document.'+formName+'.'+field+'.value');
		check_str(field,'e-mail (missing "@")','@');
		check_str(field,'e-mail (missing ".")','.');
	}
}

function check_num(field,errorTxt){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr - cStr != 0){raiseError(field,errorTxt,1);}
	}
}

function check_date(field,errorTxt){
	if(errors == 0){
		var strDate = eval('document.'+formName+'.'+field+'.value');
		var checkDate = new Date(strDate);
		if((checkDate.getMonth() + 1) != strDate.substring(0,strDate.indexOf("/"))){raiseError(field,strDate,3);}
	}
}

function replace_str(field,target,result){
	eval('document.'+formName+'.'+field+'.value = document.'+formName+'.'+field+'.value.replace(/'+target+'/g, "'+result+'")');
}

//-- MENU DISPLAY FUNCTIONS --
function windowShade(id){
	var curLayer = getObj(id);
	if(curLayer){
		if(curLayer.style.display == 'none'){
			curLayer.style.display = '';
		}else{
			curLayer.style.display = 'none';
		}
	}
}

function positionDialog(id,top,left){
	positionObj(id,top,left);
}


//-- MENU MOUSE OVER --
function menuOver(linkID,classID){return false;}

//-- MENU MOUSE OUT --
function menuOut(linkID,classID){return false;}

//-- IMAGE FUNCTIONS --
function imgSwap(imgID,newSrc){
	if(document.images){document.images[imgID].src = 'menu/'+imgID+newSrc+'.gif';}
}

function changeOpacity(curImg, opacity){
	if(curImg.style){
		curImg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ opacity +')';
	}
}

//-- UPDATE STYLE --
function updateStyle(layerName, styleName, styleVal){
	var curLayer = getObj(layerName);
	if(curLayer){
		eval('curLayer.style.'+ styleName +' = "'+ styleVal +'"');
	}
}










//-- ROTATE HEADER IMAGE --

 
function get_random(maxNum)
{
  if (Math.random && Math.round)
  {
    var ranNum= Math.round(Math.random()*(maxNum-1));
    ranNum+=1;
    return ranNum;
  }
  else
  {
  today= new Date();
  hours= today.getHours();
  mins=   today.getMinutes();
  secn=  today.getSeconds();
  if (hours==19)
   hours=18;
  var ranNum= (((hours+1)*(mins+1)*secn)%maxNum)+1;
  return ranNum;
  }
}

//Rotates site top left image depending on section
function get_Image(sSectionName)
{
 if (document.images)
 {
  var choose_one= get_random(4);  
  choose_one--;


  switch (sSectionName) 
  {
  case "Home": 



/* define image urls */
     pic1= new Image(100,81);
     pic1.src="images/image2_1.jpg";  
     pic2= new Image(100,81);
     pic2.src="images/image2_2.jpg"; 
     pic3= new Image(100,81);
     pic3.src="images/image2_3.jpg";  
     pic4= new Image(100,81);
     pic4.src="images/image2_4.jpg"; 



  var pics= new Array(4) 
   pics[0]=pic1.src;
   pics[1]=pic2.src;
   pics[2]=pic3.src;
   pics[3]=pic4.src;

  document.write("<IMG SRC='"+pics[choose_one]+"' width='100' height='81' border='0'>");
  break




  case "AllOthers": 


/* define image urls */
     pic1= new Image(116,61);
     pic1.src="images/image9_aboutcebert_1.jpg";  
     pic2= new Image(116,61);
     pic2.src="images/image9_aboutcebert_2.jpg"; 
     pic3= new Image(116,61);
     pic3.src="images/image9_aboutcebert_3.jpg";  
     pic4= new Image(116,61);
     pic4.src="images/image9_aboutcebert_4.jpg"; 



  var pics= new Array(4) 
   pics[0]=pic1.src;
   pics[1]=pic2.src;
   pics[2]=pic3.src;
   pics[3]=pic4.src;

  document.write("<IMG SRC='"+pics[choose_one]+"' width='116' height='61' border='0'>");
  break

  case "Products": 


/* define image urls */
/*
     pic1= new Image(116,61);
     pic1.src="images/image9_cherryliquid_1.jpg";  
     pic2= new Image(116,61);
     pic2.src="images/image9_cherryliquid_2.jpg";  
     pic3= new Image(116,61);
     pic3.src="images/image9_cherryliquid_3.jpg";  
     pic4= new Image(116,61);
	 pic4.src="images/image9_cherryliquid_4.jpg";  
*/
     pic1= new Image(116,61);
     pic1.src="images/image9_aboutcebert_1.jpg";  
     pic2= new Image(116,61);
     pic2.src="images/image9_aboutcebert_2.jpg"; 
     pic3= new Image(116,61);
     pic3.src="images/image9_aboutcebert_3.jpg";  
     pic4= new Image(116,61);
     pic4.src="images/image9_aboutcebert_4.jpg"; 
     


  var pics= new Array(4) 
   pics[0]=pic1.src;
   pics[1]=pic2.src;
   pics[2]=pic3.src;
   pics[3]=pic4.src;

  document.write("<IMG SRC='"+pics[choose_one]+"' width='116' height='61' border='0'>");
  break



  }
 }
}




