



// !!!!!!! RATING PROCESS 

	function fxRate(vkey,rate,idToHide,idToShow,vid){
		cp.call(baseurl+'/ajax/myajaxphp.php','process_data',return_data,rate,vid);
		hideMe(idToHide);
		showMe(idToShow);
	}

	/*function fxRateAudio(rate,idToHide,idToShow,vid){
		cp.call('ajax/myajaxphp.php','process_data_audio',return_data,rate,vid);
		hideMe(idToHide);
		showMe(idToShow);
	}*/
	function HornsUpAudio(vid,toHide,toShow) {
		cp.call(baseurl+'/ajax/myajaxphp.php','horns_up_audio',return_data,vid);
		hideMe(toHide);
		showMe(toShow);
	}

			function return_data(restul){
				
				// Collect the number of BLUE star
			var cnt=restul.getElementsByTagName('trate').item(0).firstChild.data;				
					hideMe('idViewVoteResult');
			if(cnt!='exist')
			{
				// # Show the vote 
				var x=document.getElementById('idVoteView').rows[0].cells;
					x[1].innerHTML=restul.getElementsByTagName('tvote').item(0).firstChild.data;

				
					
					if(cnt>6)
					{
						cnt=6;
					}	
					else if (cnt<0)
					{
						cnt=0;
					}
					
					blank_star=6-cnt;

					var x=document.getElementById('tblViewResult').rows[0].cells;
					
					for (i=0;i<cnt;i++ )
					{
							x[i].innerHTML='<img src='+imgurl+'/star.gif>';
					}
					
					for (j=cnt;j<5;j++ )
					{
							x[j].innerHTML='<img src=' + imgurl+'/blank_star.gif>';
					}
			}
			else
			{
				var x=document.getElementById('voteProcessthank').innerHTML="<FONT COLOR=#FF0000 >You already vote this video</FONT>";
			}
				
				return false;
			}
// RATING PROCESS END  


// !!!!!!! My voting process 

		function fxVote(voteId)
		{
				voteAnswer=document.getElementById('opAns').value;
		
				if(voteAnswer=='')
				{
					alert('Select any one');
				}
				else
				{
						cp.call(baseurl+'/ajax/myajaxphp.php','process_Vote',return_vote_result,voteId,voteAnswer);
				}
		}
					function return_vote_result(result)
					{
					var xx=result.getElementsByTagName('result').item(0).firstChild.data;
					if (xx=='1'){
							count=result.getElementsByTagName('count').item(0).firstChild.data;
							for (var  ii=0; ii<count  ; ii++ ){

								 var vv='A1'+ii;
								 var pp='P1'+ii;	
								
								vv=result.getElementsByTagName(vv).item(0).firstChild.data;
								pp=result.getElementsByTagName(pp).item(0).firstChild.data;
								
								// # Generate Voring table
								var tt=document.getElementById('tblVoteResult').insertRow(0);
								var y=tt.insertCell(0);
								var z=tt.insertCell(1);
								y.innerHTML=vv;
								z.innerHTML=pp +'%';
							
								if(vv==""){
									break;
								}
							}
							insertInToTable('tblPResult', 0,0,'Vote result');
							// # Hide the previous tale
							hideMe('divviewvresult');
							hideMe('tblVote');

					}
					else if(xx>1)
					{
						insertInToTable('tblPResult', 0,0,'<font color=#FF0000><B>Sorry you already voted..</B></FONT>');
						viewVote(xx);
							// # Hide the previous table
							//showMe('divviewvresult');
							hideMe('tblVote');
					}
				}


 // END

 // VIEW VOTE
function viewVote(pollId)
{
		cp.call(baseurl+'/ajax/myajaxphp.php','view_vote',return_view_vote,pollId);
}
		function return_view_vote(result){
			var xx;
			if (1){
					count=result.getElementsByTagName('count').item(0).firstChild.data;
					for (var  ii=0; ii<count  ; ii++ ){

						 var vv='A1'+ii;
						 var pp='P1'+ii;	
						
						vv=result.getElementsByTagName(vv).item(0).firstChild.data;
						pp=result.getElementsByTagName(pp).item(0).firstChild.data;
						
						// # Generate Voring table
						var tt=document.getElementById('tblViewVoteResult').insertRow(0);
						var y=tt.insertCell(0);
						var z=tt.insertCell(1);
						y.innerHTML=vv;
						z.innerHTML=pp +'%';
					
				if(vv==""){
					break;
				}
			}
			insertInToTable('tblViewVote', 0,0,'Current vote status');
		}
		
	}



