/*
Page:           rating.js
Created:        Aug 2006
Handles actions and requests for rating bars.	
--------------------------------------------------------- 
ryan masuga, masugadesign.com
ryan@masugadesign.com 
--------------------------------------------------------- */

var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function sndReq(vote,id_num) {
    xmlhttp.open('get', 'rpc.php?v='+vote+'&pid='+id_num);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
    alert('Your vote has been cast');
}

function handleResponse() {

  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            changeText(update[0], update[1]);
           var v = document.getElementById('vt'+update[0]);
           v.innerHTML=update[2];
        }
		}
    }
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 

    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    	var theUL = document.getElementById('unit_ul'+div2show); // the UL

	// switch UL with a loading div
	theUL.innerHTML = '<li class="current-rating" style="width: '+(20*text)+'px;"></li><li><a href="javascript:void(0);" title="1 out of 5" class="r1-unit rater"  onclick="sndReq(\'1\',\''+div2show+'\')">1</a></li><li><a href="javascript:void(0);" title="2 out of 5" class="r2-unit rater"  onclick="sndReq(\'2\',\''+div2show+'\')">2</a></li><li><a href="javascript:void(0);" title="3 out of 5" class="r3-unit rater"  onclick="sndReq(\'3\',\''+div2show+'\')">3</a></li><li><a href="javascript:void(0);" title="4 out of 5" class="r4-unit rater"  onclick="sndReq(\'4\',\''+div2show+'\')">4</a></li><li><a href="javascript:void(0);" title="5 out of 5" class="r5-unit rater"  onclick="sndReq(\'5\',\''+div2show+'\')">5</a></li>';

    if (DOM) {
        var viewer = document.getElementById('unit_ul'+div2show);
        viewer.style.width = (20*text)+'px';
    }  else {
        document.all[div2show].style.width = (20*text)+'px';
    }
}

function getnext(name) {
	 	
 	 	var slave = document.getElementById(name);
 	 	
 	 	if (slave.value=='#'){
 	 		return false;
 	 	}
 	
 		if (name=='county'){
 		
 		var e=document.getElementById('city1');
 		e.innerHTML='<select><option value="#">Select your city...</option></select>';
 		
 		}else if (name=='country'){
  		
 		var e=document.getElementById('city1');
 		e.innerHTML='<select><option value="#">Select your city...</option></select>';
  		var a=document.getElementById('county1');
 		a.innerHTML='<select><option value="#">Select your county...</option></select>';
 			
 		}

	
	

 	
 	var url = 'http://amazingdisplay.com/genCats.php?slave='+slave.value+'&name='+name;

 	frames['iframe'].location.href=url;
 	 	

   }
