// JavaScript Document
var autoMovement = true;var selectedId = 1;var currentFade = false;var currentOpacity = 0;var currentIEOpacity = 0;



function loadVariety2(item_order_num){

	if(confirm("This product is available in different varieties\nPress ok to view options")){
		return true;
	}
	else{
		return false;
	}
}


function clickedNum(id){
	
	selectedId = id; changeSelection(); stopScroll();	
}
function changeSelection(){
	var i = 1;
	while(i <= totalPanels){
		document.getElementById('control' + i).style.backgroundColor = '#CCCCCC';
		document.getElementById('item' + i).style.display = 'none';
		i++;
	}
	document.getElementById('control' + selectedId).style.backgroundColor = '#EEEEEE';
	document.getElementById('item' + selectedId).style.display = 'block';
	fade(selectedId);
	
}function mouseOver(id){
	document.getElementById('control' + id).style.backgroundColor = '#EEEEEE';
}function mouseOut(outid){
	if((outid+1) != selectedId){
		document.getElementById('control' + outid).style.backgroundColor = '#CCCCCC';
	}
}function fade(idFade){
	if(currentFade == false){
		currentFade = true;	
			document.getElementById('item' + idFade).style.opacity = '0';
			document.getElementById('item' + idFade).style.MozOpacity = '0';
			document.getElementById('item' + idFade).style.KhtmlOpacity = '0';
		document.getElementById('item' + idFade).style.filter = 'alpha(opacity=' + 0 + ')';
		currentOpacity = 0;
	}if(currentFade == true){
		if(currentOpacity < 1 && currentIEOpacity < 100){
			currentOpacity = currentOpacity + .2;
			currentIEOpacity = currentIEOpacity + 20;
			document.getElementById('item' + idFade).style.opacity = "" + currentOpacity + "";
			document.getElementById('item' + idFade).style.MozOpacity = "" + currentOpacity + "";
			document.getElementById('item' + idFade).style.KhtmlOpacity = "" + currentOpacity + "";

			document.getElementById('item' + idFade).style.filter = 'alpha(opacity=' + currentIEOpacity + ')';
			setTimeout("fade(" + idFade +");", 70);
		}else{
			currentFade = false;
			document.getElementById('item' + idFade).style.filter = 'none';
			currentOpacity = 0;
			currentIEOpacity = 0;
		}}}
function stopScroll(){
	autoMovement = false;
	document.getElementById('pauseBut').style.display = 'none';
	document.getElementById('startBut').style.display = 'block';
}function startScroll(){
	autoMovement = true;
	startTimer();
	document.getElementById('pauseBut').style.display = 'block';
	document.getElementById('startBut').style.display = 'none';
}function startTimer() {
	if(autoMovement == true){		
		if(selectedId > totalPanels){
			selectedId = 1;
		}if(selectedId <= totalPanels){
			changeSelection();
			selectedId++;
			
		}else{
			changeSelection();
		}		
		setTimeout( "startTimer();", 5000);
	}}

var acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('acceptsCookies=yes') != -1) acceptsCookies = true; 
}
else acceptsCookies = true;



