﻿var objPO = new Object();
objPO.ProductPicIndex = 1;
objPO.ProductColor = "";
objPO.boardpics = new Array();
objPO.boardpicslg = new Array();
objPO.boardpicssupericon = new Array();
objPO.boardpicssupericonwidth = new Array();
objPO.boardpicssupericonheight = new Array();
objPO.boardpicslgwidth = new Array();
objPO.boardpicslgheight = new Array();

function disable_picidx()
{
    var hide = new Array();
    for(i = 1; i <= 10; i++ )
    {
        hide = document.getElementsByName( 'im' + i );
        for(j=0; j<hide.length; j++ )
        {
            hide[j].style.display = 'none';
        }
    }
}
function enable_picidx(idx)
{
    var hide = new Array(); 
    hide = document.getElementsByName( 'im' + idx );    
    for(j=0; j<hide.length; j++ )
    {
        hide[j].style.display = 'inline';
    }

}
function enable_all_picidx()
{
    var hide = new Array();
    var i = 1;
    for( i = 1; i <= 10; i++ )
    {
        hide = document.getElementsByName( 'im' + i );
        for(j=0; j<hide.length; j++ )
        {
            hide[j].style.display = 'inline';
        }
    }
}
//var saveProductPicIndex;
//var saveProductColor;
function saveCurrPicColor()	// save current state (Current color and image index)
{
	objPO.saveProductPicIndex = objPO.ProductPicIndex;
	objPO.saveProductColor = objPO.ProductColor;
}
function restorePicAndColor()	// restore to Selected Color and Image Index
{
	objPO.ProductPicIndex = objPO.saveProductPicIndex;
	objPO.ProductColor = objPO.saveProductColor;
	//setcolorpicidx(objPO.saveProductPicIndex);
	setcolorpic_with_inventory(objPO.saveProductColor);
	setcolorpic(objPO.saveProductColor);
}

// form must have name of emailForm
function clearEmail()
{
  document.emailForm.email.value='';
}

function checkEmail() 
{
  if (document.emailForm.email.value == '' || document.emailForm.email.value == ' enter your email address')
  {
	  alert('Please enter your email address');
	  clearEmail();
	  document.emailForm.email.focus();
	  return false;
  }
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if (!filter.test(document.emailForm.email.value))
  {
	alert('Please re-enter your email address. (email address is like your_name@wavefashion.com)');
	  clearEmail();
	  document.emailForm.email.focus();
	  return false;
  }
  
  document.emailForm.submit();
	return true;
}

function openPopUpTopic(title,topic)
{
	window.open('popup.aspx?title=' + title + '&topic=' + topic, 'Topic', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=550,left=0,top=0');

}
function restoreColorChoice() // restore bold letter to normal
{
    for( var i = 1; i <= 20; i++ )		// max 20 colors
    {
        var elem = document.getElementById( 'ColorVariationTable' + i );		
		if( elem )
			elem.className = 'ColorVariation';
    }
}
function vd() 
{
	return;
}
function jscss(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):
      o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
  return '';
}
function pausecomp(millis) 
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); } 
	while(curDate-date < millis);
} 
var useSaveHtmlContent = false;
var saveHtmlContent;
function WriteLayer(ID,parentID,HtmlContent) 
{
	if (document.layers) 
	{
		var oLayer;
		if(parentID)
		{
			oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
		}
		else
		{
			oLayer = document.layers[ID].document;
		}
		oLayer.open();
		oLayer.write(HtmlContent);
		oLayer.close();
	}
	else if (parseInt(navigator.appVersion)>=5 && navigator.appName=="Netscape") 
	{
		if( document.getElementById(ID) )		
			document.getElementById(ID).innerHTML = HtmlContent;
		else		// probably not loaded yet
		{
			saveHtmlContent = HtmlContent;
			setTimeout("WriteLayer('" + ID + "','" + parentID + "',saveHtmlContent)", 500 );
		}
	}
	else if (document.all) 
	{
		if( document.all[ID] )
			document.all[ID].innerHTML = HtmlContent
		else        // probably not loaded yet.
		{
			saveHtmlContent = HtmlContent;
			setTimeout("WriteLayer('" + ID + "','" + parentID + "',saveHtmlContent)", 500 );			
		}
	}

}
function IsEmpty(aTextField) 
{
   if ((aTextField.value.length==0) || (aTextField.value==null)) 
   {
      return true;
   }
   else { return false; }
}
function hideLayer(whichLayer) {

if (document.getElementById) {
// this is the way the standards work
document.getElementById(whichLayer).style.visibility = "hidden";
}
else if (document.all) {
// this is the way old msie versions work
document.all[whichlayer].style.visibility = "hidden";
}
else if (document.layers) {
// this is the way nn4 works
document.layers[whichLayer].visibility = "hidden";
}

}

