// image swap
function ImgChange(imgNum,imgSrc){
	document.images[imgNum].src = imgSrc;
}

// validates email address
function echeck(str) {
	msg = "The email address you have provided is invalid.";
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert(msg)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert(msg)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert(msg)
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert(msg)
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert(msg)
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert(msg)
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert(msg)
	    return false
	 }
	return true;
}

function toggleImg(dir,i){	
	// replace image src
	document.getElementById('main_gallery_img').src = dir + '/' + imgArray[i];		
	document.getElementById('main_gallery_title').innerHTML = titleArray[i];	
	// set global index
	curr_index=i;
}

function manageImgStack(dir){	
	document.getElementById('main_gallery_img').src = dir + '/' + imgArray[curr_index];	
	document.getElementById('main_gallery_title').innerHTML = titleArray[curr_index];	
}

function scrubImgStack(step){	
	if (step == 'forward'){
		// if we hit max_index, go to beginning of stack
		if (curr_index == max_index){
			curr_index=0;
		} else {
			++curr_index;
		}		
	} else {
		// if we hit 0, go to end of stack
		if (curr_index == 0){
			curr_index=max_index;
		} else {
			--curr_index;
		}
	}
	manageImgStack(img_dir);	
}

function toggleSeller(opt){	
	// loop over array, and close anything currently open
	for (i=0; i < whole_groups.length; i++){
		if (document.getElementById(whole_groups[i]).style.display != 'none'){
			new Effect.BlindUp(whole_groups[i]);
		}
	}
	// loop over array, and close anything currently open
	for (i=0; i < retail_groups.length; i++){
		if (document.getElementById(retail_groups[i]).style.display != 'none'){
			new Effect.BlindUp(retail_groups[i]);
		}
	}	
	// now expand the currently selected option
	new Effect.BlindDown(opt);
}

function togglePrivacy(){
	if (document.getElementById('privacy').style.display != 'none'){
			new Effect.BlindUp(document.getElementById('privacy'));
	} else {
			new Effect.BlindDown(document.getElementById('privacy'));
	}
}

function collectionImage(img){
 	iWin = window.open(img, 'iWin', 'resizable=false,scrollbars=false,width=350,height=350,left=25,top=25');
	iWin.focus();
}