// JavaScript Document

/*
* @fucntion update response from ajax
* @param type->'favorites','email'..etc...
* @param id-> venture id
*/

/*
* @below are the lobal parameters and arrays used
* to toggole navbar images based on the id....
* Array typesA used for store types
* Array imgA used for storing deselected images
* Array imgSA used for storing selected images
* usage if new type is added first add in typesA[sequNumber] = "value"; next step imgA['type'] = "deselImagesrc"; next step imgSA['type'] = "selImagesrc";
*/
var domain = "http://";
domain+=document.domain;
var t_type = "";
var t_typeA = new Array;
var flag = true;
var imgA = new Array;
var imgSA = new Array;
var typesA = new Array;
var uname = " ";
	
	typesA[0] = "share";
	typesA[1] = "email";
	typesA[2] = "comments";
	typesA[3] = "fav";
	//typesA[4] = "enquire";
	imgA['share']="util-share.gif";
	imgSA['share']="util-share-sel.gif";
	imgA['email']="util-email.gif";
	imgSA['email']="util-email-sel.gif";
	imgA['comments']="util-comments.gif";
	imgSA['comments']="util-comments-sel.gif";
	imgA['fav']="util-fav.gif";
	imgSA['fav']="util-fav-sel.gif";
	//imgA['enquire'] = "util-enquire.gif";
	//imgSA['enquire'] = "util-enquire-sel.gif";

function upUtil(type,id,flag,name){
  try{
	$('des_video').style.display="none";
	$('videoF').style.display="block";
  }catch(e){}	
	uname = name;
	if(flag==null)flag = true;
	
	//t_typeA[type+id]=type+id;
	//alert(t_typeA[type+id]);
	//alert(t_type);
	if(t_typeA[id]==type+id){
		flag = false;
	}
	
	t_typeA[id]=type+id;
	t_type = type+id;	
		
	    if(t_typeA[id]=="fav"+id){
			if(!flag)Fflag=true;else Fflag = false;
			favH = "javascript:upUtil('fav','"+id+"',"+Fflag+")";
			$('a'+id+type).href=favH;
		}
	
	
	if(flag)upAjaxUtil(type,id,flag,"add");
			
	if(!flag){
		if(t_typeA[id]=="fav"+id)upAjaxUtil(type,id,flag,"rm");
		flag = true;
		t_type="";
		t_typeA[id]="";
		$('img'+id+type).src = "images/"+imgA[type];
		$(id).style.display= "none";
	   }
     }

function upAjaxUtil(type,id,flag,action){
	var url_loc = escape(window.location);
	
	if(type=="addfav"){		
	   param = "u_type="+type+"&id="+id+"&action="+action+"&uname="+uname+"&tabname="+$('channel_type').value+"&ch_id="+$('channelid').value;	   
	 }else{		 
	   param = "u_type="+type+"&id="+id+"&action="+action+"&uname="+uname+"&url_loc="+url_loc;	
	 }
	
	new Ajax.Updater( id, 'util.php',
					{
						method: 'get',
						parameters: param,
						onSuccess: function() {							
							if((!flag)&&(type+id=="fav"+id)){
								$(id).style.display= "none";
								//toggleImage(type,id);
								//$('img'+id+type).src = "images/"+imgA[type];
							}else{								
								$(id).style.display= "block";
								toggleImage(type,id);
							}
						}
					} );
}

function toggleImage(type,id){
	
	for(var i=0;i<typesA.length;i++){
		if(typesA[i]==type){
			$('img'+id+type).src = "images/"+imgSA[type];
		}
		else{
			if($('img'+id+typesA[i]).src==domain+"/images/util-fav-sel.gif"){}
 			else {$('img'+id+typesA[i]).src = "images/"+imgA[typesA[i]];}
			
		}
	}
}

function upMapUtil(type,id,mapID){
	
	param = "u_type="+type+"&id="+id+"&mID="+mapID;
	
	new Ajax.Request( 'util.php',
					{
						method: 'get',
						parameters: param,
						onSuccess: function(transpord) {
							map.openInfoWindowHtml(markers[mapID],transpord.responseText);
						}
					} );
}

function getSerByCit(){
	
	param = "cid="+$("cityId").value;
	new Ajax.Request('search_ajax.php',
					{
						method: 'get',
						parameters: param,
						onSuccess:function(response){
							$("cntScMain").innerHTML=response.responseText.split("~ATOKS~")[0];
							var json = response.responseText.split("~ATOKS~")[1];
							upMap(json);
							
						}
					} );
}

function sendEmail(vid,type){
	var update = type+vid;
	var url_loc = escape(window.location);
	param = $(type+vid).serialize()+"&id="+vid+"&type="+type+"&url_loc="+url_loc;
	//param = "id="+vid+"&type="+type;
	
	
	new Ajax.Request( 'email.php',
					{
						method: 'get',
						parameters: param,
						onSuccess:function(traspord){
							$(update).innerHTML = traspord.responseText;
						}
						
					} );
					//alert("emailing");
}
function flag_inapp(type,id,action,chid,tabname){	
	param = "u_type="+type+"&id="+id+"&action="+action+"&uname="+uname+"&ch_id="+chid+"&tabname="+tabname;	
	
	new Ajax.Updater( id, 'util.php',
					{
						method: 'get',
						parameters: param,
						onSuccess: function() {							
							if((!flag)&&(type+id=="fav"+id)){
								$(id).style.display= "none";
								//toggleImage(type,id);
								//$('img'+id+type).src = "images/"+imgA[type];
							}else{								
								$(id).style.display= "block";
								toggleImage(type,id);
							}
						}
					} );
}
function submitComment(vid){
	//  comments
	
	new Ajax.Updater( 'main_com', 'comments/comments.php',
					{
						method: 'get',
						parameters: $('cform'+vid).serialize()
						
					} );
}
function addComment(){
	new Ajax.Updater( 'com_form', 'comments/add_comments.php',
					{
						method: 'get',
						parameters: $('cform').serialize()
					} );
}
function focusText(){
	if($('comment_text').innerHTML=='Submit Your Comments Here...')$('comment_text').innerHTML = "";
	
}
function blurText(){
	if($('comment_text').innerHTML=='')$('comment_text').innerHTML = "Submit Your Comments Here...";
}

function getProjects(id){
	param = "lid="+id;
	new Ajax.Request( 'php/projects.php',
					{
						method: 'get',
						parameters: param
					} );
}