function showLayer(whichLayer) {

if (document.getElementById) {
// this is the way the standards work
document.getElementById(whichLayer).style.visibility = "visible";
}
else if (document.all) {
// this is the way old msie versions work
document.all[whichlayer].style.visibility = "visible";
}
else if (document.layers) {
// this is the way nn4 works
document.layers[whichLayer].visibility = "visible";
}

}
// Select Option util
function removeAllOptions(selectbox)
{
    selectbox.options.length = 0;
}
function removeOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
if(selectbox.options[i].selected)
selectbox.remove(i);
}
}
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function noop()
{
}













// blend.js

//
// modified by JR (C)2007 Comsoltech Inc
// mastershin@gmail.com
//
// Queue function
// class Queue
function Queue()
{
    var queue = new Array();
    var queueSpace = 0;
    
    // Method enqueue()
    this.enqueue = function(element)
    {
        queue.push(element);
    }
    
    // Method dequeue()
    this.dequeue = function()
    {
        if( queue.length )
        {
            var element = queue[queueSpace];
            if( ++queueSpace*2 >= queue.length )
            {
                for( var i = queueSpace; i<queue.length; i++ )
                    queue[i-queueSpace] = queue[i];
                queue.length -= queueSpace;
                queueSpace = 0;
            }
            return element;        
        }
        else
            return undefined;      
    }
    this.isThereQueue = function()
    {
        if( queue.length )
            return true;
        else
            return false;
    }
}
var g_image_queue = new Queue();
// Queued image loader
function QueueImage( imageid, imageUrl, callback )
{
    g_image_queue.enqueue( new Array( imageid, imageUrl, callback ) );
}
var g_image_curr_imageid;
var g_image_curr_imageUrl;
var g_image_curr_callback;

function isQueueImageLoaded()
{
    //if( isImageOk(document.getElementById(g_image_curr_imageid)) )
    if( all_image_array[g_image_curr_imageUrl] != null )
    {
        //alert(g_image_curr_imageid + " loaded!");
        if( g_image_curr_callback )     // call back the function
        {
            g_image_curr_callback();
        }
        QueueImageProcessor();      // and immediately process queue
    }
    else    // 
    {
        //alert(g_image_curr_imageid + " not loaded!");
        setTimeout( "isQueueImageLoaded()", 1000 );  // keep checking later
    }    
}
var all_image_array = new Array();

