function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

//zoom 

var bigWidth; //width of the zoom image 
var smallWidth; // width of zoomed image
var bigHeight; // height of the zoom image
var bigX = 0; // zoom image x position
var bigY = 0; // zooom image y position
var smallHeight;
var bigBoxWidth;
var bigBoxHeight;
var factorY;
var factorX;
var easing = 0.18;
var zoomInterval = 0; 
var mouseX = 0;
var mosueY = 0;
var sHeight;
var elements;
var sWidth;
var elements_hor;
var scrollBorder;
var scrollBorder_ver;
var thumbsPos = new Array();
var thumbsPosDown = new Array();
var thumbsPos_ver = new Array();
var thumbsPosDown_ver = new Array();
var imgAmount;
var imgAmount_ver;
var i = 0;
var g = 92*5;
var idc = 0;
var idc_ver = 0;
var hideInterval;
var images;
var images_ver;
var scrollHeight;
var scrollWidth;


function initProductPage()
{
	sHeight = 92;
	document.body.onmousemove=setMouseCoords;
	elements = countElements("thumbnails-mask","img");
	scrollHeight = sHeight * elements ;
	
	sWidth = 92;
	document.body.onmousemove=setMouseCoords;
	elements_hor = countElements("thumbnails-mask-hor","img");
	scrollWidth = sWidth * elements_hor ; 

	smallWidth = 230;
	smallHeight = 345;

	bigBoxWidth = document.getElementById('zoom-box').offsetWidth;
	bigBoxWidth = 392;

	bigBoxHeight = document.getElementById('zoom-box').offsetHeight;

	bigBoxHeight = 414;
	
	document.getElementById('zoom-image').style.left = -450 + 'px';
    document.getElementById('zoom-image').style.top = -800 + 'px';	

	YAHOO.util.Event.addListener("up-arrow", "click", moveUp);
	YAHOO.util.Event.addListener("down-arrow", "click", moveDown);

	YAHOO.util.Event.addListener("prev-arrow", "click", moveNext);
	YAHOO.util.Event.addListener("next-arrow", "click", movePrev);


	//zoom onload vars 
	var oUpArrow = document.getElementById("up-arrow");
	var oDownArrow = document.getElementById("down-arrow");
	
	var oPrevArrow = document.getElementById("prev-arrow");
	var oNextArrow = document.getElementById("next-arrow");

  countsImages_ver ('thumbnails-mask'); 
	countsImages ('thumbnails-mask-hor');
	document.getElementById('medium-image').onclick=showBig;
	document.getElementById('large-image').onmouseover=clearIntrv;

	document.getElementById('large-image').onmouseout=hideBig;
	//document.getElementById('large-image').onclick=showBig;
	bigWidth = document.getElementById('zoom-image').offsetWidth;
	bigHeight = document.getElementById('zoom-image').offsetHeight ;

}


function countsImages (element_id)
{
	images = document.getElementById(element_id).getElementsByTagName('img');

	imgAmount = (images.length -1);
	idcc = (images.length -1);
	scrollBorder = (sWidth * 3 ) - (sWidth*images.length);

	for(var d=1;d<=images.length;d++)
	{
		thumbsPos.push(sWidth*(d-1));
		
		thumbsPosDown.unshift(sWidth*(d-1));
		
		document.getElementById(images[d-1].id).style.left = thumbsPos[d-1]+'px';
	}
}
function countsImages_ver (element_id)
{
	images_ver = document.getElementById(element_id).getElementsByTagName('img');

	imgAmount_ver = (images_ver.length -1);
	idcc = (images_ver.length -1);
	scrollBorder_ver = (sHeight * 3 ) - (sHeight*images_ver.length);

    for(var d=0;d<images_ver.length;d++)
    {
	    thumbsPos_ver.push(sHeight*d);
		
	    thumbsPosDown_ver.unshift(sHeight*d);
		
	    document.getElementById(images_ver[d].id).style.top = thumbsPos_ver[d]+'px';
    }

}

function setMouseCoords(e)
{
	var ie = document.all?true:false;
	if (!e) {
		   e = window.event;
	}
	
	if (e.pageX || e.pageY) {
		   mouseX = e.pageX;
		   mouseY = e.pageY;

	} else if (e.clientX || e.clientY) {
		
	   mouseX = YAHOO.util.Event.getPageX(e); 
	   mouseY = YAHOO.util.Event.getPageY(e); 	
	}
}


//show zoom image 
function showBig()
{
	clearIntrv();	
	document.getElementById('productinfo').style.visibility = 'hidden';
	document.getElementById('zoom-image').style.visibility = 'visible';
	document.getElementById('zoom-box').style.visibility = 'visible';
	
	largeImageShown = true;
	zoomInterval = setInterval("animateBigImage()",20);
}



