// JavaScript Document123
 // Auther:Abhijit Pathak for Pathfinder 
 var pagelink;
 
 	function fnShowWidgetLightBox()
	{
		Lightbox.showBoxByID('id_widget_iframe',700,1000); void(0);
	}
 
 
 	function fnValidateJobSearch(strButtonId,strErrDivId,strSearchBoxId,enumLeftsearch)
	{
		var strSearchText = document.getElementById(strSearchBoxId).value;	
		strSearchText = fnTrim(strSearchText);
		
		if(strSearchText == "Put Job Titles, Location, Company Name,Skills,Industry,etc")
		{
			strSearchText = "";
		}		
		
		if(!fnValidateSignUpInputString(strSearchText))
		{
			document.getElementById(strErrDivId).innerHTML = "<b>Special Characters are not allowed.</b>";
			ajax_showTooltip(strErrDivId, document.getElementById(strButtonId),170,40);	
			return false;
		}	
		else if(strSearchText == "")
		{
			document.getElementById(strErrDivId).innerHTML = "Enter keyword for search.";
			ajax_showTooltip(strErrDivId, document.getElementById(strButtonId),170,20);	
			return false;
		}
		else
		{
			if(enumLeftsearch == 1)
			{
				document.frmjobsearch.submit();
			}
			else
			{
				return true;
			}
		}
	}
 
    function fnValidateLoginInputForComment(type,typeid)
	{
		//alert('inside fnValidateLoginInputForComment'+type+typeid);
		//if(document.getElementById('id_txtloginemailC_'+type).value );

	 if(document.getElementById("id_txtloginemailComment").value == "" || document.getElementById("id_txtloginemailComment").value ==false)
		{
			alert("Enter Email Address");	
			document.getElementById("id_txtloginemailComment").focus();
			document.getElementById("id_txtloginemailComment").select();
			return false;
		}
		else
		{
			if(!fnEmailCheck (document.getElementById("id_txtloginemailComment").value))
			{
				strErrorMessage = "Enter Valid Email Address.";
				document.getElementById("id_txtloginemailComment").focus();
				document.getElementById("id_txtloginemailComment").select();
				return false;
			}	
		}
		
		if(document.getElementById("id_txtloginpasswordComment").value == "" || document.getElementById("id_txtloginpasswordComment").value == false)
		{
			alert("Enter Password");
			document.getElementById("id_txtloginpasswordComment").focus();
			return false;
		}
		
		u = document.getElementById("id_txtloginemailComment").value; 
		p = document.getElementById("id_txtloginpasswordComment").value;
		var txtcomment = document.getElementById("id_txtComment").value;
		 try{
			pagelink =  document.getElementById("id_pageLinkId").value;
		}
		catch(e)
		{
			//	
		}
		txtcomment = escape(txtcomment);
	 	txtcomment = txtcomment.replace(/\r?\n/g,'<br/>');
		fnAjaxCallerforComment("id_id_LoginDivForLoginClick","loginforcomment","login",'&u='+u+'&p='+p+'&type='+type+'&typeid='+typeid+'&txtcomment='+txtcomment+'&pagelinkid='+pagelink,'','');

		return true;
	}
	var ajaxObjects = new Array();
var img = new Image();
img.src = "images/loading.gif";
var contentid;
var extracontent;
var tempajaxaction;
var tempaction;
var globalaction;
var globalajaxaction;
var globalparams;
var type;
var typeid;
var global_site;
var	intContentPageId;	
var norefresh=1; 
	function fnAjaxCallerforComment(contentelementid, action,ajax_action,params,content,hide_contentid)
    {    
		 var mytool_array ;
		 var type_search ;
		 var typeid_search ;
		 var type_search_arr;
		 var typeid_search;
		 var params_list=params;
		 //var intContentPageId_arr;
		    mytool_array=params_list.split("&");
			type_search =mytool_array[3];
			typeid_search =mytool_array[4];
		var intContentPageId_arr=mytool_array[6];
			intContentPageId_arr=intContentPageId_arr.split("=");
			intContentPageId=intContentPageId_arr[1];
			type_search_arr=type_search.split("=");
			typeid_search_arr=typeid_search.split("=");
			
			type=type_search_arr[1];
			typeid=typeid_search_arr[1];
			
		    globalaction = action;
			globalajaxaction = ajax_action;
			globalparams = params;
			tempaction = action;
			global_site =sitename;
		 	// alert("0"+mytool_array[0]+"\n"+"1"+mytool_array[1]+"\n"+"2"+mytool_array[2]+"\n"+"3"+mytool_array[3]+"\n"+"4"+mytool_array[4]+"\n"+"5"+mytool_array[5] +"\n"+"6"+mytool_array[6]);
           
			 
			tempajaxaction = ajax_action;
			var d = new Date();
			var time = d.getTime();
			contentid = contentelementid;
			extracontent = content;
			var hide_content=hide_contentid;
					
			 if(hide_content != "")
			  {
				  var arrContet = hide_content.split(",");
				  for(var intCtr = 0; intCtr < arrContet.length; intCtr++)
				  {
					$(arrContet[intCtr]).innerHTML = "";
					$(arrContet[intCtr]).style.display = "none";
				  }
			  }
			  
			  
			  try{
			  document.getElementById("main_comment").style.display ="none";
			  }
			  catch(e)
			  {
				//
			   }
			   //document.getElementById("id_txtComment").style.display ="none";
              var url = sitename+'/index.php?action='+ action +'&mode=ajax&ajax_action='+ ajax_action + params +'&'+time ;
			 /* var myAjax = new Ajax.Request(url,
			  {
				method:'get',
				onLoading: fnAjaxRequestInProgressfc,
				onSuccess: fnProcessAjaxResponsefc,
				onFailure: fnAjaxRequestErrorfc		
			  });	*/
			 
			  fnAjaxRequestInProgressfc(contentelementid);
			  var ajaxIndex = ajaxObjects.length;
			  ajaxObjects[ajaxIndex] = new sack();
			  ajaxObjects[ajaxIndex].requestFile = url;
			  
			  ajaxObjects[ajaxIndex].onCompletion = function()
			  {
				  fnProcessAjaxResponsefc(ajaxObjects[ajaxIndex].response);
			  }
			  ajaxObjects[ajaxIndex].runAJAX();
			
}


