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 timedCountDiv()
{
	t=setTimeout("stopCount()",2);	
}

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";
				else if($("AddFamilytext"))
					curdiv = "AddFamily";
					
				if(curdiv=="ortho")
				{
				    if(document.getElementById('AddFamilytext')!=null)
				    {
				        document.getElementById('AddFamilytext').style.display="none";
				    }
				    if(document.getElementById('pagecontentblue_New')!=null)
				    {
				        document.getElementById('pagecontentblue_New').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				    else if(document.getElementById('pagecontentblue_New_01')!=null)
				    {
				        document.getElementById('pagecontentblue_New_01').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				    else if(document.getElementById('pagecontentblue_New_02')!=null)
				    {
				        document.getElementById('pagecontentblue_New_02').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_03')!=null)
				    {
				        document.getElementById('pagecontentblue_New_03').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_04')!=null)
				    {
				        document.getElementById('pagecontentblue_New_04').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_05')!=null)
				    {
				        document.getElementById('pagecontentblue_New_05').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_06')!=null)
				    {
				        document.getElementById('pagecontentblue_New_06').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_07')!=null)
				    {
				        document.getElementById('pagecontentblue_New_07').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				     else if(document.getElementById('pagecontentblue_New_08')!=null)
				    {
				        document.getElementById('pagecontentblue_New_08').style.display="none";
					    elementAppear('pagecontentblue');
				    }
				}			 
				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);  
         }  
      }   
}

function zipValidate(zip,msg,msg1)
{
    var zip1=document.getElementById(zip);
    
    if(zip1.value=="")
    {
       alert(msg);       
       return false;
    }
   if(zip1.value.length < 5)
   {
       alert(msg1);       
       return false;
   } 
    return true;

}









function isPhoneKey(evt)
     {
         var charCode = (evt.which) ? evt.which : evt.keyCode;
         if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=45) && (charCode!=40) && (charCode!=41))
            return false;
         return true;
      }
      
function isZipKey1(evt)
{
      var charCode = (evt.which) ? evt.which : evt.keyCode;
         //if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=45))//Allow "-" to enter
          //if (charCode > 31 && (charCode < 48 || charCode > 57))//Not Allow "-" to enter
      if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
            return false;
           
         return true;
}

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}


 function isPoint(txtzip)
      {
        var delpoint = document.getElementById(txtzip).value;
       // var a = delpoint.length;
       if(delpoint.lastIndexOf(".")!="-1")
         {
            var delpoint1 = delpoint.split(".");
            document.getElementById(txtzip).value = delpoint1[0];
         }
        
        
      }
      
function validate1(address,city,state,zip)
{       
        var address1=document.getElementById(address);
        if(address1.value == "")
        {
            alert("Please enter address."); 
            address1.focus();   
            return false;
        }
        else
        {
            if (!isNaN(address1.value) ) 
            {
                 alert('Invalid address'); 
                 address1.value = ""; 
                 address1.focus();
                 return false;
            } 
            if(!CheckSQLInjection1(address))
            {
                return false;
            }
        }
       
        var city1=document.getElementById(city);
        if(city1.value == "")
        {
            alert("Please enter city."); 
            city1.focus();   
            return false;
        }
        else
        {
            if (!isNaN(city1.value) ) 
            {
                 alert('Invalid city name'); 
                 city1.value = ""; 
                 city1.focus();
                 return false;
            } 
            if(!CheckSQLInjection1(city))
            {
                return false;
            }
        }
        //var state1=document.getElementById(state);
        if( document.getElementById(state).selectedIndex == 0)
        {
        alert("Please select state.");    
        return false;
        }
        
        var zip1=document.getElementById(zip);
        if(zip1.value == "")
        {
            alert("Please enter zip code.");  
            zip1.focus();  
            return false;
        }
       
        else
        {   
            var str=document.getElementById(zip).value;                   
            if(zip1.value.length < 5)
            {
               alert("Invalid zip code");
                zip1.focus();         
               return false;
            }             
            else if(str.indexOf('-') != -1)           
            {
                if(str.indexOf('-') < 5)
                {
                    alert("Invalid zip code"); 
                    zip1.focus();        
                    return false;
                }         
                
            }
        }
        return true;       
       

}
function CheckBlank(fname,lname,dob,btnnext)
{

    var b=true;
 var fname1=document.getElementById(fname);
 if(fname1.value == "")
 {
    alert("Please enter first name."); 
    fname1.focus();   
    b =false;
    return false;
 }
 else 
 {
  if (!isNaN(fname1.value) ) 
    {
             alert('Invalid first name'); 
             fname1.value = ""; 
             fname1.focus();
             b =false;
             return false;
    }
 } 
 var lname1=document.getElementById(lname);
 if(lname1.value == "")
 {
     alert("Please enter last name");
     lname1.focus();  
     b =false;  
     return false;
 }
 else
 {
 if(!isNaN(lname1.value))
        {  
            alert('Invalid last name'); 
             lname1.value = ""; 
             lname1.focus();
             b =false;
             return false;
        }
 }
 
 var dob1=document.getElementById(dob);
 if(dob1.value == "")
 {
    alert("Please enter birthdate");
     dob1.focus();    
     b =false; 
    return false;
 }
 else if(dob1.value.length!=10)
 {
    alert("please enter valid date in format of MM-DD-YYYY or MM/DD/YYYY");
    b =false;
    return false;
 }
 else
 { 
    if(!CheckValidDateNewToDay(dob))
    {   
      dob1.focus();     
      b =false;
      return false;
    }
    
 }
   if(b==true)
    { 
        if(btnnext == "Yes")
        {   
            return showDialog('block');
            return true;
        }
        else(btnnext == "Yes")
        {   
            return true;
        }
    }
    else
    {
        return false;
    }
}

    

//function CheckBlank(fname,lname,dob)
//{
// var fname1=document.getElementById(fname);
// if(fname1.value == "")
// {
//    alert("Please enter first name.");   
//    fname1.focus(); 
//    return false;
// }
// 
// var lname1=document.getElementById(lname);
// if(lname1.value == "")
// {
//    alert("Please enter last name");    
//    lname1.focus();
//    return false;
// }
// 
// var age1=document.getElementById(dob);
// if(age1.value == "")
// {
//    alert("Please enter Birthday");    
//    age1.focus();
//    return false;
// }
// return true;
//}


function fixZip(fld,defaultAreaCode,sep,noext)
{ // tenacious phone # correction 

  if(!document.getElementById(fld).value.length||document.getElementById(fld).disabled) return true; // blank fields are the domain of requireValue 
  
  if(typeof(sep)=='undefined') sep= '-';
  
  if(typeof(defaultAreaCode)!='undefined') defaultAreaCode= defaultAreaCode + sep;
  
  var ext= '', val= document.getElementById(fld).value.toLowerCase();
   
  if(val.indexOf('x') > 0)
  {
    if(!noext) 
    ext= 'x'+val.substr(val.indexOf('x')).replace(/\D/g,'');
    val1= val.substr(val.lastIndexOf('x')+1,val.length);
    if(val1.length>5)
    {
    alert('Please enter zip code extensions upto 5 digits');
    document.getElementById(fld).value = "";
    }
    val= val.substr(0,val.indexOf('x'));
   
  }
  
  val= val.replace(/\D/g,'');
  
  if(val.length >= 6)
  { 
   document.getElementById(fld).value= val.substring(0,5) + sep + val.substring(5,20) + ext;    
   //   fld.focus();
   
    return true;
  } 
 
}

function google_analytics()
{
 
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-6031018-4']);
  _gaq.push(['_trackPageview']);

  (function() 
  {
    var ga = document.createElement('script'); 
    ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
  } )();
}




