
// buy check
validatePurchase = function (groupNameForErrorMsg) { //groupNameForErrorMsg optionally passed for options on buy button
var msgOptions='';
var msgPrices='';

if (document.getElementById('PRODoption').value=='not_selected'){
if (groupNameForErrorMsg)   msgOptions =  groupNameForErrorMsg;
if (!groupNameForErrorMsg)  msgOptions = 'Product options.' ;
document.getElementById('optionsWrapper').style.borderColor='#ff0000';
}

if (document.getElementById('priceCheck').value=='not_selected'){
 msgPrices =  'Pricing options.' ;
 document.getElementById('pricesWrapper').style.borderColor='#ff0000';
} 

if (msgOptions!='' || msgPrices!='' ){
	if (msgOptions !='' &&  msgPrices =='') alert('Please select from the ' + msgOptions)
	if (msgPrices  !='' &&   msgOptions=='') alert('Please select from the ' + msgPrices)
	if (msgPrices  !='' &&   msgOptions !='') alert('Please select from the ' + msgOptions + ' and ' + msgPrices)
	return false;
}

} 

// price options updater from DD
function updatePrices(selectorId,newValue){
var allPriceFields = $$('.PSprices'); 
for (i=0; i < allPriceFields.length; i++) {allPriceFields[i].value='not_selected';}
document.getElementById('priceCheck').value=newValue;
document.getElementById(selectorId).value=newValue;
}
//

// buy check



//images popup
var currentImage=1;
var currentArrayPosition=1;
function showLargeImage(id){
win=window.open('/product-images/' + id + '/' + currentArrayPosition	 + '.htm','details','width=2,height=2');
win.focus();
}

function swapImage(id,imageNum,arrayPosition){
currentImage=imageNum;
currentArrayPosition=arrayPosition; // used to open correct in array
document.getElementById('mainImage').src='xphotos/' + id + '/' + imageNum +'.jpg'
}
//images


// zoom images
function zoomImages(theId,picNum){
if (!picNum) picNum=1;
//new Effect.Opacity( 'mediaContainer',  {duration:0.8, from:0, to:1.0} );
new Ajax.Updater('mediaContainer','media/_detailsZoom.inc.php?id='+theId+'&picNum='+picNum ,{evalScripts:true
 ,onLoading: $('mediaContainer').innerHTML='<div  style="text-align:center;padding-top:60px"><img src="./_ajax/loading1.gif"   /></div>'
})
hideSwatches()
} 

function playVideo(theId){
new Effect.Opacity( 'mediaContainer',  {duration:0.8, from:0, to:1.0} ); 
new Ajax.Updater('mediaContainer','media/_detailsVideo.inc.php?id='+theId ,{evalScripts:true
//,onLoading: $('mediaContainer').innerHTML='<div  style="text-align:center;margin-top:90px"><img src="./_ajax/loading1.gif"   /></div>'
}) 
hideSwatches()
}
// zoom images

var swatchesOn=false;
function showSwatches(theId){ 
new Ajax.Updater('swatchContainer','media/_details_Swatches.inc.php?id='+theId ,{evalScripts:true
,onFinish: new Effect.Opacity( 'swatchContainer',  {duration:0.5, from:0.1, to:1.0} ) 
})
swatchesOn=true;
}

function hideSwatches(){ 
if (swatchesOn==true){ // in case  via image zoom
new Effect.Fade('swatchDIV',{duration:0.7 
})
}//if 
}//eofn

function hoverOver(iconId,iconRoll){
currentImg= ($(iconId).src);
new Effect.Opacity( iconId ,  {duration:0.4, from:0.5, to:1.0} )
 $(iconId).src=iconRoll  
}


function hoverOut(iconId){
new Effect.Opacity( iconId ,  {duration:0.7, from:0.4, to:1.0
,onFinish: ( $(iconId) ).src=currentImg } ) 
} 


showOptionalExtra=function(optProdId){
new Ajax.Updater('ajaxContainer' , 'http://www.bluejigsaw.co.uk/optional-extra-details/' + optProdId + '/view.htm', { 
onLoading:function() {$('ajaxContainer').innerHTML='';} ,
onComplete:function(){ 
new Effect.Appear ('ajaxContainer' , {duration:0.5} ) ;
//if ( $('pricesWrapper')!=null)  $('pricesWrapper').style.visibility='hidden' ; 
//if ( $('optionsWrapper')!=null) $('optionsWrapper').style.visibility='hidden';
}
});
return false;
}

hideOptionalExtra=function(){
//if ( $('pricesWrapper')!=null)  $('pricesWrapper').style.visibility='visible'   ; 
//if ( $('optionsWrapper')!=null)  $('optionsWrapper').style.visibility='visible' ;
new Effect.Fade ('ajaxContainer' , {duration:0.5}) ; 
}


function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