function fnProcessAjaxResponsefc(response)
{   
     var Message;
    // var response = transport.responseText;

	  if(response==3)
	 {     
		  $(contentid).style.display = "";
		  $('id_LoginDivForCommentClick').style.display = "none";
		  alert("Please Check Your Login Details.")   
	 }
	 else
	 {    
	 
		 if(response==1)
		   Message="<b>Datebase error</b><br/>";
		  if(response==2)
		   //Message="Comment Added Successfully."; 
		    Message="Comment Added Successfully and Sent to the Home Page."; 
	//	 Lightbox.hideBox();   
			if(response==2)
			{   
			 	//alert(type);
				switch(type)
				{

					  case "allthings":
					      url=  global_site+"/index.php?action=allthingdetails&id="+typeid+"&success="+Message;
						 location.href = url;
					  break;
					  
					  case "allthingsreconsidered":
					  url=  global_site+"/index.php?action=allthingsreconsidered&page="+intContentPageId+"&success="+Message;
					  location.href = url;
					  break;
						
						case "pressrelease":
					 	   url=  global_site+"/index.php?action=showarticledetails&articleid="+typeid+"&success="+Message+"&iscompany=1&type=company";
						   location.href = url;
						break;
						case "vedios":
		   				  url=  global_site+"/index.php?action=showvideodetails&videoid="+typeid+"&success="+Message+"&isCompanyVideo=1";
						  location.href = url;
						break;
						case "blogs":
				 		  url=  global_site+"/index.php?action=showblogdetails&blogid="+typeid+"&success="+Message+"&iscompany=1";
						  location.href = url;
						break;
						case "roports":
						  url=  global_site+"/index.php?action=showreportdetails&reportid="+typeid+"&success="+Message+"&iscompany=1";
						  location.href = url;
						break;
						case "podcasts":
					      url=  global_site+"/index.php?action=podcastdetails&id="+typeid+"&success="+Message;
						  location.href = url;
						break;
						
						case "events":
						  //url=  global_site+"index.php?action=showcompanyeventtoindividual&hid_inteventid="+typeid+"&success="+Message;
						  url=  global_site+"/index.php?action=eventdetailsnew&id="+typeid+"&success="+Message;
						  location.href = url;
						break;
						
						case "compony":
						  
						 document.getElementById("id_txtComment").value = "";
						 //alert('contentpageid is'+intContentPageId);
						 //if(intContentPageId=='aboutme')
						 if(intContentPageId==0)
						 {
							    url=  global_site+"/index.php?action=viewcompanyprofile&id="+typeid+"&success="+Message;
						        location.href = url;
							}
						 else
						 {
							
							  Lightbox.refreshAfterClose=0;
							  fnAjaxContentProcess("id_ShowCompanyContent", "viewcompanyprofile","getcontent", "id="+typeid+"&iscomment=1&boolShowCommentMsg=1",intContentPageId);
                           //  fnAjaxContentProcess("id_ShowCompanyContent", "viewcompanyprofile","getcontent", "id="+typeid,intContentPageId);
                               Lightbox.hideBox();
						 }
 					      
                        break;
					 
				} 
			    
		    }
			   
			 
	 }
	 
}
	

function fnAjaxRequestInProgressfc(contentelementid)
{
	//$(contentid).style.display = "";
	//$(contentid).innerHTML = "<img src='images/loading.gif' />";
	$(contentid).style.display = "none";
	$('id_LoginDivForCommentClick').style.display = "";
}

function fnAjaxRequestErrorfc()
{
	//$(contentid).style.display = "";
	//$(contentid).innerHTML = "Error !!!!! ";
	
	$(contentid).style.display = "";
	$('id_LoginDivForCommentClick').style.display = "none";
	alert("Error!! Please Try Again");
}

function fnCheckForCommentInput(textaid,userid)
{
	//alert(document.getElementById(textaid).value+textaid);
	if(document.getElementById(textaid).value == "")
	{
		alert("Enter Comment");
		return false;
	}
	else
	{
		try
		{  
		    if(norefresh==1)
			{
				Lightbox.refreshAfterClose=1;
			}
			else
			{
				Lightbox.refreshAfterClose=0;
			}
		}
		catch(e)
		{
		  Lightbox.refreshAfterClose=1;
		}
		
		if(userid ==0 || userid=="")
		{
			Lightbox.showBoxByID('id_LoginDivForComment', 250, 250);
			return false;
		}
	}
	return true;
}