var curdiv;
var t;
var newwindow;
var submitform = false;
var delay = 3750;
var start_frame = 1;

function init() {
	if($('imgs')) 
	{
		var lis = $('imgs').getElementsByTagName('li');
		
		for( i=0; i < lis.length; i++){
			if(i!=0){
				lis[i].style.display = 'none';
			}
		}
		end_frame = lis.length -1;
		
		start_slideshow(start_frame, end_frame, delay, lis);
	}
	
}



function start_slideshow(start_frame, end_frame, delay, lis) {
	//alert("Rotation Started");
	setTimeout(fadeInOut(start_frame,start_frame,end_frame, delay, lis), delay);
}


function fadeInOut(frame, start_frame, end_frame, delay, lis) {
	return (function() {
		lis = $('imgs').getElementsByTagName('li');
		Effect.Fade(lis[frame]);
		if (frame == end_frame) { frame = start_frame; } else { frame++; }
		lisAppear = lis[frame];
		setTimeout("Effect.Appear(lisAppear);", 0);
		setTimeout(fadeInOut(frame, start_frame, end_frame, delay), delay + 1850);
	})
	
}

function timedCount()
{
	t=setTimeout("stopCount()",2000);
	
}

function stopCount()
{
	clearTimeout(t);
	t = null;
}



function setBGHeight()
{
	var window_width = get_document_window_width();
   	var window_height = get_document_window_height();
	if(document.body.scrollwidth < window.width)
	$('presentationbox').style.width  = window_width +'px';
	else 
	$('presentationbox').style.width = document.body.scrollwidth;
	if(document.body.scrollheight < window.height)
	$('presentationbox').style.height = window_height+'px';
	else 
	$('presentationbox').style.height = document.body.scrollheight;
}

function closePopUpWindow()
{
	if(!submitform)
		opener.location.href='http://www.westerndental.com';
}


function openPaymentForm() 
{	
	if(newwindow) newwindow.close();
	
	var divwidth = 800;
	var divheight =600;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
		
	newwindow = window.open ('https://www.westerndental.com/online-payment/index.php?cmd=popup', 'pg',"menubar=0,resizable=0,scrollbars=1,screenX="+left+",screenY="+top+",left="+left+",top="+top+",width="+divwidth+",height="+divheight);
	newwindow.focus();
}

function openFormDialog(f) 
{	
	var divwidth  = 955;
	var divheight = 600;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	
		$('formframe').src = f;
		$('patientforms').style.top = top+'px';
		$('patientforms').style.left = left+'px';
	
		elementAppear('formbox');
}

function showVideo(f) 
{	
	var divwidth  = 320;
	var divheight = 280;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	
		//$('formframe').src = f;
		$('commercialstext').style.paddingTop = '10px';
		//$('commercialdiv').style.left = left+'px';
	
	//$('commercialbox').style.display = '';
	//elementAppear('commercialdiv');
	$('commercials').className = ''; 
	$('commercials').innerHTML = AC_FL_PreloadContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','320','height','280','movie','videos/37-flvplayer?video='+f+'&statevolume=50&autoplay=true','quality','high','allowfullscreen','false' );
}

function hideVideo() 
{	
	
	elementFade('commercialdiv');
	$('commercialholder').innerHTML = '';
	$('commercialbox').style.display = 'none';
		$('commercialstext').style.paddingTop = '30px';
}

function switchPayment(value) 
{
	current = $(value+'li');
	
	if(value == 'credit' || value == '')
		$('checkli').style.display = 'none';
	
	if(value == 'check' || value == '')
		$('creditli').style.display = 'none';
		
	if(value != '')
		current.style.display = '';
}

function swap_cvv_image(value)
{
	if(value!='')
	{
		new_src="/images/online-payment/"+value+'.jpg';
		$('card_img').src = new_src;
	}else
		$('card_img').src = "spacer.gif";
}

function switchDesc(divid)
{
	if(t == null)
	{
		if(curdiv == divid)
		{
			
		}
		else
		{
			if(curdiv != null)
			{	
				if($(curdiv).style.display != "none")
				{
					timedCount();
					elementFade(curdiv);
					elementAppear(divid);
				}
			}
			else
			{
					curdiv = "samh";
					
				if($(curdiv).style.display != "none")
				{
					timedCount();
					elementFade(curdiv);
					elementAppear(divid);
				}
			}
			curdiv = divid;
		}
	}
}