function QueueImageProcessor()
{
    if( g_image_queue.isThereQueue() )    // if there are images in a queue
    {
        var element = g_image_queue.dequeue();
        //while( element )        
        {
        	        		
    				all_image_array[element[1]].src = element[1];
    				
            g_image_curr_imageid = element[0];
            g_image_curr_imageUrl = element[1];
            g_image_curr_callback = element[2];
            
            // now start loading the image                        
            //bt_setImageObject(g_image_curr_imageUrl, g_image_curr_imageUrl);
            if( all_image_array[g_image_curr_imageUrl] == null )    // not loaded yet
            {
                setTimeout( "QueueImageProcessor()", 3000 );    
                //alert("all_image_array " + g_image_curr_imageUrl + " is null" );
            }
            else            
            {
                document.getElementById(g_image_curr_imageid).src = all_image_array[g_image_curr_imageUrl].src;
                //document.getElementById(g_image_curr_imageid).src = g_image_curr_imageUrl;
                        
                // chances are, it's not complete.
                setTimeout( "isQueueImageLoaded()", 1000);
            }
            
            //element = g_image_queue.dequeue();
        }
    }
    else
        setTimeout( "QueueImageProcessor()", 3000 );
}
setTimeout( "QueueImageProcessor()", 8000 );
function bt_setImageObject(key, imagefile)      // key is image URL
{
    all_image_array[key] = new Image();
    all_image_array[key].src = imagefile;
}
function bt_getImageObject(key)
{
    return all_image_array[key];
}







function isImageOk(img) {
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}
function getActualObject(obj) {
    var theObj;
    if (typeof obj == "string") {
		var isCSS = (document.body && document.body.style) ? true : false;
        if (isCSS && document.getElementById) {
            theObj = document.getElementById(obj);
        } else if (isCSS && document.all) {
            theObj = document.all(obj);
        } else if (document.layers) {
            theObj = SeekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	var imgObj = getActualObject(all_image_array[imagefile]);

	var isReady = (typeof imgObj.readyState != 'undefined') ? (imgObj.readyState == "complete") : ((typeof imgObj.complete != 'undefined') ? (imgObj.complete == true) : true);
	if (isReady == false)
	{
		setTimeout( "blendimage('" + divid + "','" + imageid + "','" + imagefile + "','" + millisec + "')", 250 );
		return;
	}


	if( all_image_array[imagefile] == null )
	{
		setTimeout( "blendimage('" + divid + "','" + imageid + "','" + imagefile + "','" + millisec + "')", 250 );
	    return;
	}

	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	//document.getElementById(imageid).src = imagefile;
	
	document.getElementById(imageid).src = all_image_array[imagefile].src;

	//fade in image
	var step = 5;      // must be added to exact 100
	for(var i = 0; i <= 100; i+=step) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed * step));
		timer++;
		
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


function findByID(p, id) {
	// var arObj = document.getElementsByTagName(tag);
	var arObj = p.childNodes;
	// var serverCtrlName = id.replace(/_/g, "’$'"); /* remove all underscores? */
	var regExId = new RegExp(id + "$", "ig"); /* search pattern: the ID string must be at the end of the control's ID or name; ig = case-insensitive, global matches */

	for (var i = 0; i < arObj.length; i++) {
		if (arObj[i].id) {
			if (arObj[i].id.match(regExId))
				return arObj[i];
		}
		/*
		else if (arObj[i].name)
		{
		if (arObj[i].name == serverCtrlName)
		return arObj[i];
		}
		*/
	}

	return false;
}
function findByTag(p, tag) 
{
	// var arObj = document.getElementsByTagName(tag);
	var arObj = p.getElementsByTagName(tag);
	// var serverCtrlName = id.replace(/_/g, "’$'"); /* remove all underscores? */

	if( arObj )
		return arObj[0];
	return false;
}
var AJAX = null; // Initialize the AJAX variable.
AJAX = newAjax();
function newAjax()
{
	if (window.XMLHttpRequest) { //Are we working with mozilla?
	return new XMLHttpRequest(); //Yes -- this is mozilla.
	} else { // Not Mozilla, must be IE
	return new ActiveXObject("Microsoft.XMLHTTP"); // Wheee, ActiveX, how do we format c: again?
	} // End setup Ajax.
	if (AJAX==null) { // If we couldn't initialize Ajax...
//	alert("Your browser doesn't support AJAX."); // Sorry msg. return false //
	}
}