// JavaScript Document

function bindEvent(n,o,f)//nesne,olay,fonksiyon
{
	if(n.attachEvent)return n.attachEvent("on"+o,f);
	else if(n.addEventListener)return n.addEventListener(o,f,false);	
}
function unbindEvent(n,o,f)
{
	if(n.detachEvent)return n.detachEvent("on"+o,f);
	if(n.removeEventListener)return n.removeEventListener(o,f,false);
}

function nTop(n)
{
	try
	{
		if(n.offsetParent.tagName=='BODY')return n.offsetTop;
		else if(n.offsetParent.tagName=='TBODY')return 0;
		else return n.offsetTop+nTop(n.offsetParent);
	}
	catch(e)
	{
		return 0;
	}
}

function nLeft(n)
{
	try
	{
		if(n.offsetParent.tagName=='BODY')return n.offsetLeft;
		else if(n.offsetParent.tagName=='TBODY')return 0;
		else return n.offsetLeft+nLeft(n.offsetParent);
	}
	catch(e)
	{
		return 0;
	}
}

function parseMoney(f)
{
	f=f.toString();
	var i=f.indexOf('.');
	if(i!=-1){
		f=f.substr(0,i+3);
	}
	return f;
}

function getWindowWidth()
{
	if(window.innerHeight){
		var w=window.innerWidth;
	} else if(document.documentElement.clientHeight){
		var w=document.documentElement.clientWidth;
	} else if(document.body.offsetHeight){
		var w=document.body.offsetWidth;
	} else {
		var w=944;
	}
	return w;
}

function getWindowHeight()
{
	if(window.innerHeight){
		var h=window.innerHeight;
	} else if(document.documentElement.clientHeight){
		var h=document.documentElement.clientHeight;
	} else if(document.body.offsetHeight){
		var h=document.body.offsetHeight;
	} else {
		var h=1000;
	}
	
	return h;
}

function oClone(a)
{
	var o = new Object();
	var i=null;
	for(i in a){
		o[i]=a[i];
	}
	return o;
}

function clearSelect(s)
{
	for(var n=s.options.length-1;n>=0;n--)s.options[n]=null;
}

function fillSelect(s,v,clear)
{
	if(clear)clearSelect(s);
	var o=null;
	for(x in v){
		o=new Option(v[x],x);
		s.options[s.options.length]=o;
	}
}

function $id(n)
{
	return document.getElementById(n);
}

// JavaScript Document
//function xOverlay(bgColor,opacity,hideOnClick)
//function xDialog(xo,hasCloseButton,hasBorder)
//function xSlideShow(xd,hasCloseButton,hasBorder)

function setOpacity(element,opacity)
{
	if(navigator.appName=="Microsoft Internet Explorer"){
		var f="alpha(opacity="+(parseFloat(opacity)*100)+")";
		element.style.filter=f;
		
	} else {
		element.style.opacity=opacity;
	}
}

function xOverlay(bgColor,opacity,hideOnClick)
{
	this.bgColor=bgColor;
	this.opacity=opacity;
	this.hideOnClick=hideOnClick;
	var xo=this;
	var $w=$(window);
	var $d=$(document);
	var o=document.createElement('div');
	this.o=o;
	o.style.position='absolute';
	o.style.top="0px";
	o.style.left="0px";
	this.setSize = function (){
		try{
			o.style.width=($d.width())+"px";
			o.style.height=($d.height())+"px";
			
			/*if(navigator.appVersion.indexOf("MSIE 7")!=-1){
				o.style.width=($d.width())+"px";
				o.style.height=($d.height())+"px";
			} else {
				var hsbar=false;
				var vsbar=false;
				if( $d.width() > ($w.width()+21) )hsbar=true;
				if( $d.height() > ($w.height()+21) )vsbar=true;
				if(vsbar&&hsbar){
					o.style.width=($d.width())+"px";
					o.style.height=($d.height())+"px";
				} else if(vsbar){
					o.style.width=($d.width()-21)+"px";
					o.style.height=($d.height())+"px";
				} else if(hsbar){
					o.style.width=($d.width())+"px";
					o.style.height=($d.height()-21)+"px";
				} else {
					o.style.width=($d.width()-4)+"px";
					o.style.height=($d.height()-4)+"px";
				}
			}*/
		} catch(exc) {
			
		}
	};
	
	this.setSize();
	o.style.backgroundColor=this.bgColor;
	o.style.display='none';
	setOpacity(o,opacity);
	o.style.padding="0px";
	o.style.margin="0px";
	o.style.zIndex=9999999;
	
	$(o).click(function (){
		if(xo.hideOnClick){
			xo.hide();
		}
	});
	document.body.appendChild(o);
	$w.resize(function (){
		xo.setSize();
	});
	$w.scroll(function(){
		return;
		//alert($w.scrollTop()+":"+$w.scrollLeft());
		o.style.top=$w.scrollTop()+"px";
		o.style.left=$w.scrollLeft()+"px";
		if(xo.activeElement){
			xo.relocateElement(xo.activeElement);
		}
	});
	
	this.relocateElement = function (element){
		element.style.top=(($w.height()-element.clientHeight)/2+$w.scrollTop())+"px";
		element.style.left=(($w.width()-element.clientWidth)/2+$w.scrollLeft())+"px";
	};
	
	this.show=function (element,opacity){
		xo.setSize();
		o.style.display='block';
		if(element){
			if(typeof(element)=="string"){
				element=document.getElementById(element);
			}
			if(element.parentNode){
				element.parentNode.removeChild(element);
			}
			xo.activeElement=element;
			element.style.position="absolute";
			element.style.visibility="hidden";
			element.style.display="block";
			setOpacity(element,opacity);
			document.body.appendChild(element);
			this.relocateElement(element);
			element.style.zIndex=9999999+1;
			element.style.visibility="visible";
		}
		if(this.onShow){
			this.onShow();
		}
	};
	
	this.hide=function (){
		o.style.display='none';
		if(xo.activeElement){
			xo.activeElement.style.visibility="hidden";
			xo.activeElement.style.display="none";
		}
		if(this.onHide){
			this.onHide();
		}
		delete xo.activeElement;
	};
	
	this.hide2=function (){
		o.style.display='none';
		if(xo.activeElement){
			xo.activeElement.style.visibility="hidden";
			xo.activeElement.style.display="none";
		}
		delete xo.activeElement;
	};
}

