/* this function (throbber_img) is important for uc_cart*/
function throbber_img(){
  var loc = new Array();
  loc = location.href.split('/');
return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='"+loc[0]+"//"+loc[2]+"/sites/all/themes/pexuniverse_new/images/throbber.gif'>";
}
var throbber = throbber_img();

function center_any_dialog_block(thisid){

//var tmp_id = '#'+thisid;
var id_pw = $(thisid);
//var id_pw = document.getElementById(thisid);

		var pwinH = id_pw.height();
		var pwinW = id_pw.width();
      
     var newleft = Math.round(($(window).width() - pwinW) / 2,0); 
     var newtop = Math.round(($(window).height() - pwinH) / 2,0);


		//Set the popup window to center
		id_pw.css('top',  newtop);
		id_pw.css('left', newleft);
		
}



function cart_sign_in_user(tosend,fromact){
    if(document.getElementById('wrongname_msg')!=null) document.getElementById('wrongname_msg').style.display = 'none';
	//document.getElementById('userexists_msg').style.display = 'none';
	
	if(fromact=='sign_in') {
	    document.getElementById('wrongname_msg').className = 'in_stock'; 
	    document.getElementById('wrongname_msg').style.display = 'inline';
	    document.getElementById('wrongname_msg').innerHTML = throbber;
    }
	if(fromact=='new_email') {
	    document.getElementById('userexists_msg').className = 'in_stock';
	    //document.getElementById('userexists_msg').style.display = 'inline';
	    document.getElementById('userexists_msg').innerHTML = throbber;
    }
	
	    if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
 			self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
		
		var reqpath = '/cart_sign_in_user';
		if(fromact=='forgot_email') reqpath = '/cart_forgot_email';
		
			self.xmlHttpReq.open('POST', reqpath, true);
			self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            self.xmlHttpReq.send(tosend);
            self.xmlHttpReq.onreadystatechange = function() {
			if (self.xmlHttpReq.readyState == 4) {
			          eval(self.xmlHttpReq.responseText);
					   if(!op_si){
                            if(msg==1){
							   window.location.reload();
							}
							if(msg==2){
							   document.getElementById('wrongname_msg').className = 'wrongname-msg';
							   document.getElementById('wrongname_msg').innerHTML = msg_cnt;
							   document.getElementById('wrongname_msg').style.display = 'inline';
							}
							if(msg==3){
							   document.getElementById('userexists_msg').className = 'ziperr';
							   document.getElementById('userexists_msg').innerHTML = msg_cnt;
							   //document.getElementById('userexists_msg').style.display = 'inline';
							}	
							if(msg==4){
							   document.getElementById('userexists_msg').innerHTML = msg_cnt;
							   //document.getElementById('userexists_msg').style.display = 'inline';
							}		
							if(msg==5){
                                  if(submsg=='yes'){
								    document.getElementById('forgot_msg_th').style.display = 'none';
								    document.getElementById('forgot_msg_1').style.display = 'none';
									document.getElementById('forgot_msg_2').style.display = 'none';
								    document.getElementById('forgot_msg_3').style.display = 'inline';
									document.getElementById('forgot_email_field_1').style.display = 'none';
									document.getElementById('forgot_email_field_2').style.display = 'none';
									//alert(mailres);
								  }
                                  if(submsg=='no'){
								    document.getElementById('forgot_msg_th').style.display = 'none';
								    document.getElementById('forgot_msg_1').style.display = 'none';
									document.getElementById('forgot_msg_3').style.display = 'none';
								    document.getElementById('forgot_msg_2').style.display = 'inline';
									document.getElementById('forgot_send_button').src = '/sites/all/themes/pexuniverse_new/images/send_try.png';
								  }								  
							}								
						}
						else alert('Sorry. Unknown Error Appeared. \n\nPlease contact us if you have questions.');
   			     }
			}	


}


  var send_try_pic = new Image();
  send_try_pic.src = '/sites/all/themes/pexuniverse_new/images/send_try.png';
function cart_forgot_password(act){

  center_any_dialog_block('#password_notify');

  var selObj = document.getElementById('password_notify');
  if(act=='hide') selObj.style.display = 'none';
  document.getElementById('forgot_msg_1').style.display = 'inline';
  document.getElementById('forgot_email_field_1').style.display = 'inline';
  document.getElementById('forgot_email_field_2').style.display = 'inline';
  document.getElementById('forgot_msg_2').style.display = 'none';
  document.getElementById('forgot_msg_3').style.display = 'none';
  document.getElementById('forgot_msg_th').style.display = 'none';
  //var mx = event.clientX;
  //var my = event.clientY-180;
  //var mosey = document.documentElement.scrollTop;
  //var mosey = e.pageY;
  //selObj.style.top = mosey + 'px';
  //selObj.style.top = my + 'px';
 // selObj.style.left = mx = 'px';
  if(act=='hide') selObj.style.display = 'none';
  else selObj.style.display = 'inline';
}



function cart_forgot_password_send(){
  var patt = /^([a-zA-Z0-9_.\-])+@(([a-zA-Z0-9-])+.)+(.[a-zA-Z0-9]{2,4})+$/;
  var forgot_em = document.getElementById('forgoten_email').value;
  document.getElementById('forgot_msg_3').style.display = 'none';
  document.getElementById('forgot_msg_2').style.display = 'none';
  document.getElementById('forgot_msg_1').style.display = 'none';
  if(forgot_em.match(patt)){
    var tmpim = throbber;
	document.getElementById('forgot_msg_th').style.display = 'inline';
    document.getElementById('forgot_msg_th').innerHTML = '' + tmpim + '';
	var tosend = 'forgoten_email=' + forgot_em + '';
	cart_sign_in_user(tosend,'forgot_email');
  }
  else{
   document.getElementById('forgot_msg_th').style.display = 'none';
   document.getElementById('forgot_email_error').style.display = 'inline';
  }
}

function cart_fp_hide_error(keyCode){
  if(keyCode == 13) {
    cart_forgot_password_send();
  }	
  else{
   document.getElementById('forgot_email_error').style.display = 'none';
  } 
}

function comments_limit_length(thisid,comlen){
  var limit_obj = document.getElementById(thisid);
  if(limit_obj.value.length > comlen) {
    limit_obj.value = limit_obj.value.substring(0,comlen);
  }
 
}

$(document).ready(function(){
$('.block-hp-read-more-button').click(function(){
					$(this).hide();
					$(this).next('.block-hp-read-more').show();
					});
					
$('.block-hp-read-more-button-less').click(function(){
					$(this).parent().hide();
					$(this).parent().prev('.block-hp-read-more-button').show();
					});
});