function switchdiv(divid)
{
	if(t == null)
	{
		if(curdiv == divid)
		{
			
		}
		else
		{
			if(curdiv != null)
			{	
				if($(curdiv+"text").style.display != "none")
				{
					timedCount();

					elementFade(curdiv+"text");
					elementAppear(divid+"text");
					
					if($('commercials') && curdiv == 'commercials' )
					{
						$('commercials').innerHTML = '<img width="285" height="234" alt="" src="images/large_img/commercials.jpg" />';
						$('commercials').className = 'headingimg';
						$('commercialstext').style.paddingTop = '30px';
					}
				}
			}
			else
			{
				if($("familytext"))
					curdiv = "family";
				else if($("familycatext"))
					curdiv = "familyca";
				else if($("easycredit2text"))
					curdiv = "easycredit2";
				else if($("relationstext"))
					curdiv = "relations";
				else if($("orthotext"))
					curdiv = "ortho";
				else if($("dentisttext"))
					curdiv = "dentist";
				else if($("aboutustext"))
					curdiv = "aboutus";
				else if($("pressatext"))
					curdiv = "pressa";
				else if($("contactatext"))
					curdiv = "contacta";
					
				if($(curdiv+"image").style.display != "none")
				{
					timedCount();
					elementFade(curdiv+"image");
					elementAppear(divid+"text");
				}
				else
				{
					timedCount();
					elementFade(curdiv+"text");
					elementAppear(divid+"text");
				}
			}
			curdiv = divid;
		}
	}
}

function verifyAmount()
{
	pa = $('paymentamount');
	va = $('verifypayment');
	//er = $('paymenterror');
	
	if((pa.value != va.value))
	{
		pa.className = 'errorinput';
		va.className = 'errorinput';
		//er.style.display ='';
	}
	else
	{
		pa.className = 'input';
		va.className = 'input';
		//er.style.display ='none';
	}
}

function get_document_window_height()
{
   if (document.body && document.body.clientHeight &&
       (document.body.clientHeight > 1)) return document.body.clientHeight;
   else if (window && window.innerHeight) return window.innerHeight;
   else if (document.documentElement && document.documentElement.offsetHeight)
      return document.documentElement.offsetHeight;
   else if (document.body && document.body.offsetHeight)
      return document.body.offsetHeight;
   return 0;
}

function get_document_window_width()
{
   if (document.body && document.body.clientWidth)
      return document.body.clientWidth;
   else if (window && window.innerWidth) return window.innerWidth;
   else if (document.documentElement && document.documentElement.offsetWidth)
      return document.documentElement.offsetWidth;
   else if (document.body && document.body.offsetWidth)
      return document.body.offsetWidth;
   return 0;
}

function convert_width(width,window_width)
{
   if (width == null) width = page_width + 52;
   else if (typeof(width) == 'string') {
      var percent_pos = width.indexOf('%');
      if (percent_pos != -1)
         width = window_width * (width.substr(0,percent_pos) / 100);
   }
   if (! document.all) {
      if (width > (window_width - 25)) width = window_width - 25;
   }
   else if (width > (window_width - 10)) width = window_width - 10;
   return width;
}

function convert_height(height,window_height)
{
   if (height == null) height = window_height;
   else if (typeof(height) == 'string') {
      var percent_pos = height.indexOf('%');
      if (percent_pos != -1)
         height = window_height * (height.substr(0,percent_pos) / 100);
   }
//   else height += header_offset;
   if (height > (window_height - 40)) height = window_height - 40;
   return height;
}

function calculate_left(width,window_width)
{
   var left = (window_width - width) / 2;
   if (! document.all) left += 10;
   if (left < 0) left = 0;
   return left;
}

function calculate_top(height,window_height)
{
   var top = ((window_height - height) / 2) - 3;
   if (top < 0) top = 0;
   return top;
}

function checkQuery()
{
	var parameters = document.location.search;  
    var options = new Array();  
    var num_options = 0;  
    var start_pos = parameters.indexOf('?');  
    if (start_pos != -1) do {  
         start_pos += 1;  
         var end_pos = parameters.indexOf('&',start_pos);  
         if (end_pos == -1) options[num_options++] = parameters.substring(start_pos);  
         else options[num_options++] = parameters.substring(start_pos,end_pos);  
         if (end_pos == -1) start_pos = -1;  
         else start_pos = end_pos;  
      }  
      while (start_pos != -1);  
      for (var loop = 0;  loop < num_options;  loop++) {  
         if (options[loop] == "popup") popup = true;  
         if (options[loop].substring(0,4) == "load") {  
            var equal_pos = options[loop].indexOf('=');  
            if (equal_pos != -1) load_option = options[loop].substring(equal_pos + 1);  
         }  
      }   
}