function xDialog(xo,hasCloseButton,hasBorder)
{
	this.xo=xo;
	this.hasBorder=hasBorder;
	this.hasCloseButton=hasCloseButton;
	this.disableHide=false;
	var xd=this;
	
	this.d=document.createElement('div');
	this.d.id='xDialogContainer';
	this.d.style.position='absolute';
	this.d.style.visibility='hidden';
	document.body.appendChild(this.d);
	
	if(hasBorder){
		this.borderTL=document.createElement('div');
		this.borderTL.id='xDialogTopLeft';
		this.borderTL.style.position='absolute';
		this.borderTL.style.zIndex=1;
		this.d.appendChild(this.borderTL);
		this.borderTC=document.createElement('div');
		this.borderTC.id='xDialogTopCenter';
		this.borderTC.style.position='absolute';
		this.borderTC.style.zIndex=1;
		this.d.appendChild(this.borderTC);
		this.borderTR=document.createElement('div');
		this.borderTR.id='xDialogTopRight';
		this.borderTR.style.position='absolute';
		this.borderTR.style.zIndex=1;
		this.d.appendChild(this.borderTR);
		this.borderML=document.createElement('div');
		this.borderML.id='xDialogMiddleLeft';
		this.borderML.style.position='absolute';
		this.borderML.style.zIndex=1;
		this.d.appendChild(this.borderML);
		this.borderMR=document.createElement('div');
		this.borderMR.id='xDialogMiddleRight';
		this.borderMR.style.position='absolute';
		this.borderMR.style.zIndex=1;
		this.d.appendChild(this.borderMR);
		this.borderBL=document.createElement('div');
		this.borderBL.id='xDialogBottomLeft';
		this.borderBL.style.position='absolute';
		this.borderBL.style.zIndex=1;
		this.d.appendChild(this.borderBL);
		this.borderBC=document.createElement('div');
		this.borderBC.id='xDialogBottomCenter';
		this.borderBC.style.position='absolute';
		this.borderBC.style.zIndex=1;
		this.d.appendChild(this.borderBC);
		this.borderBR=document.createElement('div');
		this.borderBR.id='xDialogBottomRight';
		this.borderBR.style.position='absolute';
		this.borderBR.style.zIndex=1;
		this.d.appendChild(this.borderBR);
	}
	
	if(hasCloseButton){
		this.clsBtn=document.createElement('div');
		this.clsBtn.id='xDialogCloseButton';
		this.clsBtn.style.cursor='pointer';
		this.clsBtn.style.position='absolute';
		this.clsBtn.style.visibility='hidden';
		this.clsBtn.onclick = function (){
			if(!xd.disableHide){
				xd.hide();
			}
		};
		this.clsBtn.style.zIndex=9999999+3;
		document.body.appendChild(this.clsBtn);
	}

	this.relocateElement = function (element,width,height){
		if(!width||!height){
			return;
		}
		var awidth=width;
		var aheight=height;
		if(this.hasBorder){
			
			var leftBorderWidth=this.borderTL.clientWidth;
			leftBorderWidth=Math.max(leftBorderWidth,this.borderML.clientWidth);
			leftBorderWidth=Math.max(leftBorderWidth,this.borderBL.clientWidth);
			
			var rightBorderWidth=this.borderTR.clientWidth;
			rightBorderWidth=Math.max(rightBorderWidth,this.borderMR.clientWidth);
			rightBorderWidth=Math.max(rightBorderWidth,this.borderBR.clientWidth);
			
			width+=leftBorderWidth+rightBorderWidth;
			
			var topBorderHeight=this.borderTL.clientHeight;
			topBorderHeight=Math.max(topBorderHeight,this.borderTC.clientHeight);
			topBorderHeight=Math.max(topBorderHeight,this.borderTR.clientHeight);
			
			var bottomBorderHeight=this.borderBL.clientHeight;
			bottomBorderHeight=Math.max(bottomBorderHeight,this.borderBC.clientHeight);
			bottomBorderHeight=Math.max(bottomBorderHeight,this.borderBR.clientHeight);
			
			height+=topBorderHeight+bottomBorderHeight;
			
			element.style.top=topBorderHeight+'px';
			element.style.left=leftBorderWidth+'px';
			
			this.borderTL.style.left='0px';
			this.borderTL.style.top='0px'
			
			this.borderTC.style.left=leftBorderWidth+'px';
			this.borderTC.style.top='0px';
			this.borderTC.style.width=awidth+"px";
			
			this.borderTR.style.left=(leftBorderWidth+awidth)+'px';
			this.borderTR.style.top='0px';
			
			this.borderML.style.top=topBorderHeight+"px";
			this.borderML.style.height=aheight+"px";
			this.borderMR.style.top=topBorderHeight+"px";
			this.borderMR.style.left=(leftBorderWidth+awidth)+'px';
			this.borderMR.style.height=aheight+"px";
			
			this.borderBL.style.top=(topBorderHeight+aheight)+'px';
			this.borderBC.style.top=(topBorderHeight+aheight)+'px';
			this.borderBC.style.left=leftBorderWidth+'px';
			this.borderBC.style.width=awidth+'px';
			this.borderBR.style.top=(topBorderHeight+aheight)+'px';
			this.borderBR.style.left=(leftBorderWidth+awidth)+'px';
			
		}
		
		this.d.style.width=width+"px";
		this.d.style.height=height+"px";
		this.xo.relocateElement(this.d);
	};
	
	this.show = function(element,width,height,opacity,disableHide){
		if(typeof(element)=="string"){
			element=document.getElementById(element);
		}
		this.activeElement=element;
		
		this.clsBtn.style.display='none';
		this.clsBtn.style.visibility='hidden';
		/*if(disableHide){
			this.disableHide=true;
			this.xo.hideOnClick=false;
		} else {
			this.disableHide=false;
			this.xo.hideOnClick=true;
			this.clsBtn.style.visibility='visible';
		}
		*/

		if(!opacity){
			opacity=1;
		}

		element.parentNode.removeChild(element);
		this.d.appendChild(element);
		element.style.display='block';
		element.style.visibility='visible';
		element.style.position='absolute';
		element.style.top='0px';
		element.style.left='0px';
		element.style.zIndex=2;

		this.relocateElement(element,width,height);

		this.xo.onHide=function (){
			xd.hide();
		};
		this.xo.show(this.d,opacity);
		this.relocateElement(element,width,height);
		
		if(this.hasCloseButton && !disableHide){
			this.disableHide=false;
			this.xo.hideOnClick=true;
			this.clsBtn.style.display='block';
			this.clsBtn.style.visibility='visible';
			this.clsBtn.style.top=(nTop(this.borderTR))+"px";
			this.clsBtn.style.left=(nLeft(this.borderTR)-16)+"px";
		} else {
			this.disableHide=true;
			this.xo.hideOnClick=false;
			this.clsBtn.style.visibility='hidden';
			this.clsBtn.style.display='none';
		}
		
		if(this.onShow){
			this.onShow();
		}
	};

	this.hide = function(){
		this.xo.hide2();
		xd.d.style.display='none';

		xd.d.style.visibility='hidden';
		if(xd.activeElement){
			xd.activeElement.style.display='none';
			xd.activeElement.style.visibility='hidden';
			xd.d.removeChild(xd.activeElement);
			document.body.appendChild(xd.activeElement);
		}
		if(this.clsBtn){
			this.clsBtn.style.display='none';
		}
		
		delete xd.activeElement;
		if(this.onHide){
			this.onHide();
		}
	};
}

