var utilVars={projName:'videopharmacy'}, psWWWrsid;

var jQ,ttVars={};
jQuery.noConflict();jQ=jQuery;

if(jQ.browser.msie && jQ.browser.version<7){try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}}

jQ(document).ready(function(){
	pageOnLoad();
});




function pageOnLoad(){
	
	/* --- common --- */
	  
	  jQ('.search-block form ').submit(function(){
        var inp=this.search;
        if(jQ.trim(inp.value)==inp.defaultValue || jQ.trim(inp.value)=='' ) return false;
    }).find('input')
        .focus(function(){ if(this.value==this.defaultValue)this.value=''; })
        .blur( function(){ if(this.value=='')this.value=this.defaultValue; }); 


	  jQ('div.commitment2  ').submit(function(){
        var inp=this.search;
        if(jQ.trim(inp.value)==inp.defaultValue || jQ.trim(inp.value)=='' ) return false;
    }).find('input')
        .focus(function(){ if(this.value==this.defaultValue)this.value=''; })
        .blur( function(){ if(this.value=='')this.value=this.defaultValue; }); 
	
	jQ('a.edit').click(function(){window.open(this.href,'edit','toolbar=0');return false;});
	jQ('.quicksearch a').click(function(){
		document.location.href=document.location.protocol+'//'+document.location.host+'/?search='+jQ('#search').val();
		return false;
	});
	jQ('.quicksearch input').click(function(){
		if(this.value==this.defaultValue)this.value=""}
	).blur(function(){
		if(this.value=="")this.value=this.defaultValue}
	);
	//jQ('form tfoot').find('a','button').click(fn_submit);
	jQ('a.bookmark').click(makeBookmark);
	jQ('#reload_vcode_img').click(function(){
		var i=jQ('#vcode_img');
		v.attr('src',v.attr('src')+'?');
		return false;
	});
	
	var crt=jQ('.cart');
	if(crt.length){
		crt.find('.checkout').click(function(){try{document.checkout.submit();}catch(ex){};return false});
		crt.find('.update').click(function(){try{document.cart.submit();}catch(ex){};return false});
		crt.find('.continue').click(function(){document.location.pathname='/';return false});
		//crt.find('img.photo').click(function(){return popImg('imgs/pills/blisters/'+jQ(this).attr('prod')+'.jpg');});
		
	}

	var crt=jQ('.product');

	
	/* --- site specific --- */
	
	jQ('#big_pic img').mouseover(function(){ jQ('#big_pic').css('background-image','url(imgs/'+this.id+'.jpg)') });
	var prod=jQ('table.prod');
	if(prod.length){
		prod.each(function(i,el){
			var u=jQ(el).find('.add-inf a').attr('href');
			jQ(el).find('h3, img').click(function(){location=u;});
		});
	}
	


    jQ("#phone2").live('paste', function() {
      	return false;
    });

    jQ("#phone2").live('keyup', function() {
		jQ("#phone2").css("background-color","#a9ffa2");
    });
    
    swfobject.embedSWF("out/?id=we_accept_banner", "flashWeaccept", "230", "40", "8",null,null,{scale:'noscale',wmode:'transparent',salign:'l'});
 /**********************************************************/
 	//if(jQ('#radio3').attr('checked')){jQ('tr.deliv-calc').css({display:'table-row'});} else {jQ('tr.deliv-calc').css({display:'none'});}
	jQ('tr.table_bg3').click(function(){
		jQ('.table_bg3 input[type="radio"][name="shipping_method_id"]').removeAttr('checked');
		jQ(this).children('td').children('input[type="radio"][name="shipping_method_id"]').attr('checked', 'checked');
		jQ('#cart').submit();
	});
	jQ('input[type="text"]').focus(function(){if(jQ(this).val()==this.defaultValue){jQ(this).val('');} else {jQ(this).select();}});
	jQ('input[type="text"]').blur(function(){if(jQ(this).val()==''){jQ(this).val(this.defaultValue);}});
	jQ('textarea').focus(function(){if(jQ(this).val()==this.defaultValue){jQ(this).val('');} else {jQ(this).select();}});
	jQ('textarea').blur(function(){if(jQ(this).val()==''){jQ(this).val(this.defaultValue);}});
	jQ('tr.table_bg3 a.tb').click(function(){jQ('tr.deliv-calc').toggle(); return false;});
	
	//freeship
	var flag_fade = false;
	jQ('.freeship').mouseenter(function(){ if(!flag_fade){ flag_fade=true;  jQ(this).children('.freeship-descr').fadeIn('fast', function(){flag_fade=false;});} });
	jQ('.freeship').mouseleave(function(){ jQ(this).children('.freeship-descr').fadeOut('fast'); });
	
 /**********************************************************/
}


/* --- common utils --- */

function openSupportWindow(){ showWindow('support_window','out/?id=live_support_url',500,560); }
function showCertificate(u){
	u=u||'out/?id=certificates_url';
	showWindow('cert_window',u,500,350);
}
function showSpecialOffer(u){
	u=u||'out/?id=special_offer_url';
	showWindow('spo_window',u,620,620);
}
function showWindow(id,u,w,h){
	if(!utilVars[id] || utilVars[id].closed){
		utilVars[id]=popItUp(u,id,w,h);
	}
	utilVars[id].focus();
}
function popItUp(u,n,w,h){
	var l=(screen.availWidth  - w) / 2, t=(screen.availHeight - h) / 2
	,op='toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',left='+l+',top='+t
	,n=n||'_blank';
	return window.open(u,n,op);
}
function reloadImageCode(el){
	var img=document.getElementById('vcode_img');
	if(!utilVars.imgCodeUrl) utilVars.imgCodeUrl=img.src;
	img.src=utilVars.imgCodeUrl+'?'+Math.random();
}

function makeBookmark(){
	var host=document.location.host,
	u='http://'+host+'/';
	try{
		if (window.sidebar){
		window.sidebar.addPanel(this.title, u, '');
		}else if(document.all){
		window.external.AddFavorite(u, this.title);

		}
	}catch(ex){alert(ex.message)}
	return false;
}

/* --------------- */

function popImg(){
	var u='imgs/pills/blisters/'+jQ(this).attr('prod')+'.jpg';
	var h='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
	+'<head><title></title>'
	+'<style>html,body,table{margin:0;padding:0;height:100%;width:100%;text-align:center}</style>'
	+'</head><body onclick="close();"><table><tr><td><img src="'+u+'" /></td></tr></table></body></html>';
	var wnd=popItUp('about:blank','img_window',520,520);
	wnd.document.write(h);
	wnd.focus();
	return false;
}

function showhide(el, speed) {
    if ( jQ(el).css("display") == 'none'  ){
       
       jQ(el).fadeIn(speed);
       
    }else{
        jQ(el).fadeOut(speed);
      }  
}



function loadTime(){


var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("answer").innerHTML=xmlhttp.responseText;
    }
  }
  document.getElementById("answer").innerHTML='Loading...';
xmlhttp.open("POST","delivery.php?zip="+document.getElementById('text_delivery').value,true);
xmlhttp.send();

}
function showLiveSupport(){popItUp('/out/?id=live_support_url',620,620)}