// !!!!!!!! SEND COMMENT PROCESS

	function fxSendComments(idToHide,commentId,uid,vid){
		comment_value=document.getElementById(commentId).value;
		if(comment_value==''){
			alert(' Comment box is empty !!');
		}
		else{
			hideMe(idToHide);	
			cp.call(baseurl+'/ajax/myajaxphp.php','process_comments',return_comment_response,comment_value,uid,vid);
		}		
		
	}

	function fxSendCommentsAudio(idToHide,commentId,uid,vid){
		comment_value=document.getElementById(commentId).value;
		if(comment_value==''){
			alert(' Comment box is empty !!');
		}
		else{
			hideMe(idToHide);	
			cp.call(baseurl+'/ajax/myajaxphp.php','process_comments_audio',return_comment_response,comment_value,uid,vid);
		}		
		
	}

	function fxSendCommentsProfiles(idToHide,commentId,uid,vid){
		comment_value=document.getElementById(commentId).value;
		if(comment_value==''){
			alert(' Comment box is empty !!');
		}
		else{
			hideMe(idToHide);	
			cp.call(baseurl+'/ajax/myajaxphp.php','process_comments_profiles',return_comment_response,comment_value,uid,vid);
		}		
		
	}

			function return_comment_response(restul){

				if(restul.getElementsByTagName('a').item(0).firstChild.data==0){
					showMe('divComResult2');
				}
				else{
					showMe('divComResult1');
				}
			}
// END

// RECENT VIEW PROCESS
	var current_position=4;
	function recentview(amount,flag){
		
		gflag="viewrecent";
		if(flag=='next')
		{		
				var start=current_position
					current_position=current_position+amount;
				var end=current_position;
				if(dbreport!='1'){

				}

			sql="SELECT VID, title, viewtime, vkey from video where viewtime<>'0000-00-00 00:00:00' order by viewtime desc limit "+start + " , " +end;  
			executeDB(sql);	
			//alert(sql);
 			if(dbreport<0)
			{
					end=current_position;
					current_position=current_position-amount;
					start=current_position;
					alert("End");

			}
		}

		if(flag=='prev')
		{
			var end=current_position;
				current_position=current_position-amount;
			var start=current_position;

			if(start<0){
				start=amount;
				end=start+amount;
				alert("End");
			}

			sql="SELECT VID, title, viewtime, vkey from video where viewtime<>'0000-00-00 00:00:00' order by viewtime desc limit "+start + " , " +end;  
			executeDB(sql);
		}
	}
//END


function pollAnsBox(myID){
	Me=document.getElementById(myID);
	if(Me.value==""){
		  Me.style.background="#3366FF";
		
	}
	else{
		
		Me.style.background="#FFFFFF";
			xy=Me.value;
		for (i=0;i<Me.value;i++ ){		
			var x=document.getElementById('tblViweAnsBox').insertRow(0);
			var y=x.insertCell(0);
			var z=x.insertCell(1);
			y.innerHTML='Answer ' + (xy-i);			
			z.innerHTML='<INPUT TYPE=text SIZE=40 NAME=voteAnsBox'+i+' ID=voteAnsBox'+i+' onBlur=txtBoxValidation(voteAnsBox'+i+', #EAEAEA,#FF0033) >';
		}
	}
	
}

// ## Delete row of a Tabile
	function delteRow(){
		var x=document.getElementById('tblViweAnsBox').rows.length-1;

		for (var i=x;i>=0;i--){
					document.getElementById('tblViweAnsBox').deleteRow(i);
			}
	}


	function fxvalidation(){
		var flag=true;
		var x=document.getElementById('tblViweAnsBox').rows.length-1;

		// ## Question text
		flag=txtBoxValidation('txtQtn','#EAEAEA','#FF0033');

		// ## Questin qty
		flag=txtBoxValidation('txtPollAnsQty','#EAEAEA','#FF0033');
		
		
		for ( i=x; i>=0; i-- )
		{
			targetID='voteAnsBox'+i;
			if (document.getElementById(targetID).value==""){
				txtBoxValidation(targetID,'#EAEAEA','#FF0033');
				flag=false;
				break;
			}
				
							
		}

		return flag;
	}
  

function fxShowAccInfo(a,b){
	showMe(a);
	hideMe(b);	
}


function pollAnsBox($num){
	alert($num);
}





/////being paste



//myjsajax

// User vote
function rateuser(voter,candate,rate){
	
	try{
		cp.call('ajax/myphpajax.php','process_uservote',return_uservote,voter,candate,rate);
	}
	catch(Err){
		alert('Connection failed');
	}

}

