var innerHTMLForm;
	
function CloseBlock(mod_container,mod_fromdiv){
	var mod_container = document.getElementById(mod_container);	
	var mod_fromdiv = document.getElementById(mod_fromdiv);		
	if(innerHTMLForm) mod_fromdiv.innerHTML = innerHTMLForm ;
	mod_container.style.display="none";	
	mod_fromdiv.style.display="none";
	Continue();
}
		
function ShowBlock(mod_container,mod_fromdiv){
	Stop();
	var mod_container = document.getElementById(mod_container);	
	var mod_fromdiv = document.getElementById(mod_fromdiv);		              
    innerHTMLForm = mod_fromdiv.innerHTML;
	mod_container.style.display="block";	
	mod_fromdiv.style.display="block";	
	mod_fromdiv.style.top = Math.max((document.documentElement.clientHeight/2) + document.documentElement.scrollTop - (mod_fromdiv.offsetHeight/2),0) + 'px';
	mod_fromdiv.style.left = Math.max((document.documentElement.clientWidth/2) + document.documentElement.scrollLeft - (mod_fromdiv.offsetWidth/2),0) + 'px';
}
		
function SendSubscribeEmail(){
	var container = document.getElementById('SubscribeBlockError');
	var EmailBlock = document.getElementById('SubscribeBlockinnerDIV');
	var SubscribeBlockfrm = document.getElementById('SubscribeBlockfrm');

	try{	

		var yourname = document.getElementById('yourname');	
		var youremail = document.getElementById('youremail');	
		var question = document.getElementById('question');
		var answer = document.getElementById('answer');
	
		yourname = yourname?yourname.value:'';
		youremail = youremail?youremail.value:'';
		answer = answer?answer.value:'';	
		question = question?question.value:'';
						
	    ErrorMsg = '';
	    
		non_blank('SubscribeBlockfrm','yourname','Please supply your Name.')
		valid_email('SubscribeBlockfrm','youremail','Please supply your Email Address.',true);
		non_blank('SubscribeBlockfrm','answer','Please prove that you\'re not a computer.');
		if(ErrorMsg == ''){
			var questionanswer = agent.call('/ajax/CMBase.ajax.php','checkCaptchaCom','',question,answer);
			if(questionanswer != true) {
				ErrorMsg += '\r\n - Please prove that you\'re not a computer.';
			}
	    }
	    			 
		if(ErrorMsg==''){
			container.innerHTML='<div style="width: 180px; margin-bottom: 7px;">Sending request...</div>';
			var res =agent.call('/ajax/CMBase.ajax.php','addSubscription','',yourname,youremail);
	        
			if(res == 0) return EmailBlock.innerHTML='<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SubscribeBlockinnerDIV\');"><img src="../../images/closediv.gif"/></a></div><form id="SubscribeBlockfrm" name="SubscribeBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0" class="SubscribeblockTable"><tr><td colspan="2" class="SubscribeBlockHeader"><img src="../images/subscribe-image.gif" /></td></tr><tr><td class="SubscribeBlockLabel" nowrap style="text-align:left;">Thank you for subscribing to the White Nights newsletter. <br/>An email has been sent to you to confirm your subscription.</td></tr></table></form>';
			
			else return EmailBlock.innerHTML= '<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SubscribeBlockinnerDIV\');"><img src="../../images/closediv.gif"/></a></div><form id="SubscribeBlockfrm" name="SubscribeBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0" class="SubscribeblockTable"><tr><td colspan="2" class="SubscribeBlockHeader"><img src="../images/subscribe-image.gif" /></td></tr><tr><td class="SubscribeBlockLabel" nowrap style="text-align:left;">'+res+'<br />To report this error please click <a href="mailto:christa@whitenights.co.za?subject=Newsletter+sign-up+error">here</a>.</td></tr></table></form>';
		}
		else return alert(ErrorMsg);
	}
	catch(e){	
		EmailBlock.innerHTML = '<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SubscribeBlockinnerDIV\');"><img src="../../images/closediv.gif"/></a></div><form id="SubscribeBlockfrm" name="SubscribeBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0" class="SubscribeblockTable"><tr><td colspan="2" class="SubscribeBlockHeader"><img src="../images/subscribe-image.gif" /></td></tr><tr><td class="SubscribeBlockLabel" nowrap style="text-align:left;">There was an error sending your subscription.<br />' + e +'</td></tr></table></form>';
	}
}