function xSlideShow(xd,hasCloseButton,hasBorder)
{
	this.xd=xd;
	this.hasCloseButton=hasCloseButton;
	this.hasBorder=hasBorder;
	this.disableHide=false;
	
	var xss=this;
	
	this.d = document.createElement('div');
	this.d.id="xSlideShowContainer";
	this.d.style.position="absolute";
	this.d.style.display="block";
	this.d.style.visibility="hidden";
	document.body.appendChild(this.d);

	this.img = document.createElement('img');
	this.img.id = "xSlideShowImage";
	this.img.style.position="absolute";
	this.img.style.cursor="pointer";
	this.d.appendChild(this.img);

	this.nextBtn = document.createElement('div');
	this.nextBtn.id = "xSlideShowNextButton";
	this.nextBtn.style.position="absolute";
	this.nextBtn.style.display="block";
	this.nextBtn.style.cursor="pointer";
	this.nextBtn.onclick=function (){
		xss.next();
	};
	
	this.nextBtn.onmousedown = function (){
		/*var x=this.offsetLeft+1;
		var y=this.offsetTop+1;
		
		this.style.top=y+"px";
		this.style.left=x+"px";*/
		this.id='xSlideShowNextButton2';
	};
	this.nextBtn.onmouseup = function (){
		/*var x=this.offsetLeft-1;
		var y=this.offsetTop-1;
		
		this.style.top=y+"px";
		this.style.left=x+"px";*/
		this.id='xSlideShowNextButton';
	};
	
	this.d.appendChild(this.nextBtn);

	this.previousBtn = document.createElement('div');
	this.previousBtn.id = "xSlideShowPreviousButton";
	this.previousBtn.style.position="absolute";
	this.previousBtn.style.display="block";
	this.previousBtn.style.cursor="pointer";
	this.previousBtn.onclick=function (){
		xss.previous();
	};
	this.previousBtn.onmousedown = function (){
		/*var x=this.offsetLeft+1;
		var y=this.offsetTop+1;
		
		this.style.top=y+"px";
		this.style.left=x+"px";
		*/
		this.id='xSlideShowPreviousButton2';
	};
	this.previousBtn.onmouseup = function (){
		/*var x=this.offsetLeft-1;
		var y=this.offsetTop-1;
		
		this.style.top=y+"px";
		this.style.left=x+"px";
		*/
		this.id='xSlideShowPreviousButton';
	};
	
	this.d.appendChild(this.previousBtn);
	
	this.current = document.createElement('div');
	this.current.id = "xSlideShowCurrent";
	this.current.style.position="absolute";
	this.d.appendChild(this.current);

	this.currentPicture=0;
	this.pictures=[];
	
	this.img.onload=function (){
		xss.img.style.display='block';
		//xss.xd.show(xss.d,0,0);
		setTimeout(function (){
			var width=xss.img.clientWidth+28;
			width=Math.max(width,xss.previousBtn.clientWidth+xss.nextBtn.clientWidth+85);
			var height=Math.max(xss.previousBtn.clientHeight,xss.nextBtn.clientHeight);
			height+=xss.img.clientHeight+10;
			
			xss.img.style.left=((width-xss.img.clientWidth)/2)+"px";
			
			xss.current.style.left=( (width-70)/2 ) + "px";
			
			xss.d.style.width=width+"px";
			xss.d.style.height=height+"px";
			xss.width=width;
			xss.height=height;
			xss.xd.show(xss.d,width,height);
			xss.xd.relocateElement(xss.d,width,height);
			xss.img.style.visibility='visible';
		},50);
							 
	};
	
	this.img.onclick=function (){
		xss.next();
	};
	
	this.preloadPictures = function (pictures){
		this.pictures = pictures;
		for(var i=0;i<pictures.length;i++){
			var pimg = new Image();
			pimg.src=pictures[i];
		}
	};
	
	this.next = function (){
		if(this.currentPicture<(this.pictures.length-1)){
			this.loadPicture(this.currentPicture+1);
		} else {
			this.loadPicture(0);
		}
		
	};

	this.previous = function (){
		if(this.currentPicture>0){
			this.loadPicture(this.currentPicture-1);
		} else {
			this.loadPicture(this.pictures.length-1);
		}
	};

	this.show = function (pictures,picture,opacity){
		if(pictures.length==0)return;
		this.xd.hasCloseButton=this.hasCloseButton;
		this.xd.hasBorder=this.hasBorder;
		this.xd.disableHide=this.disableHide;

		this.pictures = pictures;
		if(picture){
			this.loadPicture(picture);
		} else {
			this.loadPicture(0);
		}
		if(opacity){
			setOpacity(this.d,opacity);
		} else {
			setOpacity(this.d,1);
		}
		this.xd.show(this.d,this.width,this.height);
	};
	
	this.loadPicture = function (picture){
		if(picture){
			this.currentPicture=picture;
		} else {
			this.currentPicture=0;
		}
		//this.current.innerHTML=this.pictures[this.currentPicture];
		this.current.innerHTML="image "+(this.currentPicture+1)+" of "+this.pictures.length;
		this.img.style.visibility='hidden';
		this.img.style.display='block';
		this.img.src=this.pictures[this.currentPicture];
		this.width=this.img.clientWidth;
		this.height=this.img.clientHeight;
	};

	this.hide = function (){
	};
}