function loadBig(img,prodId,channel, cache_url)
{
    prepViewLargeImageLink(prodId, img, channel, cache_url)
    document.getElementById("medium-image").src =  img;
    loadZoomImage(img,prodId, cache_url);
}

function loadZoomImage(img,prodId, cache_url)
{
    document.getElementById("zoom-image").src = cache_url + "/images/products/" + img + ".jpg"
    document.getElementById("zoom-image").width = 920;
    document.getElementById("zoom-image").height = 1380;
}

function clearIntrv()
{
	clearTimeout(hideInterval);		
}

function hideBig()
{	
	hideInterval = setTimeout("hideDelay()",250);	
}

function hideDelay()
{	
	if(document.getElementById('zoom-image').style.visibility != 'hidden') {
		clearInterval (zoomInterval);
			
		document.getElementById('productinfo').style.visibility = 'visible';
		
		document.getElementById('zoom-image').style.visibility = 'hidden';
		document.getElementById('zoom-box').style.visibility = 'hidden';		
	}
}

function hideBigBox()
{	
	document.getElementById('zoom-image').style.visibility = 'hidden';
}

//zoom function 
function animateBigImage()
{
	var xPos =  mouseX;
	var yPos =  mouseY;	
	var bigXPos = YAHOO.util.Dom.getX('zoom-image');
	var bigYPos = YAHOO.util.Dom.getY('zoom-image');

	var largeXOffset = YAHOO.util.Dom.getX('medium-image');
	var largeYOffset = YAHOO.util.Dom.getY('medium-image');
	

	var bigXPos = document.getElementById('zoom-image').offsetLeft;
	var bigYPos = document.getElementById('zoom-image').offsetTop;

	factorX = (bigWidth- bigBoxWidth)/smallWidth;
	factorY = (bigHeight - bigBoxHeight) / smallHeight;

	var targetX = 0 - (factorX * (xPos-largeXOffset));
	var targetY = 0 - (factorY * (yPos-largeYOffset));		

	targetX = Math.round(targetX);
	targetY = Math.round(targetY);


	bigX +=  ((targetX-bigX)*easing); 
	bigY +=  ((targetY-bigY)*easing);	

	bigY = Math.round(bigY);
	bigX = Math.round(bigX);


	document.getElementById("zoom-image").style.left  = bigX + 'px';
	document.getElementById("zoom-image").style.top = bigY + 'px';
	
 
}

//scroll fucntionality 

function countElements(container_id, tag)
{
	var container = document.getElementById(container_id);
	var elem_count = container.getElementsByTagName(tag).length;
	return elem_count;
}
 