function SendEnquiryEmail(){
try{
        var SendEnquiryBlockinnerDIV = document.getElementById('SendEnquiryBlockinnerDIV');
	    var SendEnquiryBlockfrm = document.getElementById('SendEnquiryBlockfrm');
	    
	    var yourname = document.getElementById('yournameEnquiry');	
		var youremail = document.getElementById('youremailEnquiry');	
		var phone = document.getElementById('phone');
		var enquiry = document.getElementById('enquiry');
	    var selectstyle = document.getElementById('selectstyleEnquiry');
	    var selectstyle = selectstyle[selectstyle.selectedIndex].value;
	    var question = document.getElementById('Enquiryquestion');
		var answer = document.getElementById('answerEnquiry');
			    
		yourname = yourname?yourname.value:'';
		youremail = youremail?youremail.value:'';
		phone = phone?phone.value:'';	
		enquiry = enquiry?enquiry.value:'';		
		answer = answer?answer.value:'';	
		question = question?question.value:'';
	
	    ErrorMsg = '';
	    
		non_blank('SendEnquiryBlockfrm','yournameEnquiry','Please supply your Name.');
		non_blank('SendEnquiryBlockfrm','phone','Please supply your Phone Number.');
		valid_email('SendEnquiryBlockfrm','youremailEnquiry','Please supply your Email Address.',true);	
		non_blank('SendEnquiryBlockfrm','enquiry','Please supply your Enquiry.');
		non_blank('SendEnquiryBlockfrm','answerEnquiry','Please prove that you\'re not a computer.');  
		if(selectstyle=='') ErrorMsg += ' -  Please supply your Selection.\r\n';
		if(ErrorMsg == ''){
			var questionanswer = agent.call('/ajax/CMBase.ajax.php','checkCaptchaCom','',question,answer);
			if(questionanswer != true) {
				ErrorMsg = '\r\n - Please prove that you\'re not a computer.';
			}
		}
	    
		
			 
		if(ErrorMsg==''){		
		    
			SendEnquiryBlockinnerDIV.innerHTML = '<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SendEnquiryBlockinnerDIV\',\'contactOver\');"><img src="../../images/closediv.gif" /></a></div><form id="SendEnquiryBlockfrm" name="SendEnquiryBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="5" class="SubscribeBlockHeader"><img src="../images/send-enquiry-image.gif" /></td></tr><tr><td class="SubscribeBlockLabel" nowrap style="text-align:left;">Sending Enquiry...</td></tr></table></form>';
			var EmailBlock = agent.call('/ajax/CMBase.ajax.php','SendEnquiry','',yourname,youremail,enquiry,selectstyle);
			
			 SendEnquiryBlockinnerDIV.innerHTML = '<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SendEnquiryBlockinnerDIV\',\'contactOver\');"><img src="../../images/closediv.gif" /></a></div><form id="SendEnquiryBlockfrm" name="SendEnquiryBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="5" class="SubscribeBlockHeader"><img src="../images/send-enquiry-image.gif" /></td></tr><tr><td class="EnquiryBlockLabel" nowrap style="text-align:left;">'+EmailBlock+'</td></tr></table></form>';
		}else{
			alert('There were problems sending this form:\r\n' + ErrorMsg);
		}
    }
	catch(e){	
	    
		SendEnquiryBlockinnerDIV.innerHTML = '<div class="closeimg"><a onclick="javascript:CloseBlock(\'contactOverlay\',\'SendEnquiryBlockinnerDIV\',\'contactOver\');"><img src="../../images/closediv.gif" /></a></div><form id="SendEnquiryBlockfrm" name="SendEnquiryBlockfrm" action=""><table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="5" class="SubscribeBlockHeader"><img src="../images/send-enquiry-image.gif" /></td></tr><tr><td class="SubscribeBlockLabel" nowrap style="text-align:left;">' + e + '</td></tr></table></form>';
	}
}