var mainmenuSelectedItem=null;

function mainmenuItemOver(n)
{
	var id=n.id.replace('mainmenu_','');
	n.src='nimages/mainmenu/menuovr_'+id+'.jpg';
}

function mainmenuItemOut(n)
{
	var id=n.id.replace('mainmenu_','');
	if(n!=mainmenuSelectedItem){
		n.src='nimages/mainmenu/menu_'+id+'.jpg';
	}
}

function mainmenuSetup(n)
{
	$('[class=mainmenuitem]').mouseover(function (){
		mainmenuItemOver(this);
	}).mouseout(function (){
		mainmenuItemOut(this);
	});
	
	if(n){
		mainmenuSelectedItem=$id("mainmenu_0"+n);
		mainmenuItemOver(mainmenuSelectedItem);
	}
}

function productListItemSetup()
{
	$('[class=productlistitem]').mouseover(function (){
		this.style.backgroundImage='url(nimages/productoverbg.png)';
		//this.childNodes[1].style.visibility='visible';
	}).mouseout(function (){
		this.style.backgroundImage='url(nimages/productbg.png)';
		//this.childNodes[1].style.visibility='hidden';
	});
}

function productListItem2Setup()
{
	$('[class=productlistitem2]').mouseover(function (){
		this.style.backgroundImage='url(nimages/productoverbg2.png)';
	}).mouseout(function (){
		this.style.backgroundImage='url(nimages/productbg2.png)';
	});
}

function warn(m,n)
{
	alert(m);
	if(n)
		if(n.focus)n.focus();
	return false;
}

function isValidEmail(e)
{
	var d = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9_\.-]+\.[a-zA-Z]+$/;
	return d.test(e);
}


function isValidFullname(n)
{
	var u = /^[a-zA-Z\ ]+$/;
	return u.test(n);
}