function resizeFrame(framediv, height, width, type){
		currentHeight =  parseInt(document.getElementById(framediv).style.height);
		
		if(type == 'locimg'){
			if(width > 400){
				height = height * (400 / width);
			}
		}
		
				
		while(currentHeight <= height){
			currentHeight = currentHeight+1;
			document.getElementById(framediv).style.height = currentHeight + "px";
		}
		
		while(currentHeight >= height){
			currentHeight = currentHeight-1;
			document.getElementById(framediv).style.height = currentHeight + "px";
		}
		if(height > 340){
			document.getElementById(framediv).style.height = "340px";
		}
	}
	
	
	
	
	
	
	
	function gallerychange(type, path, description, id, count, height, width, server){
		if(count >= 1){
			document.getElementById('1').style.border = '1px solid #CCCCCC';
			document.getElementById('type1').style.backgroundColor = '#FFFFCC';
			document.getElementById('type1').style.color = '#000000';
		}
		if(count >= 2){
			document.getElementById('2').style.border = '1px solid #CCCCCC';
			document.getElementById('type2').style.backgroundColor = '#FFFFCC';
			document.getElementById('type2').style.color = '#000000';
		}
		if(count >= 3){
			document.getElementById('3').style.border = '1px solid #CCCCCC';
			document.getElementById('type3').style.backgroundColor = '#FFFFCC';
			document.getElementById('type3').style.color = '#000000';
		}
		if(count >= 4){
			document.getElementById('4').style.border = '1px solid #CCCCCC';
			document.getElementById('type4').style.backgroundColor = '#FFFFCC';
			document.getElementById('type4').style.color = '#000000';
		}
		if(count >= 5){
			document.getElementById('5').style.border = '1px solid #CCCCCC';
			document.getElementById('type5').style.backgroundColor = '#FFFFCC';
			document.getElementById('type5').style.color = '#000000';
		}
		if(count >= 6){
			document.getElementById('6').style.border = '1px solid #CCCCCC';
			document.getElementById('type6').style.backgroundColor = '#FFFFCC';
			document.getElementById('type6').style.color = '#000000';
		}
		if(count >= 7){
			document.getElementById('7').style.border = '1px solid #CCCCCC';
			document.getElementById('type7').style.backgroundColor = '#FFFFCC';
			document.getElementById('type7').style.color = '#000000';
		}
		if(count >= 8){
			document.getElementById('8').style.border = '1px solid #CCCCCC';
			document.getElementById('type8').style.backgroundColor = '#FFFFCC';
			document.getElementById('type8').style.color = '#000000';
		}
		if(count >= 9){
			document.getElementById('9').style.border = '1px solid #CCCCCC';
			document.getElementById('type9').style.backgroundColor = '#FFFFCC';
			document.getElementById('type9').style.color = '#000000';
		}
		if(count >= 10){
			document.getElementById('10').style.border = '1px solid #CCCCCC';
			document.getElementById('type10').style.backgroundColor = '#FFFFCC';
			document.getElementById('type10').style.color = '#000000';
		}
		
		if(type == 'ytube'){
			document.getElementById('galleryname').innerHTML = description + '<br />&nbsp;';  
			
			document.getElementById('galleryframe').innerHTML='&nbsp;<object width=400 height=310><param name=movie value=http://www.youtube.com/v/'+ path +'&rel=0&autoplay=1></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/v/'+ path +'&rel=0&autoplay=1 type=application/x-shockwave-flash wmode=transparent width=400 height=310></embed></object>';
			
			document.getElementById(id).style.border = '1px solid #FF9900';
			document.getElementById('type' + id).style.backgroundColor = '#FF9900';
			document.getElementById('type' + id).style.color = '#FFFFFF';
			
			resizeFrame('galleryframe', '340', '430');
		}
		if(type == 'locvid'){
			document.getElementById('galleryframe').innerHTML='<embed style=\'margin-top:10px;\' src=/embed/flvplayer.swf width=380 height=300 allowscriptaccess=always allowfullscreen=true flashvars=height=300&width=380&file=/videos/' + path + ' />';
			document.getElementById('galleryname').innerHTML = description + '<br />&nbsp;';  
			
			document.getElementById(id).style.border = '1px solid #FF9900';
			document.getElementById('type' + id).style.backgroundColor = '#FF9900';
			document.getElementById('type' + id).style.color = '#FFFFFF';
			
			resizeFrame('galleryframe', '320', '400');
		}
		if(type == 'locimg'){
			 width2 = parseInt(width)+ 30;
			 height2 = parseInt(height)+ 30;
			 if(width > 400){
				 if(height > 340){
					 document.getElementById('galleryname').innerHTML = description + '<br /><a style="font-size:10px; color:#CCCCCC;"  href="javascript:showImage(\'/iqtoys/images/' + path + '\',\'' + width2 + '\',\'' + height2 + '\',\'1111\');">Click here for a larger version</a>'; 
					 document.getElementById('galleryframe').innerHTML='<img src="/iqtoys/images/gallery_thumb/'+ path +'_w400_h340.jpg" alt="Large Image">';
			 	}
				else{
					 document.getElementById('galleryname').innerHTML = description + '<br /><a style="font-size:10px; color:#CCCCCC;"  href="javascript:showImage(\'/iqtoys/images/' + path + '\',\'' + width2 + '\',\'' + height2 + '\',\'1111\');">Click here for a larger version</a>'; 
					 document.getElementById('galleryframe').innerHTML='<img src="/iqtoys/images/gallery_thumb/'+ path +'_w400_h340.jpg" alt="Large Image">';
				}
			 }

			 else{
				 document.getElementById('galleryname').innerHTML = description + '<br />&nbsp;'; 
				 document.getElementById('galleryframe').innerHTML='<img src="http://' + server + '/iqtoys/images/'+ path +'" alt="Large Image">';
			 }
			 
			document.getElementById(id).style.border = '1px solid #FF9900';
			document.getElementById('type' + id).style.backgroundColor = '#FF9900';
			document.getElementById('type' + id).style.color = '#FFFFFF';
			
			//resizeFrame('galleryframe', height, width, type);
		}
	}
	
	
	
	
	
	function loadVariety(item_order_num){
		
		if(confirm("This product is available in different varieties\nPress ok to view options")){
			window.location = "/site/page=item/item=" + item_order_num;
		}
	}
	
	function loadItem(item_name, quantityField, selector){
		if(selector != 'none'){
			selectorValue = document.getElementById(selector).value;
		}
		
		if (!acceptsCookies) {
			alert("Sorry, you are not able to accept cookies, so a shopping cart could not be created.");
			return false;
		}
		var quantity = document.getElementById(quantityField).value;
		if(selector == 'none'){
			var agree=confirm("Add " + quantity + "x " + item_name + " to your cart?");
		}
		else{
			var agree=confirm("Add " + quantity + "x " + item_name + " " + selectorValue + " to your cart?");
		}
		if (agree)
			return true ;
		else
			return false ;
	}
	
	function Item(item_name, quantityField){
		var quantity = document.getElementById(quantityField).value;
		var agree=confirm("Add " + quantity + "x " + item_name + " to your cart?");
		if (agree)
			return true ;
		else
			return false ;
	}