function moveDown(e)
{		
	if (idc_ver>0) {
		idc_ver--;
	} else {
		idc_ver=images_ver.length-1;
	}
	var tempPoss = thumbsPos_ver.shift();
	thumbsPos_ver.push(tempPoss);
	document.getElementById(images_ver[idc_ver].id).style.top = -92+'px';	
	
	for(var d=0;d<images_ver.length;d++)
	{
		var moves = new YAHOO.util.Anim(images_ver[d].id, {top: {to: thumbsPos_ver[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		moves.animate();		
	}
}
 
//move thumbnails up 
function moveUp(e) 
{ 				
	if(document.getElementById(images_ver[idc_ver].id).offsetTop<92) 
	{		
		document.getElementById(images_ver[idc_ver].id).style.top = 368+'px';
	}
	if(idc_ver<imgAmount_ver)
	{						
		idc_ver++;
	}
	else 
	{
		idc_ver=0;
	}
		
	var tempPos = thumbsPos_ver.pop();
	thumbsPos_ver.unshift(tempPos);
	
	for(var d=0;d<images_ver.length;d++)
	{	
		var move = new YAHOO.util.Anim(images_ver[d].id, {top: {to: thumbsPos_ver[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		move.animate();	
	}
	
}

function moveNext(e)
{		
	if (idc>0) {
		idc--;
	} else {
		idc=images.length-1;
	}
	var tempPoss = thumbsPos.shift();
	thumbsPos.push(tempPoss);
	document.getElementById(images[idc].id).style.left = -92+'px';	
	
	for(var d=0;d<images.length;d++)
	{
		var moves = new YAHOO.util.Anim(images[d].id, {left: {to: thumbsPos[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		moves.animate();		
	}
}
 
//move thumbnails up 
function movePrev(e) 
{ 				
	if(document.getElementById(images[idc].id).offsetLeft<92) 
	{		
		document.getElementById(images[idc].id).style.left = 276+'px';
	}
	if(idc<imgAmount)
	{						
		idc++;
	}
	else 
	{
		idc=0;
	}
		
	var tempPos = thumbsPos.pop();
	thumbsPos.unshift(tempPos);
	
	for(var d=0;d<images.length;d++)
	{	
		var move = new YAHOO.util.Anim(images[d].id, {left: {to: thumbsPos[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		move.animate();	
	}
	
}



function isGoodEmail(emailStr, thankyouflag) 
{
	if (thankyouflag == null) 
	{
		thankyouflag=true;
	}
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\!\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var firstChars=validChars;
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom="(" + firstChars + validChars + "*" + ")";
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid
	if (user.match(userPat)==null) 
	{
		return false;
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if(IPArray[i]>255) 
			{
				return false;
			}
		}
		return true;
	}

	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	{
	   // the address must end in a two letter or three letter word.
	   return false
	}
	if (domArr[domArr.length-1].length==3 && len<2) 
	{
	   return false
	}

	// default behavior - keep existing uses continue to work
	if(thankyouflag) 
	{
	// Everything's valid:
	   window.open('Thank You', 'newFormWindow', 'width=340,height=260');
	}
	return true;
}

function launchGenericPopUp(winName, url, w, h, incScroll)
{	
	var newWindow = window.open(url, winName, 'width='+w+',height='+h+',menubar=no,resizable=1,status=no,scrollbars='+incScroll);
	if (window.focus) {
		newWindow.focus();
	}	
}

function toggleDisplay(id)
{
    var elem = document.getElementById(id);
    var disp = elem.style.display;
	var imgId= 'img'+id; 
	var imgg = document.getElementById(imgId); 
    if('none' != disp)
    {
        elem.style.display = 'none';
		imgg.src = "images/right.jpg" ;
    }
    else
    {
        elem.style.display = 'block';
		imgg.src = "images/down.jpg";
    }
}




function emailus(ProductId) 
{
		window.location = "mailto:customerservice@pret-a-beaute.com?subject=Inquiry about item code "+ProductId;
}					

function emailfriend(ProductId) 
{
		var body = "http://www.pret-a-beaute.com/ViewShopProduct.aspx?ProductId="+ProductId;
		window.location = "mailto: ?subject=Check this at PRET-A-BEAUTE.COM&body="+body;
}
	
function toggletab(id)
{
	if(id!='DESC') {
		var elem1 = document.getElementById('DESC');
		elem1.style.display = 'none';
		var elemm1 = document.getElementById('DESCtd');
		if(elemm1!=null) {
			elemm1.style.backgroundColor = "#E6E6E6";
			elemm1.style.fontWeight= 'normal';
		}
	}
	if(id!='FASHION') {
		var elem2 = document.getElementById('FASHION');
		elem2.style.display = 'none';
		var elemm2 = document.getElementById('FASHIONtd');
		if(elemm2!=null) {
			elemm2.style.backgroundColor = "#E6E6E6";
			elemm2.style.fontWeight= 'normal';
		}
	}
	if (id != 'Third') {
	    var elem3 = document.getElementById('Third');
		elem3.style.display = 'none';
		var elemm3 = document.getElementById('Thirdtd');
		if(elemm3!=null) {
			elemm3.style.backgroundColor = "#E6E6E6";
			elemm3.style.fontWeight= 'normal';
		}
	}
	
//	var elem7 = document.getElementById('test');
//	elem7.style.display = 'none';
	var elem = document.getElementById(id);
	elem.style.display = 'block';
	var tdid = id+'td';
	document.getElementById(tdid).style.backgroundColor = "#FFFFFF"; 
	document.getElementById(tdid).style.fontWeight= 'bold';
}			




function initTSH(){
var str1 = 'test1 test2 test3';
scrollBox=document.getElementById("scrollbox")
scroll1=document.getElementById("scroller1")
scroll2=document.getElementById("scroller2")

scroll1.innerHTML=str1
scroll1.innerHTML+=" | < > | "

scroll2.innerHTML=scroll1.innerHTML
scroll2.style.left= 0
scroll2.style.top= 0

scroll1.onmouseover=function(){clearTimeout(hs3Timer)}
scroll1.onmouseout=function(){scrollTSH()}
scroll2.onmouseover=function(){clearTimeout(hs3Timer)}
scroll2.onmouseout=function(){scrollTSH()}

setTimeout("scrollTSH()",2000)
}


function scrollTSH(){
clearTimeout(hs3Timer)

scroll1Pos=parseInt(scroll1.style.left)
scroll2Pos=parseInt(scroll2.style.left)

scroll1Pos-=step
scroll2Pos-=step

scroll1.style.left=scroll1Pos+"px"
scroll2.style.left= scroll2Pos+"px"

if(scroll1Pos< -scroll1.offsetWidth){
scroll1.style.left=scroll1.offsetWidth+"px"
}


if(scroll2Pos< -scroll1.offsetWidth*2){
scroll2.style.left=0
}

hs3Timer=setTimeout("scrollTSH()",50)

}