function ShowStyle(styleid,thislink){
	Stop();
	currentstyle = styleid;
	var style = styles[styleid];
	// show loading image...
	var fullimage = document.getElementById('img_fullview');
	var loadingdiv = document.getElementById('img_loading');
	var containerdiv = document.getElementById('DrawImagesGallery');
	containerdiv.style.backgroundImage = "";
	fullimage.src = 'images/spacer.gif';
	loadingdiv.style.display = 'block';
	loadingdiv.style.top = fullimage.offsetTop + 'px';
	loadingdiv.style.left = fullimage.offsetLeft + 'px';
	
	// set thislink style
	if(thislink != null){	
		var divz = document.getElementsByTagName('a');
		for(var i=0;i<divz.length;i++){
			if(divz[i].parentNode.className=="styleListSelected"){
				 divz[i].parentNode.className = 'styleList';							
			}
		}		
		thislink.parentNode.className = 'styleListSelected';
		Cufon.refresh();	
	}
	
	// set large image details
	var stylename = document.getElementById('bigStyleName');
	var styledescription = document.getElementById('bigStyleDescription');
	var stylewashing = document.getElementById('bigStyleWashing');
	stylename.innerHTML = style.name;
	styledescription.innerHTML = style.description;
	stylewashing.innerHTML = style.washing_instructions;
	
	Start();	
}

function Show(){
	if(!suspendshow){
		var style = styles[currentstyle];
		if(currentfile == style.filecount){
			currentfile = 0;	
		}			
		 
		var nextImage = 'gallery/images/'+currentstyle+'/'+currentstyle+'_'+currentfile+'.jpg';
		
		GalleryShowImage.show(currentstyle,nextImage);
		currentfile += 1;
		Cufon.refresh();
	}
}

function Stop(){
	clearTimeout(intervalhandle);
	suspendshow = true;
}

function Start(){
	suspendshow = false;
	currentfile = 0;
	Show();
}

function Continue(){
	suspendshow = false;
	Show();
}

function StartTimer(){
	clearTimeout(intervalhandle);
	intervalhandle = setTimeout('Show();',6000);
}
	
function viewBigimg(mod_container,big_view_div,id){
	Stop();
    var overlay = document.getElementById('contactOverlay');	
	var big_view_div = document.getElementById('bigViewDIV');
	var big_img = document.getElementById('img_bigview');
	overlay.style.display="block";	
	big_view_div.style.display="block";
	big_view_div.style.top = Math.max((document.documentElement.clientHeight/2) + document.documentElement.scrollTop - (big_view_div.offsetHeight/2),0) + 'px';
	big_view_div.style.left = Math.max((document.documentElement.clientWidth/2) + document.documentElement.scrollLeft - (big_view_div.offsetWidth/2),0) + 'px';
	big_img.src = '/images/loading.gif';
	big_img.src = '/gallery/images/' + currentstyle + '/big_images/' + currentstyle + '_' + (currentfile==0?styles[currentstyle].filecount-1:currentfile-1) + '.jpg' ;
}	
	
function SizingChart(){
    Stop();
    var home_content = document.getElementById('home_content');
    home_content.style.display = "none";
    var s_container = document.getElementById('size_container');
    s_container.style.display = "block";
	Cufon.refresh(); // Why is this included?
}
function SizingVideo(){
    Stop();
    var home_content = document.getElementById('home_content');
    home_content.style.display = "none";
    var v_container = document.getElementById('video_container');
    v_container.style.display = "block";
	FlashVideo_ShowVideo("Video_Player");
}

function ViewHome(){
    currentfile = 0;
    var v_container = document.getElementById('video_container');
    v_container.style.display = "none";
    var v_div = document.getElementById('FlashVideo_player_Video_Player');
    v_div.innerHTML = "";
    var s_container = document.getElementById('size_container');
    s_container.style.display = "none";
    var home_content = document.getElementById('home_content');
    home_content.style.display = "block";
    Start();
}