function mSelect(inp,params,opts)
{
	var form=findParentForm(inp);
	var width=params.width;
	var height=params.height;
	var color=params.color;
	var color2=params.color2;
	var bgColor=params.bgColor;
	var bgColor2=params.bgColor2;
	var bgImage=params.bgImage;
	var fontSize=params.fontSize;
	var fontFamily=params.fontFamily;
	var borderStyle=params.borderStyle;
	var borderWidth=params.borderWidth;
	var borderColor=params.borderColor;
	var arrowImage=params.arrowImage;
	var arrowImageDown=params.arrowImageDown;
	var onChange=params.onChange;
	
	//width=inp.style.width;
	
	var obj=new Object();
	var div=document.createElement('div');
	obj.div=div;
	div.id=inp.id+"_mSelectOptions";
	div.style.display='none';
	div.style.position='absolute';
	if(width)div.style.width=width;
	else div.style.width=inp.style.width;
	if(height)div.style.height=height;
	div.style.overflow='auto';
	if(bgColor)div.style.backgroundColor=bgColor;
	if(bgImage)div.style.backgroundImage=bgImage;
	if(borderStyle)div.style.borderStyle='solid';
	else div.style.borderStyle='none';
	if(borderWidth)div.style.borderWidth=borderWidth;
	if(borderColor)div.style.borderColor=borderColor;
	div.style.zIndex='999999';
	
	inp.div = div;
	inp.form=form;
	inp.style.cursor='pointer';
	inp.value=null;
	inp.selectedIndex=-1;
	inp.options=new Array();
	if(onChange)inp.xOnChange=onChange;
	
	var idiv=document.createElement('div');
	idiv.style.position='relative';
	idiv.style.float='left';
	idiv.style.width=inp.style.width;
	idiv.style.height=inp.style.height;
	inp.appendChild(idiv);
	inp.idiv=obj.idiv=idiv;
	
	var tdiv=document.createElement('input');
	tdiv.style.position='absolute';
	//var ttop=Math.floor((parseInt(inp.offsetHeight)-parseInt(fontSize))/2)-3;
	var ttop=1;
	tdiv.style.top=ttop+'px';
	tdiv.style.left='2px';
	tdiv.style.width=inp.style.width;
	tdiv.style.fontSize=fontSize;
	tdiv.style.textAlign='left';
	tdiv.style.borderStyle='none';
	tdiv.style.backgroundColor='transparent';
	tdiv.style.color=color;
	tdiv.style.cursor='pointer';
	tdiv.readOnly=true;
	idiv.appendChild(tdiv);
	inp.tdiv=obj.tdiv=tdiv;
	
	var aimg=document.createElement('img');
	aimg.src=arrowImage;
	aimg.style.cursor='pointer';
	aimg.style.position='absolute';
	aimg.style.top='0px';
	aimg.style.right='0px';
	idiv.appendChild(aimg);
	bindEvent(aimg,"mousedown",function (){
		aimg.src=arrowImageDown;
	});
	bindEvent(aimg,"mouseup",function (){
		aimg.src=arrowImage;
	});
	bindEvent(aimg,"mouseout",function (){
		aimg.src=arrowImage;
	});
	
	var pimg=new Image();
	pimg.src=arrowImageDown;
	
	document.body.appendChild(div);
	
	bindEvent(div,"mouseout",function (){
		obj.timeout=setTimeout(function (){
			div.style.display='none';
			inp.blur();
		},1000);
	});
	
	bindEvent(div,"mouseover",function (){
		if(obj.timeout)clearTimeout(obj.timeout);
	});
	
	bindEvent(inp,"mouseout",function (){
		obj.timeout=setTimeout(function (){
			div.style.display='none';
			inp.blur();
		},1000);
	});
	
	bindEvent(inp,"mouseover",function (){
		if(obj.timeout)clearTimeout(obj.timeout);
	});
	
	var hinp=document.createElement('input');
	hinp.type='hidden';
	hinp.name=inp.id;
	form.appendChild(hinp);
	obj.hinp=hinp;
	
	bindEvent(inp,"click",function (){
		var x=nLeft(inp);
		var y=nTop(inp);
		div.style.top=parseInt(y+inp.offsetHeight+1)+"px";
		div.style.left=x+"px";
		div.style.display='';
	});
	
	
	inp.fill = function(opts,clr){
		if(clr){
			this.clear();
		}
		var h='';
		var op=null;
		var oi=0;
		var cnt=0;
		for(o in opts){
			cnt++;
		}
		for(o in opts){
			op=document.createElement('div');
			inp.options[inp.options.length]=op;
			op.style.cursor='pointer';
			op.style.float="left";
			if( ((parseInt(fontSize)+4)*cnt)>parseInt(height) ){
				op.style.width=(parseInt(this.div.style.width)-21)+"px";
			} else {
				op.style.width=(parseInt(this.div.style.width)-5)+"px";
			}
			op.style.color=color;
			op.style.backgroundColor=bgColor;
			op.style.height=fontSize;
			op.style.padding='2px';
			op.mSelectValue=o;
			op.innerHTML=opts[o];
			op.xIndex=oi;
			if(oi==0){
				tdiv.value=opts[o];
				hinp.value=o;
			}
			bindEvent(op,"mouseover",function (e){
				var n = null;
				if(!window.event)n=e.target;
				else n=window.event.srcElement;
				
				if(obj.timeout)clearTimeout(obj.timeout);
				n.style.backgroundColor=bgColor2;
			});
			bindEvent(op,"mouseout",function (e){
				var n = null;
				if(!window.event)n=e.target;
				else n=window.event.srcElement;
				n.style.backgroundColor=bgColor;
			});
			bindEvent(op,"click",function (e){
				var n = null;
				if(!window.event)n=e.target;
				else n=window.event.srcElement;
				
				inp.selectedIndex=n.xIndex;
				inp.value=hinp.value=n.mSelectValue;
				tdiv.value=n.innerHTML;
				tdiv.value=tdiv.value.replace("&nbsp;&nbsp;&nbsp;&nbsp;","");
				div.style.display='none';
				if(onChange)inp.xOnChange(n.mSelectValue);
			});
			div.appendChild(op);
			++oi;
		}
	};
	
	inp.clear = function(){
		this.div.innerHTML='';
		this.tdiv.value='';
		this.value=null;
		this.selectedIndex=-1;
		inp.options=new Array();
	};
	
	inp.fill(opts);
	
	inp.setSelectedIndex = function (n){
		inp.selectedIndex=n;
		inp.value=hinp.value=inp.options[n].mSelectValue;
		tdiv.value=inp.options[n].innerHTML;
		div.style.display='none';
		if(onChange)onChange(inp.value);
	}
	
	inp.setValue = function (n,noevent){
		var i=0;
		inp.value=n;
		for(i=0;i<inp.options.length;i++){
			if(inp.options[i].mSelectValue==n){
				inp.selectedIndex=i;
				inp.value=hinp.value=inp.options[i].mSelectValue;
				tdiv.value=inp.options[i].innerHTML;
				tdiv.value=tdiv.value.replace("&nbsp;&nbsp;&nbsp;&nbsp;","");
				div.style.display='none';
			}
		}
		if(!noevent)if(onChange)onChange(inp.value);
	}
	
	inp.getValue = function (){
		return hinp.value;
	};
	
	inp.getText = function (){
		var i=0;
		var n=hinp.value;
		for(i=0;i<inp.options.length;i++){
			if(inp.options[i].mSelectValue==n){
				return inp.options[i].innerHTML;
			}
		}
		return "";
	}

	return obj;
}

function newslcheck()
{
	var f=document.forms.newsletterf;
	if(!isValidEmail(f.email.value))return warn("Please enter a valid email address",f.email);
	
	$.ajax({
		type:'GET',
		url:'newslettersubcribe.php?email='+encodeURIComponent(f.email.value),
		success:function results(msg){
			alienWarn('Thank you for subscribing');
		}
	});
	
	return false;
}