function openCertDetails()
{
	var referer = "https://www.iqtoys.co.nz";

		
	certDetailsUrlWithReferer = "https://seal.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&dn=www.iqtoys.co.nz&lang=en";

	thewindow = window.open(certDetailsUrlWithReferer,
		"newWindow", config="height=500,width=516,toolbar=no,menubar=no," +
		"scrollbars=yes,resizable=no,location=no,directories=no,status=yes");
}
function showImage(theImage,width,height,name) {
	initStr = "toolbars=no,status=no,width="+width+",height="+height;
	open(theImage,name,initStr);
}
function requireFields(reqFieldAr,reqFieldErrorMsgAr,maskAr,maskErrorMsgAr) {
	var errorMsg = "";
	var numFields = reqFieldAr.length;
	for (i=0;i<numFields;i++) {
		curVal = eval(THE_FORM+"."+reqFieldAr[i]+".value");
		if (curVal=="")
			errorMsg += reqFieldErrorMsgAr[i]+"\n";
		else if ((eval("maskAr[\""+reqFieldAr[i]+"\"]"))!=null&&!(eval("maskAr[\""+reqFieldAr[i]+"\"]").test(curVal)))
			errorMsg += eval("maskErrorMsgAr[\""+reqFieldAr[i]+"\"]")+"\n";
	}
	return errorMsg;
}

