// JavaScript Document

function hidestatus()
{
var statusmsg=""
window.status=statusmsg
return true
}

function trim(x)
{
  var ch,c
  ch=x.toString()
  c=ch.charAt(0)
  while (c==" ")
  { ch=ch.slice(1)
  c=ch.charAt(0)
  }
  c=ch.charAt(ch.length-1)
  while(c==" ")
  { ch=ch.slice(0,-1)
  c=ch.charAt(ch.length-1)
  }
  return ch;
}

function CheckAllFormData()
{
		          //If All right then is_ok=1
				  is_ok=1;
	
				  tmp1 = document.form_4371.ch_num;
				  if( trim(tmp1.value)!='' ) { document.getElementById('ch_num_text').style.color=''; }
				  else {
					is_ok=0;
					document.getElementById('ch_num_text').style.color='red';
					document.form_4371.ch_num.focus();
				  }
				  tmp1 = document.form_4371.bodymessg;
				  if( trim(tmp1.value)!='' ) { document.getElementById('bodymessg_text').style.color=''; }
				  else {
					is_ok=0;
					document.getElementById('bodymessg_text').style.color='red';
					document.form_4371.bodymessg.focus();
				  }
		
				  tmp1 = document.form_4371.question;
				  if( trim(tmp1.value)!='' ) { document.getElementById('question_text').style.color=''; }
				  else {
					is_ok=0;
					document.getElementById('question_text').style.color='red';
					document.form_4371.question.focus();
				  }
		
				  tmp1 = document.form_4371.email;
				  if( check_mail(tmp1.value) ) { document.getElementById('email_text').style.color=''; }
				  else {
					is_ok=0;
					document.getElementById('email_text').style.color='red';
					document.form_4371.email.focus();
				  }
				  
				  tmp1 = document.form_4371.fname;
				  if( trim(tmp1.value)!='' ) { document.getElementById('fname_text').style.color=''; }
				  else {
					is_ok=0;
					document.getElementById('fname_text').style.color='red';
					document.form_4371.fname.focus();
				  }  
		
				  if (is_ok==1) {
					if(confirm('Send now?')) { document.form_4371.action.value='2'; document.form_4371.submit(); }
					else return false;
				  }
					else return false;
}

function trim(x)
{
  var ch,c
  ch=x.toString()
  c=ch.charAt(0)
  while (c==" ")
  { ch=ch.slice(1)
  c=ch.charAt(0)
  }
  c=ch.charAt(ch.length-1)
  while(c==" ")
  { ch=ch.slice(0,-1)
  c=ch.charAt(ch.length-1)
  }
  return ch;
}

function check_mail(email)
{ var re = new RegExp("^[\\w\\.-]+@[\\w\\.-]+\\.[A-Za-z]{2,}");
  return (re.test(email));
}

function zoomin(num) {
	s = 'pic' + num;
	b = 'picb' + num;
	document.getElementById(s).style.display='none';
	document.getElementById(b).style.display='';
}
function zoomout(num) {
	s = 'pic' + num;
	b = 'picb' + num;
	document.getElementById(s).style.display='';
	document.getElementById(b).style.display='none';
}

// Move Rating (Stars)
function MoveRating(n1, n2, stat, abs_value) {
	with (document) {
		var st = new String(abs_value);
		switch (stat) {
			case 'on':
				for (var i = 1; i <= 5; i++) {
					getElementById('star_'+n1+'_'+i).className='star_off';
				}
				for (i = 1; i <= n2; i++) {
					getElementById('star_'+n1+'_'+i).className='star_on';
				}
				getElementById('big_star_'+n1).className = 'big_star';
				getElementById('big_star_'+n1).innerHTML=n2;
				break;
			case 'off':		
				getElementById('big_star_'+n1).innerHTML=abs_value;
				for (i = 1; i <= n2; i++) {
					for (var i = 1; i <= 5; i++) {
						getElementById('star_'+n1+'_'+i).className='star_off';
						if (i <= abs_value) getElementById('star_'+n1+'_'+i).className='star_on';
						else getElementById('star_'+n1+'_'+i).className='star_off';
					}								
				}
				if (st.length > 1) getElementById('big_star_'+n1).className = 'big_star_sm';
				break;
		}		
	}
}

//Send Array in php-Mysql query (STARS)
var SendArray = new Array();
function RateCard(prd_num, value, prd_id, style, abs_value, votes) {
	
	SendArray.value     = value;
	SendArray.prd_id    = prd_id;
	SendArray.prd_num   = prd_num;
	SendArray.style     = style;
	SendArray.abs_value = abs_value;
	SendArray.votes     = votes;
	
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState !== 4) {
			document.getElementById('big_star_'+prd_num).innerHTML = '';
		}
		if (req.readyState == 4) {
			document.getElementById('big_star_'+prd_num).innerHTML = abs_value;
			document.getElementById('rate_card_'+prd_num).innerHTML = req.responseJS.result;
			//document.getElementById('rate_card_'+prd_num).innerHTML = req.responseText;
			document.getElementById('msg').innerHTML = req.responseJS.msg;
			document.getElementById('msg').style.display = '';
		}
	}
	req.open('POST', dot+'rate.phtml', true);
	req.send({SendArray:SendArray});
}