function mLogin()
{
	var email=$('#modalLoginEmail').val();
	var passwd=$('#modalLoginPassword').val();
	if(email=="")return warn("Please enter your email address");
	if(!isValidEmail(email))return warn("Please enter a valid email address");
	if(passwd=="")return warn("Please enter your password");
	
	$.ajax({
		type:'GET',
		url:'process.php?mode=mlogin&username='+encodeURIComponent(email)+'&password='+encodeURIComponent(passwd),
		success:function results(msg){
			if(msg=="1"){
				location.href="http://forum.elecite.com/elecite_login.php?username="+encodeURIComponent(email)+"&password="+encodeURIComponent(passwd);
			} else {
				window.xd.hide();
				window.xd.show('loginOops',380,200,0.95);
				//warn("You have entered wrong username or password",document.getElementById('#modalLoginPassword'));
			}
		}
	});
	return false;
}

function showMLogin()
{
	$('#login').click();
}

function sendLostPw()
{
	var email=document.getElementById('lostPwEmail').value;
	if(email=="")return warn("Please enter a valid email address",document.getElementById('lostPwEmail'));
	if(!isValidEmail(email))return warn("Please enter a valid email address",document.getElementById('lostPwEmail'));
	
	$.ajax({
		type:'GET',
		url:'lostpw.php?email='+encodeURIComponent(email),
		success:function results(msg){
			alert("Your password has been sent to your email");
		}
	});
}

function closeAccount()
{
	var reason=document.getElementById('closeReason').value;
	$.ajax({
		type:'GET',
		url:'process.php?mode=closeAccount&reason='+encodeURIComponent(reason),
		success:function results(msg){
			alienWarn_A('You are no longer a ninja.');
			window.xd.onHide = function (){
				window.xd.onShow=null;
				$('#alienwarneye').css('display','none');
				location.href='index.php';
			}
			setTimeout(function (){
			//alert("Your account has been closed");
			location.href='index.php';
								 },7000);
			
		}
	});
}

function stateFill(countryid,ss)
{
	$.ajax({
		type:'GET',
		url:'process.php?mode=liststates&countryid='+encodeURIComponent(countryid),
		success:function results(msg){
			var states=eval(msg);
			if(ss.fill)ss.fill(states,true);
			else fillSelect(ss,states,true)
		}
	});
}

function stateFillSelect(countryid,ss,sid)
{
	$.ajax({
		type:'GET',
		url:'process.php?mode=liststates&countryid='+encodeURIComponent(countryid),
		success:function results(msg){
			var states=eval(msg);
			if(ss.fill)ss.fill(states,true);
			else fillSelect(ss,states,true)
			ss.setValue(sid);
		}
	});
}

function findParentForm(n)
{
	//alert(n.parentNode.tagName+":"+n.parentNode.name);
	if(n==null)return null;
	else if(n.parentNode.tagName=='FORM')return n.parentNode;
	else return findParentForm(n.parentNode);
}

function ie6pngfix()
{
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if(ie6){
		$(document).pngFix(); 
	}
}
var devTimeout=null;

function showDevicesListC(id)
{
	$id('deviceslist').style.display='none';
	var l=$id('devicesclist_'+id);
	var x=150;
	l.style.display='block';
	l.style.width='30px';
	l.style.margin='0px 0px 0px 150px';
	l.style.overflow='hidden';
	var intt=null;
	intt=setInterval(function (){
		clearTimeout(devTimeout);
		if(x==0){
			clearInterval(intt);
		} else {
			x-=30;
			l.style.margin='0px 0px 0px '+x+'px';
			l.style.width=parseInt(180-x)+'px';
		}
	},25);
}

function showDevicesList(id)
{
	$id('devicesclist_'+id).style.display='none';
	var l=$id('deviceslist');
	var x=-150;
	l.style.display='block';
	l.style.width='30px';
	l.style.margin='0px 0px 0px 5px';
	l.style.overflow='hidden';
	var intt=null;
	intt=setInterval(function (){
		clearTimeout(devTimeout);
		if(x==0){
			clearInterval(intt);
		} else {
			x+=30;
			l.style.left=x+'px';
			l.style.width=parseInt(180+x)+'px';
		}
	},25);
}

function showDevicesListCW(id)
{
	$id('deviceslistw').style.display='none';
	var l=$id('devicesclistw_'+id);
	var x=150;
	l.style.display='block';
	l.style.width='30px';
	l.style.margin='0px 0px 0px 150px';
	l.style.overflow='hidden';
	var intt=null;
	intt=setInterval(function (){
		clearTimeout(devTimeout);
		if(x==0){
			clearInterval(intt);
		} else {
			x-=30;
			l.style.margin='0px 0px 0px '+x+'px';
			l.style.width=parseInt(180-x)+'px';
		}
	},25);
}

function showDevicesListW(id)
{
	$id('devicesclistw_'+id).style.display='none';
	var l=$id('deviceslistw');
	var x=-150;
	l.style.display='block';
	l.style.width='30px';
	l.style.margin='0px 0px 0px 5px';
	l.style.overflow='hidden';
	var intt=null;
	intt=setInterval(function (){
		clearTimeout(devTimeout);
		if(x==0){
			clearInterval(intt);
		} else {
			x+=30;
			l.style.left=x+'px';
			l.style.width=parseInt(180+x)+'px';
		}
	},25);
}

var selectDeviceWA=null;
function selectDeviceWShow(a)
{
	if(a){
		selectDeviceWA=a;
	}
	window.xd.onShow = function (){
		var h=170;
		h=Math.max(h,212);
		var offset=$('#xDialogContainer').offset();
		$('#ninjaa').css('top',parseInt(offset.top+(h-147)/2)+"px")
								.css('left',parseInt(offset.left-40)+"px")
								.css('display','block');
		$('#selectDeviceWO').css('top',parseInt(offset.top+110)+"px")
								.css('left',(offset.left+105)+"px")
								.css('display','block');
	};
	window.xd.onHide = function (){
		window.xd.onShow=null;
		$('#ninjaa').css('display','none');
		$('#selectDeviceWO').css('display','none');
	}
	window.xd.show('selectDeviceW',380,170,0.95);
	
	return false;
}

