/*****************************************************
Function: add/remove elements from the document
******************************************************/

function removeElement(parentID,elementID){
	var parent = document.getElementById(parentID);
	var child = document.getElementById(elementID);
	
	parent.removeChild(child);
}

function addElement(parentID,elementID,elementType){
	var newElement = document.createElement(elementType);
	newElement.setAttribute('id',elementID);
	var parent = document.getElementById(parentID);
	
	parent.appendChild(newElement);
}

function setElementAttribute(id,stype,text){
	var element = document.getElementById(id);
	
	element.setAttribute(stype,text);
}

function setClassName(id,sclass){
	var element = document.getElementById(id);
	element.className = sclass;
}

function setOnClick(element,statement){
	document.getElementById(element).onclick = function(){eval(statement)};	
}

/*****************************************************
Function: check value agains regular expression
******************************************************/
function checkRegExpress(reg,id,format){
	var element = document.getElementById(id);
	
	if(!element.value.match(reg)){
		showError(format);
		return false;
	}else{
		return true;	
	}
}


/*****************************************************
Function: show/hide div
******************************************************/
function showHideElement(element,state){ //state: true = show ; false = hide
	var div = document.getElementById(element);
	var divStyle = div.style;
	
	if(state){
		divStyle.display = 'block';
	}else{
		divStyle.display = 'none';
	}
}

/*****************************************************
Function: page information
******************************************************/
if(document.all) { 
	document.onmousemove = UpdateCursorPositionDocAll; 
}else {
	document.onmousemove = UpdateCursorPosition; 
}

var cX = 0; var cY = 0;

function UpdateCursorPosition(e){
	cX = e.pageX; 
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e){
	cX = event.clientX; 
	cY = event.clientY;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

/*****************************************************
Function: popup  error msg to user
******************************************************/
function showError(msg){
	popupSetTitle("Oooops!!");
	popupSetText(msg);
	popupAddButton("OK","OK","popupHide()");
	popupShow();	
}

/*****************************************************
Function: check to see if an element is in an array
******************************************************/
function inArray(arr,value){
	var found = false;
	
	for(x in arr){
		if(arr[x] == value){
			found = true;
			break;
		}
	}
	
	return found;
}

/*****************************************************
Function: Macromedia functions
******************************************************/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*****************************************************
Function: fading images for pages
		FadeImages(sImages,sPause,sWidth,sHeight);
******************************************************/
function lifeStyleImages(){
	var ImagesToSend = new Array()
	ImagesToSend[0] = "/images/main/lifestyle/01.jpg"
	ImagesToSend[1] = "/images/main/lifestyle/02.jpg"
	ImagesToSend[2] = "/images/main/lifestyle/04.jpg"
	//ImagesToSend.sort(randOrd);
	FadeImages(ImagesToSend,7000,958,370);
}

function featuresImages(){
	var ImagesToSend = new Array()
	ImagesToSend[0] = "/images/main/features/01.jpg"
	ImagesToSend[1] = "/images/main/features/02.jpg"
	ImagesToSend[2] = "/images/main/features/03.jpg"
	//ImagesToSend.sort(randOrd);
	FadeImages(ImagesToSend,7000,958,370);
}

function designImagesTop(){
	var ImagesToSend = new Array()
	ImagesToSend[0] = "/images/main/design/top01.jpg"
	ImagesToSend[1] = "/images/main/design/top02.jpg"
	//ImagesToSend.sort(randOrd);
	FadeImages(ImagesToSend,5000,270,185);
}

function designImagesBottom(){
	var ImagesToSend = new Array()
	ImagesToSend[0] = "/images/main/design/bottom01.jpg"
	ImagesToSend[1] = "/images/main/design/bottom02.jpg"
	//ImagesToSend.sort(randOrd);
	FadeImages(ImagesToSend,6000,270,185);
}

function designImagesMain(){
	var ImagesToSend = new Array()
	ImagesToSend[0] = "/images/main/design/01.jpg"
	ImagesToSend[1] = "/images/main/design/02.jpg"
	//ImagesToSend.sort(randOrd);
	FadeImages(ImagesToSend,7000,688,370);
}

/*****************************************************
Function: fading images for pages with backgrounds
		function changes css class
******************************************************/
var t;
var i = 0;
var x = 0;

function fadeFeatures(){
	var bgDIV = document.getElementById("bgFeaturesFade");
	if(bgDIV){
		if(i==0){
			t = setTimeout("fadeFeatures()",7000);
			setClassName('bgFeaturesFade','bgFeatures1');
			i = 1;
		}else{
			t = setTimeout("fadeFeatures()",7000);
			setClassName('bgFeaturesFade','bgFeatures2');
			i = 0;
		}
	}
}	

/*****************************************************
Function: flash functions
******************************************************/
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function flashSound(control,swfName) { // 0 = off; 1= on
	var flashMovie = getFlashMovie("home");
	if(flashMovie){
		flashMovie.sendTextToFlash(control);	
	}
}
 
function getTextFromFlash(str) {
	document.htmlForm.receivedField.value = "From Flash: " + str;
	return str + " received";
}

/*****************************************************
Function: browser popup window
******************************************************/

function go(url,w,h) {
	var dim = eval('"width=' + w + ',height=' + h + ',toolbar=0, location=0,directories=0,status=0, menubar=0,scrollbars=0,resizable=0"');
	Npop = window.open(url,"flash",dim);
	oldWin = Npop.opener;
	
	flashSound('0');
}