function return_uservote(result){

	try{

				myMsg=result.getElementsByTagName('myMsg').item(0).firstChild.data;
				cnt=result.getElementsByTagName('cnt').item(0).firstChild.data;
				
				 showMe('himr');
				if(cnt>6){cnt=6;}	
				else if (cnt<0)	{cnt=0;}
					
				
					blank_star=6-cnt;

					var x=document.getElementById('tblViewUserVote').rows[0].cells;
					
					
					for (i=0;i<cnt;i++ )
					{
						
							x[i].innerHTML='<img src='+imgurl+'/star.gif>';
					}
					
					for (j=cnt;j<5;j++ )
					{
							x[j].innerHTML='<img src=' + imgurl+'/blank_star.gif>';
					}
				
				

				
				if(myMsg=='f'){
					var x=document.getElementById('tblViewUserTate').rows[0].cells;
					x[0].innerHTML='<B>Sorry! You already rated him.</B>';

				}else{
						var x=document.getElementById('tblViewUserTate').rows[0].cells;
 						x[0].innerHTML='<B>Thanks!</B>';
				}
				


	}
		catch(Err){
			   alert('Server prolem');
	}



					

}
// End user vote 





///indexonly

	start=1;
	function fxOnload(){
		alert('this is on load');
	}


	function show_recent(direction, total)
	{
		if(direction=="right")
			start = start + 4;
		else if(direction=="left")
			start = start - 4;

		if(start >= 13)
			start = 1;
		else if(start <= 0)
			start = 9;

		if(start == 1 && total>0)
		{
			document.getElementById('recent1').style.display = "block";
			document.getElementById('recent2').style.display = "none";
			document.getElementById('recent3').style.display = "none";
			if(total<4) last = total; else last = 4;
			document.getElementById('recent_total').innerHTML = "[1-"+last+" of "+total+"]";
		}
		if(start == 5 && total>4)
		{
				document.getElementById('recent1').style.display = "none";
				document.getElementById('recent2').style.display = "block";
				document.getElementById('recent3').style.display = "none";
				if(total<8) last = total; else last = 8;
				document.getElementById('recent_total').innerHTML = "[5-"+last+" of "+total+"]";
		}
		if(start == 9 && total>8)
		{
				document.getElementById('recent1').style.display = "none";
				document.getElementById('recent2').style.display = "none";
				document.getElementById('recent3').style.display = "block";
				if(total<12) last = total; else last = 12;
				document.getElementById('recent_total').innerHTML = "[9-"+last+" of "+total+"]";
		}
		return;
}






        function createNewList()
        {
                var name = prompt("Enter a name for a new contact group.", "");
                if(name)
                        document.location.href="friends.php?add_list="+name;
        }
        function doAction(action)
        {
                if(action)
                {

                        document.getElementById('action_name').value = action;
                        document.friendsForm.submit();

                }
        }
        function invite_mem_addall()
        {
                var x=document.getElementById("myfriends");
                var y=document.getElementById("invitefriends");
                var i;
                i= x.options.length;
                if(i!=0)
                {
                        y.options.length=i;
                        for(var j=0;j<i;j++)
                        {
                                y.options[j]=new Option(x.options[j].text,x.options[j].value);
                        }
                        for(j=0;j<i;j++)
                        {
                                x.remove(0);
                        }
                }

        }
        function invite_mem_add()
        {
                var x=document.getElementById("myfriends");
                var y=document.getElementById("invitefriends");
                var i;
                i = x.selectedIndex;
                if(i>=0)
                {
                        y.options[y.options.length]=new Option(x.options[i].text,x.options[i].value);
                        x.remove(x.selectedIndex);
                }
        }
        function invite_mem_removeall()
        {
                var x=document.getElementById("invitefriends");
                var y=document.getElementById("myfriends");
                var i;
                i= x.options.length;
                if(i!=0)
                {
                        y.options.length=i;
                        for(var j=0;j<i;j++)
                        {
                                y.options[j]=new Option(x.options[j].text,x.options[j].value);

                        }
                        for(j=0;j<i;j++)
                        {
                                x.remove(0);

                        }
                }
        }







        function invite_mem_remove()
        {
                var x=document.getElementById("invitefriends");
                var y=document.getElementById("myfriends");
                var i;
                i = x.selectedIndex;
                if(i>=0)
                {
                        y.options[y.options.length]=new Option(x.options[i].text,x.options[i].value);
                        x.remove(x.selectedIndex);
                }
        }

        function invite_mem_send()
        {
                var i,out;
                var x=document.getElementById("invitefriends");
                for(i=0; i<x.options.length; i++)
                {
                        out = out + "<input type=hidden name=flist[] value="+x.options[i].text+" >";
                }
                document.getElementById('friends_div').innerHTML=out;
                document.fform.submit();
        }

        function approve_post(id,idHlinkAprove)
        {                
		alert("This posting will approved. Refresh the page.");
		var y="apostform"+id;
		var x = document.getElementById(y);
                return x.submit();


        }