function setSessionDVMID(id)
{
	$.ajax({
		type:'GET',
		url:'process.php?mode=sessiondvmid&dvmid='+id,
		success:function results(msg){
			if(selectDeviceWA && selectDeviceWA.href && selectDeviceWA.href.indexOf("product/")!=-1){
				var p = selectDeviceWA.href.indexOf("product/");
				var l=selectDeviceWA.href.substr(p);
				l=l.split("/");
				location.href = "product/" + l[1];
			} else {
				location.reload();
			}
		}
	});
}

function setSessionDVMIDGoGallery(id)
{
	$.ajax({
		type:'GET',
		url:'process.php?mode=sessiondvmid&dvmid='+id,
		success:function results(msg){
			window.top.location.href='gallery.php';
		}
	});
}

function eleciteWarn(msg,w,h)
{
	if(!w)w=380;
	if(!h)h=170;
	
	document.getElementById('elecitewarn').style.width=w+"px";
	document.getElementById('elecitewarn').style.height=h+"px";
	
	document.getElementById('elecitewarnmsg').innerHTML=msg;
	window.xd.show('elecitewarn',w,h,0.95);
	return false;
}

function alienWarn(msg)
{
	document.getElementById('alignwarnmsg').innerHTML=msg;
	window.xd.show('alienwarn',380,170,0.95);
	var h=document.getElementById('alignwarnmsg').clientHeight+130;
	h=Math.max(h,170);
	window.xd.hide();
	window.xd.onShow = function (){
		var h=document.getElementById('alignwarnmsg').clientHeight+130;
		h=Math.max(h,212);
		var offset=$('#xDialogContainer').offset();
		$('#ninjaa').css('top',parseInt(offset.top+(h-147)/2)+"px")
								.css('left',parseInt(offset.left-40)+"px")
								.css('display','block');
	};
	window.xd.onHide = function (){
		window.xd.onShow=null;
		$('#ninjaa').css('display','none');
	}
	
	document.getElementById('alienwarn').style.height=h+"px";
	window.xd.show('alienwarn',380,h,0.95);
	return false;
}

function alienWarn_A(msg)
{
	document.getElementById('alignwarnmsg').innerHTML=msg;
	window.xd.show('alienwarn',380,170,0.95);
	var h=document.getElementById('alignwarnmsg').clientHeight+130;
	h=Math.max(h,170);
	window.xd.hide();
	window.xd.onShow = function (){
		var offset=$('#xDialogContainer').offset();
		$('#alienwarneye').css('top',parseInt(offset.top+30)+"px")
								.css('left',parseInt(offset.left-50)+"px")
								.css('display','block');
	};
	window.xd.onHide = function (){
		window.xd.onShow=null;
		$('#alienwarneye').css('display','none');
	}
	
	document.getElementById('alienwarn').style.height=h+"px";
	window.xd.show('alienwarn',380,h,0.95);
	return false;
}

