/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts.com Visual Caster v1.0        |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com © 2007                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+

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);
}

	
/*****News letter sign up for resellers minisite starts*******/

function doNewsLetterSignUp()
{ 
    var user_name = document.getElementById("txtNewsUsr").value;
	var user_email = document.getElementById("txtNewsEmail").value;
	if ( user_name =='' ) {
		alert("Enter your name ...");
		return false;
	} else if ( user_email =='' ) {
		alert("Enter Email address ...");
		return false;
	} else {
	   if ( checkEmail(user_email) ) {
		var url="./newsletter_signup.php?uname=" + user_name + "&uemail=" + user_email;
		xmlhttp.open("GET", url , true)
		xmlhttp.onreadystatechange = setNewsLetterStatus;
		xmlhttp.send(null)
	   }
	}
} 

function setNewsLetterStatus() 
{ 
	var newsMsg = document.getElementById("newsLetterMsg");
	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{ 
		if (xmlhttp.status == 200){ 
		  if(xmlhttp.responseText == 'S')
		  {
			newsMsg.innerHTML=' ';
			newsMsg.style.color="#00FF00";
			newsMsg.innerHTML = ('Successfully subscribed newsletter !!');
		  }
		  else if(xmlhttp.responseText == 'X')
		  {
			newsMsg.innerHTML=' ';
			newsMsg.style.color="#FF0000";
			newsMsg.innerHTML = ('Already subscribed newsletter !!');
		  } else {
	      }
	   } 
	}
} 
/*****News letter sign up for resellers minisite ends*******/
/*****Feedbackrating for resellers minisite starts*******/
function setrate( rate, iPath ) {
	for( var x=1; x<=rate; x++ )
	{
		document['istar_'+x].src= iPath + "/images/star2.gif";
	}
	document.frmfeedadd.rating.value=rate;
}
function selstar( rate, iPath ) {
	if ( document.frmfeedadd.rating.value == '0' ) {
		
		for( var x=1; x<=rate; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star2.gif";
	  }
    } else {
		for( var x=1; x<=document.frmfeedadd.rating.value; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star1.gif";
		}
		for( var x=1; x<=rate; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star2.gif";
		}
	}
	  
}
function remstar( rate, iPath ) {
	if ( document.frmfeedadd.rating.value == '0' ) {
		for( var x=1; x<=rate; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star1.gif";
		}
    } else {
		for( var x=1; x<=5; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star1.gif";
		}
		for( var x=1; x<=document.frmfeedadd.rating.value; x++ )
		{
			document['istar_'+x].src= iPath + "/images/star2.gif";
		}
	}
	  
}
function viewFeedback( id ) {
   var widFdbDiv = document.getElementById('div_Fdb'+id);

   if ( widFdbDiv.style.display == 'none' ) {
        widFdbDiv.style.display = "";  
   }
}
function hideFeedback( id ) {
   var widFdbDiv = document.getElementById('div_Fdb'+id);
   if ( widFdbDiv.style.display == "" ) {
	 widFdbDiv.style.display = "none";  
   }
}



function viewFeedback1( id ) {
   var widFdbDiv = document.getElementById('div_Fdbs'+id);

   if ( widFdbDiv.style.display == 'none' ) {
        widFdbDiv.style.display = "";  
		    
   }
}
function hideFeedback1( id ) {
   var widFdbDiv = document.getElementById('div_Fdbs'+id);
   if ( widFdbDiv.style.display == "" ) {
	 widFdbDiv.style.display = "none";  
   }
}


/*****Feedbackrating for resellers minisite ends*******/

function sndReq(vote,id_num,ip_num,units,rating) {
	var theUL = document.getElementById('unit_ul'+id_num); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<div class="loading"></div>';
	xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units+'&rating='+rating);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

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]);
        }
		}
    }
}

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"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

/* =============================================================== */
var ratingAction = {
		'a.rater' : function(element){
			element.onclick = function(){

			var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
			var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
			var parameterList = new Array();

			for (j = 0; j < parameterTokens.length; j++) {
				var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
				var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
				parameterList[parameterName] = parameterValue;
			}
			var theratingID = parameterList['q'];
			var theVote = parameterList['j'];
			var theuserIP = parameterList['t'];
			var theunits = parameterList['c'];
			var therating = parameterList['rating'];
									
			//for testing	alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
			sndReq(theVote,theratingID,theuserIP,theunits,therating); return false;		
			}
		}
		
	};
Behaviour.register(ratingAction);