////myjsfx


function searchList () {
	document.getElementById("search-photo").style.display = "none";
	document.getElementById("search-blog").style.display = "none";
	document.getElementById("search-video").style.display = "none";
	document.getElementById("search-forum").style.display = "none";
	var searchDiv = document.getElementById("searchSelect").value;
	document.getElementById(searchDiv).style.display = "block";
	
}




//## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  SITE CONFIGURATIN !!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DB initialization 
var dbArray = new Array();
var dbreport;
var recordcount;
var coloumcount;

// Ajax initialization 
	var cp = new cpaint();
	cp.set_debug(false);			
	cp.set_response_type('XML');	

  
// Java script ini

	
	var imgurl = 'http://www.metalinjection.net/tv/images';
	var baseurl = 'http://www.metalinjection.net/tv/';

//## END



//##!!!!!!!!!!!!!!!!!!!!!!!!!!   My FUNCTION ARCHIVE  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


//!!!!!!!!! Executer Databse

var dbLloaded=true;

function executeDB(sql){
		var processScriptUrl=baseurl+'ajax/myphpajax.php';
		cp.call(processScriptUrl,'executeDB',return_value,sql);
	
}
	
function return_value(result){
				
		dbreport=result.getElementsByTagName('dbreport').item(0).firstChild.data;
		
		if (dbreport=='1'){
			// GET How many row fetch
			recordcount=result.getElementsByTagName('recordcount').item(0).firstChild.data;
			coloumcount=result.getElementsByTagName('coloumcount').item(0).firstChild.data;

			//Population My DB Values							
				for( i=0;i<recordcount;i++){
					dbArray[i]=new Array(recordcount);
					for( ii=0;ii<coloumcount;ii++){
						dbArray[i][ii]=result.getElementsByTagName('dbvalue'+i+ii).item(0).firstChild.data;															
					}
				}
				
				
		}


dbLoaded = false;
							
															
}
//END 

//!!!!!!!Insert data in to  table HTML patge

	function insertInToTable(tblId, varRow, varCell, varData){
		try{
			var x=document.getElementById(tblId).rows[varRow].cells;
			x[varCell].innerHTML=varData;
			return false;
		}
		catch(Err){
			return false;
		}
	}

//END 



// !!!!!! Input validation empty

	function txtBoxValidation(myId,defaultColor,errColor){
		
		// # My property
		try{	
			me=document.getElementById(myId);

			if(me.value==""){	
				me.style.background=errColor;
				me.setFocus;
				return false;
			}
			else{
				me.style.background=defaultColor;
				me.setFocus;
				return true;
			}
		}
		catch(Err){
			return 'Err';
		}
	}

// END 
 
  
// !!!! !!HIEKE A OBJECT //
function hideMe(myId){
	document.getElementById(myId).style.display="none";
	
}
// END

// !!!!!! TO SHOW A OBJECT 
function showMe(myId){
	document.getElementById(myId).style.display="block";
	
}
//END 




// !!!!!!  ASSIGN VALUE IN TO A OBJECT

function directMyvalueto(myValue,thatId){
	document.getElementById(thatId).value=myValue;
}
// END 








////sendtofriend
function myPopup2(id) {
window.open( "http://www.metalinjection.tv/tv/sendtofriend.php?id=" + id, "myWindow", "status = 1, height = 400, width = 400, resizable = 0" )
}




///slider


(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			
			if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};				
			
			if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				if(options.numeric){
					html += '<ol id="'+ options.numericId +'"></ol>';
				} else {
					if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				};
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			if(options.numeric){									
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			} else {
				$("a","#"+options.nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+options.prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
			};
			
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							$("a","#"+options.nextId).hide();
							$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+options.nextId).show();
							$("a","#"+options.lastId).show();					
						};
						if(t==0){
							$("a","#"+options.prevId).hide();
							$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+options.prevId).show();
							$("a","#"+options.firstId).show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);







$(document).ready(function(){
$("#slider").easySlider({
auto: true,
pause:3000,
continuous: true});
});