$(document).ready(function (){
	window.xo=new xOverlay('#000000',0.65,true);
	window.xd=new xDialog(window.xo,true,true);
	window.xss=new xSlideShow(window.xd,true,true);
	window.loginOopsShow = function (){
		window.xd.onShow = function (){
		var offset=$('#xDialogContainer').offset();
		$('#ninjaa').css('top',parseInt(offset.top+30)+"px")
								.css('left',parseInt(offset.left-40)+"px")
								.css('display','block');
		};
		window.xd.onHide = function (){
			window.xd.onShow=null;
			$('#ninjaa').css('display','none');
		}
		window.xd.show('loginOops',380,200,0.95);
	}
	
	$(window).resize(function (){
		var l=0;
		var w=getWindowWidth();
		l=(w-944)/2-20;
		if(l<0)l=0;
		$id('positioner').style.left=l+'px';
	});
	if(document.getElementById('login')){
		$('#modalLoginEmail , #modalLoginPassword').keypress(function (e){
			//if(e.keyCode==13)mLogin();
		});
	}
	
	if(document.getElementById('deviceslistcontainer')){
		var pdeviceId=null;
		
		$('.pdevice').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
			if(this.childNodes[1])this.childNodes[1].style.backgroundImage='url(nimages/devicescindicateover.png)';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
			if(this.childNodes[1])this.childNodes[1].style.backgroundImage='url(nimages/devicescindicate.png)';
		}).click(function (){
			var id=this.id.toString().replace('pdevice_','');
			
			if($id('devicesclist_'+id)){
				if(devTimeout)clearTimeout(devTimeout);
				$id('deviceslist').style.display='none';
				$id('devicesclist_'+id).style.display='block';
				$('#devicesst').focus();
				//showDevicesListC(id);
				pdeviceId=id;
			} else {
				setSessionDVMID(id);
			}
		});
		
		$('.devicesclist_p').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
			this.childNodes[0].style.backgroundImage='url(nimages/devicescindicatepover.png)';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
			this.childNodes[0].style.backgroundImage='url(nimages/devicescindicatep.png)';
		}).click(function (){
			var id=this.id.toString().replace('devicesclist_p_','');
			
			$id('deviceslist').style.display='block';
			$id('devicesclist_'+id).style.display='none';
			$('#devicesst').focus();
			//showDevicesList(id);
		});
		
		$('.devicesclist_c').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
		}).click(function (){
			if(devTimeout)clearTimeout(devTimeout);
			var id=this.id.toString().replace('devicesclist_c_','');
			setSessionDVMID(id);
		});
		
		$('#devicesst').focus(function(){
			if(devTimeout)clearTimeout(devTimeout);
		}).blur(function (){
			devTimeout=setTimeout(function (){
				$('#deviceslistcontainer').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},300);
		});
		
		$('#devicess').click(function (){
			$('#deviceslistcontainer').css('display','block');
			$('#devicesst').focus();
		}).mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
		}).mouseout(function (){
			devTimeout=setTimeout(function (){
				$('#deviceslistcontainer').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},2000);
		});
		
		$('#deviceslistcontainer').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
		}).mouseout(function (){
			devTimeout=setTimeout(function (){
				$('#deviceslistcontainer').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},2000);
		});
		
		
		
		
		$('#devicessarrow').mousedown(function (){
			this.style.backgroundImage='url(nimages/devicessarrowdown.png)';
		}).mouseup(function (){
			this.style.backgroundImage='url(nimages/devicessarrow.png)';
		}).mouseout(function (){
			this.style.backgroundImage='url(nimages/devicessarrow.png)';
		});
	}
	
	if(document.getElementById('deviceslistcontainerw')){
		var pdeviceId=null;
		
		$('.pdevicew').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
			if(this.childNodes[1])this.childNodes[1].style.backgroundImage='url(nimages/devicescindicateover.png)';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
			if(this.childNodes[1])this.childNodes[1].style.backgroundImage='url(nimages/devicescindicate.png)';
		}).click(function (){
			var id=this.id.toString().replace('pdevicew_','');
			
			if($id('devicesclistw_'+id)){
				if(devTimeout)clearTimeout(devTimeout);
				$id('deviceslistw').style.display='none';
				$id('devicesclistw_'+id).style.display='block';
				$('#devicesstw').focus();
				//showDevicesListC(id);
				pdeviceId=id;
			} else {
				setSessionDVMID(id);
			}
		});
		
		$('.devicesclist_pw').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
			this.childNodes[0].style.backgroundImage='url(nimages/devicescindicatepover.png)';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
			this.childNodes[0].style.backgroundImage='url(nimages/devicescindicatep.png)';
		}).click(function (){
			var id=this.id.toString().replace('devicesclist_pw_','');
			
			$id('deviceslistw').style.display='block';
			$id('devicesclistw_'+id).style.display='none';
			$('#devicesstw').focus();
			//showDevicesList(id);
		});
		
		$('.devicesclist_cw').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
			this.style.color='#333333';
			this.style.backgroundColor='#aaca13';
		}).mouseout(function (){
			this.style.color='#cccccc';
			this.style.backgroundColor='#262b2c';
		}).click(function (){
			if(devTimeout)clearTimeout(devTimeout);
			var id=this.id.toString().replace('devicesclist_cw_','');
			setSessionDVMID(id);
		});
		
		$('#devicesstw').focus(function(){
			if(devTimeout)clearTimeout(devTimeout);
		}).blur(function (){
			devTimeout=setTimeout(function (){
				//$('#deviceslistcontainerw').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},300);
		});
		
		$('#devicessw').click(function (){
			$('#deviceslistcontainerw').css('display','block');
			$('#devicesstw').focus();
		}).mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
		}).mouseout(function (){
			devTimeout=setTimeout(function (){
				//$('#deviceslistcontainerw').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},2000);
		});
		
		$('#deviceslistcontainerw').mouseover(function (){
			if(devTimeout)clearTimeout(devTimeout);
		}).mouseout(function (){
			devTimeout=setTimeout(function (){
				//$('#deviceslistcontainerw').css('display','none');
				//if(pdeviceId)setSessionDVMID(pdeviceId);
			},2000);
		});
		
		
		
		
		$('#devicessarroww').mousedown(function (){
			this.style.backgroundImage='url(nimages/devicessarrowdown.png)';
		}).mouseup(function (){
			this.style.backgroundImage='url(nimages/devicessarrow.png)';
		}).mouseout(function (){
			this.style.backgroundImage='url(nimages/devicessarrow.png)';
		}).click(function (){
			if($id('deviceslistcontainerw').style.display=='block'){
				$id('deviceslistcontainerw').style.display='none';
				return false;
			}
		});
	}
	
	try
	{
		$('.gbtn3').mousedown(function (){
			if(this.src){
				this.src=this.src.replace('.png','2.png');
			}
		}).mouseup(function (){
			if(this.src){
				this.src=this.src.replace('2.png','.png');
			}
		}).mouseout(function (){
			if(this.src){
				this.src=this.src.replace('2.png','.png');
			}
		});
	}catch(e){
	}
});

function preLoadImages()
{
	var srcList=['nimages/mainmenu/menu_01.jpg',
				 'nimages/mainmenu/menu_02.jpg',
				 'nimages/mainmenu/menu_03.jpg',
				 'nimages/mainmenu/menu_04.jpg',
				 'nimages/mainmenu/menuovr_01.jpg',
				 'nimages/mainmenu/menuovr_02.jpg',
				 'nimages/mainmenu/menuovr_03.jpg',
				 'nimages/mainmenu/menuovr_04.jpg',
				 'nimages/productoverbg.png',
				 'nimages/productoverbg2.png',
				 'nimages/spotproductoverbg.png',
				 'nimages/devicessarrowdown.png',
				 'nimages/loginbtn2.png',
				 'nimages/registerbtn2.png',
				 'nimages/browsethemesbtn2.png',
				 'nimages/cancel2.png',
				 'nimages/submit2.png',
				 'nimages/alldonebtn2.png',
				 'nimages/savebtn2.png',
				 'nimages/addtochartbtn2.png',
				 'nimages/checkout2.png',
				 'nimages/goback2.png',
				 'nimages/vieweditcart2.png',
				 'nimages/sendbtn2.png',
				 'nimages/closebtn2.png',
				 'nimages/scnextbtn.png',
				 'nimages/scpreviousbtn.png',
				 'nimages/home2.png',
				 'nimages/producthelp2.png',
				 'nimages/viewall2.png'
				 ];
	
	
	var preLoadImgs=new Array();
	var i=0;
	for(i=0;i<srcList.length;i++){
		preLoadImgs[i]=new Image();
		preLoadImgs[i].src=srcList[i];
	}
}

preLoadImages();
