// JavaScript Document
var IE = document.all?true:false;
function GetSitePath()
{	
	if(location.protocol=='http:')
		var spath="http://www.consultantbox.com/";
	else if(location.protocol=='https:')
		var spath="https://www.consultantbox.com/";
	return spath;
	//return 'http://localhost/vip/';
}

function getElementPosition(elemID) 
{
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
	var offsetBottom=0;
    while (offsetTrail) 
	{
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
		offsetBottom +=offsetTrail.offsetBottom;
        offsetTrail = offsetTrail.offsetParent;
    }
    
	if(navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 
	{
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
		offsetBottom += document.body.bottomMargin;
    }
    
	alert(offsetLeft+", "+ offsetTop+", "+ offsetBottom);
}

function Trim(strValue)
{	
	return LTrim(RTrim(strValue));
}

function LTrim(strValue)
{
	var LTRIMrgExp = /^\s */;
	return strValue.replace(LTRIMrgExp, '');
}

function RTrim(strValue)
{
	var RTRIMrgExp = /\s *$/;
	return strValue.replace(RTRIMrgExp, '');
}

function StringLength(ctrName,strMinLength,strMaxLength,fieldLabel,required)
{		
	if(Trim(ctrName.value)!='')
	{
		var str=ctrName.value;
		if(str.length < strMinLength || str.length > strMaxLength)
		{
			alert(fieldLabel);
			ctrName.focus();
			return false;
		}
		return true;
	}
	else if(required==true && Trim(ctrName.value)=='')
	{
			alert(fieldLabel);
			ctrName.focus();
			return false;
	}
	else
	{
		return true;
	}	
}

function isEmailAddr(email,required,label)
{
	var reEmail = /^.+\@.+\..+$/;
	if(Trim(email.value)=='' && required==true)
	{
		alert(label);
		email.focus();
		return false;
	}
    else if(Trim(email.value)!='')
	{
	   	if(reEmail.test(email.value)==false)
		{
			alert(label);
			email.focus();
			return false;
		}
		else
		{
			return true;	
		}
	}    
}

function validInt(formField,fieldLabel,required)
{	
	if(isNaN(formField.value))
	{
		alert('Please enter valid 10 digit code for the "' + fieldLabel +'" field.');
		formField.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function AllowAlphaNumeric(formField,fieldLabel) 
{
	var myregExp = /^[a-zA-Z0-9]+$/;
	if (!myregExp.test(formField.value)) 
	{
		alert(fieldLabel);
		formField.focus();
		return false;
	} 
	else 
	{
		return true;
    	}
}

function isNumeric(formField,fieldLabel) 
{
	var myregExp = /^[.0-9]+$/;
	if (!myregExp.test(formField.value)) 
	{
		alert(fieldLabel);
		formField.focus();
		return false;
	} 
	else 
	{
		return true;
    }
}

function CheckNum(evt)
{
	evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
	//charCode=parseInt(charCode);

	if ((charCode >= 48 && charCode <=57) || (charCode >= 37 && charCode <=40) || (charCode==8 || charCode==9 || charCode==46))	
		return true;
	else
		return false;
}

function isPhone(formField,required,fieldLabel) 
{
	if(Trim(formField.value) != '')
	{
		var myregExp = /^[0-9]+$/;
		if (!myregExp.test(formField.value) || formField.value.length < 10) 
		{
			alert(fieldLabel);
			formField.focus();
			return false;
		} 
		else 
		{
			return true;
		}
	}
	else
	{
		if(required==false)
		{
			return true;
		}
		else
		{
			alert(fieldLabel);
			formField.focus();
			return false;
		}
	}
}

function limitText(limitField, limitCount, limitNum)
{
	if(limitField.value.length>=limitNum)
	{
		limitField.value = limitField.value.substring(0,limitNum);
	}
	else
	{
		limitCount.value = limitNum-limitField.value.length;
	}
}

var wlimit;
var cnt;	
function limitWord(limitField, limitCount, limitNum, evt)
{
	evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
	if(charCode!='32')
	{
		var words = limitField.value.split(" ");
		cnt = words.length;
		
		if(cnt > limitNum)
		{
			limitField.value = limitField.value.substring(0,wlimit);
			limitCount.style.fontWeight='bold';
			limitCount.style.color='#CC0000';
			alert("You have reached the max. allowed words limit!");
		}
		else
		{
			limitCount.style.fontWeight='normal';
			limitCount.style.color='#000000';
			
			if(cnt == limitNum)
				wlimit = limitField.value.length;
			limitCount.value = limitNum-cnt;
		}
		if(Trim(limitField.value)=='')
		{
				if(limitCount.value==(limitNum-1))
					limitCount.value=limitNum;
		}
	}
}

function LimitChars(limitField, limitCount, limitNum) 
{
	var words = limitField.value;
	cnt = words.length;
	
	if(cnt > limitNum)
	{
		limitField.value = limitField.value.substring(0,limitNum);
	}
	else
	{
		if(cnt == limitNum)
			wlimit = limitField.value.length;
		limitCount.value = limitNum-cnt;
	}
	if(Trim(limitField.value)=='')
	{
			if(limitCount.value==(limitNum-1))
				limitCount.value=limitNum;
	}
}

function ShowHideDiv(div)
{
	if(div.style.display=='none')
		div.style.display='block';
	else
		div.style.display='none';
}

function GetStars(level, div)
{
	var imgs='';			
	var site_path=GetSitePath();
	
	for(i=1;i<=level;i++)
	{
		imgs += '<img align="absmiddle" src="'+site_path+'images/str_full.png" width="20" />&nbsp;';
	}
	
	for(j=level;j<5;j++)
	{
		imgs += '<img align="absmiddle" src="'+site_path+'images/str_empty.png" width="20" />&nbsp;';
	}
	
	div.innerHTML=imgs;
}

function ShowConsData(stype, user_id, div)
{
	var site_path=GetSitePath();
	
	if(div.style.display=='none')
		div.style.display='block';
	ajax_do(site_path+"view_cons_profile.php?ajax=1&stype="+stype+"&user_id="+user_id, div);
}

function ShowRefConsData(user_id, div)
{
	var site_path=GetSitePath();
	
	if(div.style.display=='none')
	{
		div.style.display='block';
		div.innerHTML='<img src="../images/timer.gif" alt="" />';	
		ajax_do(site_path+"admin/ajax_view_dline.php?user_id="+user_id, div);
	}
	else
	{
		div.style.display='none';
	}
}

function ShowSLConsDetail(user_id)
{
	div=document.getElementById('div_clist'+user_id);
	var site_path=GetSitePath();
	
	if(div.style.display=='none')
	{
		div.style.display='block';
		ajax_do(site_path+"view_cons_det.php?user_id="+user_id, div);
	}
	else
	{
		div.style.display='none';
	}
}

function ShowMoreConsCountries(sp, div)
{
	if(div.style.display=='none')	
	{
		div.style.display='block';
		sp.innerHTML='Hide More...';	
	}
	else
	{
		div.style.display='none';
		sp.innerHTML='View More...';
	}
}

function SendReq(cons_id, div)
{
	var site_path=GetSitePath();
	
	div.innerHTML='';
	document.getElementById('div_contact'+cons_id).innerHTML='Contact Initiated.';
	if(div.style.display=='none')
		div.style.display='block';
	ajax_do(site_path+"ajax_send_int_req.php?cons_id="+cons_id, div);		
}

function CheckContact(frm)
{
	with(frm)
	{
		if(txtchkses.value=='1')
		{
			if(Trim(contact_msg_title.value)=='')
			{
				alert("Please enter your message title!");
				contact_msg_title.focus();
				return false;
			}
			else if(Trim(contact_msg.value)=='')
			{
				alert("Please enter your message!");
				contact_msg.focus();
				return false;
			}
		}
		else
		{
			if(Trim(contact_p_fname.value)=='')
			{
				alert("Please enter your first name!");
				contact_p_fname.focus();
				return false;
			}
			else if(Trim(contact_p_lname.value)=='')
			{
				alert("Please enter your last name!");
				contact_p_lname.focus();
				return false;
			}
			else if(isEmailAddr(contact_pemail, true, "Please enter your valid email address!")==false)
			{				
				return false;
			}
			else if(Trim(contact_msg_title.value)=='')
			{
				alert("Please enter your message title!");
				contact_msg_title.focus();
				return false;
			}
			else if(Trim(contact_msg.value)=='')
			{
				alert("Please enter your message!");
				contact_msg.focus();
				return false;
			}
		}
	}
}		

function CheckAdminContact(frm)
{
	with(frm)
	{
		if(Trim(contact_msg_title.value)=='')
		{
			alert("Please enter your message title!");
			contact_msg_title.focus();
			return false;
		}
		else if(Trim(contact_msg_admin.value)=='')
		{
			alert("Please enter your message!");
			contact_msg_admin.focus();
			return false;
		}		
	}
}		

function ShowIntHiring(div)
{
	if(div.style.display=='none')
	{
		div.style.display='block';		
	}
	else
	{
		div.style.display='none';	
	}
}

function ValidateIntDates(frm, div, div_timer)
{
	var ret_val=true;
	
	with(frm)
	{
		if(int_date1.value=='')
		{
			alert("Please select possible interview date#1!");
			int_date1.focus();
			ret_val=false;
		}
		else if(int_tzone1.value=='')
		{
			alert("Please select possible interview time zone#1!");
			int_tzone1.focus();
			ret_val=false;
		}
		else if(int_date2.value!='' && int_tzone2.value=='')
		{
			alert("Please select possible interview time zone#2!");
			int_tzone2.focus();
			ret_val=false;
		}	
		else if(int_date3.value!='' && int_tzone3.value=='')
		{
			alert("Please select possible interview time zone#3!");
			int_tzone3.focus();
			ret_val=false;
		}
	}
	
	if(ret_val==true)
	{
		var site_path=GetSitePath();
		div_timer.style.display='block';
		div_timer.innerHTML='<img src="'+site_path+'images/timer.gif" alt="">';
		div.style.display='none';		
		return true;
	}
	else
	{
		return ret_val;
	}
}

function ShowSLCons(div, int_id)
{
	if(div.style.display=='none')
	{
		div.style.display='block';
		location.href='#anc_sl_cons_list'+int_id;
	}
	else
	{
		div.style.display='none';	
	}
}

function ShowHideContactForm(cont_user_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';
	ajax_do(site_path+"ajax_show_cont_form.php?cont_user_id="+cont_user_id, div);
	ShowLightBox(div.id);	
}

function ShowHideAdminContactForm()
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';
	ajax_do(site_path+"ajax_show_cont_admin_form.php", div);
	ShowLightBox(div.id);	
}

function ShowHideInterviewForm(uid)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';				
	ajax_do(site_path+"ajax_set_int_dates.php?uid="+uid, div);
	ShowLightBox(div.id);	
}

function ShowHideToolDet(tool_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';				
	ajax_do(site_path+"ajax_show_tool_det.php?tool_id="+tool_id, div);
	ShowLightBox(div.id);	
}


function RemSLCon(user_id, job_id)
{
	if(confirm("Are you sure you want to remove this SAP Consultant from Shortlisted Consultants?"))	
		location.href='view_jobs.php?job_mod=4&job_id='+job_id+'&del_user_id='+user_id;
}

function RemAppCon(user_id, job_id)
{
	if(confirm("Are you sure you want to remove this SAP Consultant from Applications?"))	
		location.href='view_jobs.php?job_mod=4&job_id='+job_id+'&del_app_id='+user_id;
}

function ApplyJob(job_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';				
	ajax_do(site_path+"ajax_apply_job.php?job_id="+job_id, div);
	ShowLightBox(div.id);	
}

function ShowUserRatings(user_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';		
	if(div.style.display=='none')
	{
		ajax_do(site_path+"ajax_show_rating.php?user_id="+user_id, div);
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();		
	}
}

function ShowUserRef(user_id, div_num)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';		
	if(div.style.display=='none')
	{
		ajax_do(site_path+"ajax_show_ref.php?first_disp=1&user_id="+user_id+"&div_num="+div_num, div);		
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();		
	}
}

function ShowUserRefAdmin(user_id, div_num)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="../images/timer.gif" alt="" />';		
	if(div.style.display=='none')
	{
		ajax_do(site_path+"ajax_show_ref_only.php?first_disp=1&user_id="+user_id+"&div_num="+div_num, div);		
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();		
	}
}

function ShowLinkWithUs(path)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';		
	if(div.style.display=='none')
	{
		ajax_do(site_path+"ajax_link_with_us.php", div);		
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();		
	}
}

function ShowProfilePopup(msg)
{	
	div=document.getElementById('div_lb_pop');
	if(div.style.display=='none')
	{		
		div.innerHTML=msg;
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();
	}
}

function AddCons(cons_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	document.getElementById('div_added'+cons_id).src=site_path+'images/fav_user_off.png';
	document.getElementById('div_added'+cons_id).title='Already added in your favorite list';
	ajax_do(site_path+"ajax_add_cons.php?cons_id="+cons_id, div);
	ShowLightBox(div.id);
}

function AddConsProfile(cons_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	document.getElementById('div_added'+cons_id).src=site_path+'images/fav_user_big_off.png';
	document.getElementById('div_added'+cons_id).title='Already added in your favorite list';
	ajax_do(site_path+"ajax_add_cons.php?cons_id="+cons_id, div);
	ShowLightBox(div.id);
}

function ShowFavConsultants()
{
	var site_path=GetSitePath();
	location.href=site_path+'view_sel_cons.php?login_mod=3';	
}

function SelCon(jid, uid)
{
	div=document.getElementById('div_cons_added');
	var site_path=GetSitePath();
	ajax_do(site_path+"ajax_sel_job_cons.php?job_id="+jid+"&con_id="+uid, div);
	document.getElementById('img_user'+uid).innerHTML='<img src="'+site_path+'images/added_user.png" alt="" title="Already selected for this SAP Role">';
	alert("SAP Consultant with ID: "+uid+" successfully added to your SAP Role!");
}
		
function isUrl(s) 
{
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function ShowUserRefTab(user_id, div_num)
{
	var site_path=GetSitePath();
	for(i=1; i<=4; i++)
	{
		document.getElementById('div_ref_tab_hd'+i).style.display='block';
		document.getElementById('div_ref_tab_hd'+i+'_sel').style.display='none';
	}
	
	document.getElementById('div_ref_tab_hd'+div_num).style.display='none';
	document.getElementById('div_ref_tab_hd'+div_num+'_sel').style.display='block';	
	
	div=document.getElementById('div_ref_data');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';		
	div.style.display='block';	
	ajax_do(site_path+"ajax_show_ref_data.php?user_id="+user_id+"&div_num="+div_num, div);		
}

function ShowConsDetail(user_id)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';		
	if(div.style.display=='none')
	{
		ajax_do(site_path+"view_cons_det.php?user_id="+user_id, div);
		ShowLightBox(div.id);
	}
	else
	{
		HideLightBox();		
	}
}

function ShowRefChecker(path)
{
	var site_path=GetSitePath();
	div=document.getElementById('div_lb_pop');
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';
	ajax_do(site_path+"ajax_show_ref_checker.php", div);
	ShowLightBox(div.id);	
}

function ShowStates(obj_chk, div, user_id)
{
	var site_path=GetSitePath();
	if(obj_chk.checked==true && div.style.display=='none')
	{
		div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';
		div.style.display='block';
		ajax_do(site_path+"ajax_show_states.php?user_id="+user_id, div);
	}
	else
	{
		div.innerHTML='';
		div.style.display='none';	
	}
}

function ShowHideStarSkills(div, sp)
{
	if(div.style.display=='none')
	{
		div.style.display='block';
		sp.innerHTML='Hide More...';	
	}
	else
	{
		div.style.display='none';
		sp.innerHTML='View More...';
	}
}

var curr_lb_div; 
var is_modal = false; 
	 
function ShowLightBox(lb_div, isModal) 
{ 
	document.getElementById(lb_div).style.display='block'; 
	document.getElementById('fade').style.display='block';
	curr_lb_div = lb_div;
	//if (isModal) 
		is_modal = true; 
	//else is_modal = false; 
} 
	 
function HideLightBox() 
{ 
	if(document.getElementById(curr_lb_div)) 
	{ 
		document.getElementById(curr_lb_div).style.display='none'; 
		document.getElementById('fade').style.display='none'; 
		curr_lb_div = ''; 
	} 
} 


function ShowHideMoreCnt(sp, div)
{
	if(div.style.display=='none')
	{
		div.style.display='block';	
		sp.innerHTML='Hide More...';
	}
	else
	{
		div.style.display='none';	
		sp.innerHTML='View More...';
	}
}

var curr_lb_div; 
var is_modal = false; 
	 
function ShowSLightBox(lb_div) 
{ 
	document.getElementById(lb_div).style.display='block'; 
	$().ready(function() {
		var $scrollingDiv = $("#"+lb_div);
 		
			$scrollingDiv
				.stop()
				.animate({"marginTop": ($(window).scrollTop() + 100) + "px"}, "slow" );	
			
			$(window).scroll(function(){		
			$scrollingDiv
				.stop()
				.animate({"marginTop": ($(window).scrollTop() + 100) + "px"}, "slow" );			
		});
	});
		
	//document.getElementById('fade').style.display='block';
	curr_lb_div = lb_div; 
	//if (isModal) 
		is_modal = true;
	//else is_modal = false; 
} 

function ShowEditForm(add_page_name, edit_id)
{	
	var site_path=GetSitePath();
	document.getElementById('div_save_msg').style.display='none';
	document.getElementById('div_del_msg').style.display='none';
	manage_page=add_page_name;
	div=document.getElementById('div_lb_pop');	
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';						
	ajax_do(add_page_name+"?edit_id="+edit_id, div);	
	ShowSLightBox(div.id);
}

function HideAddForm() 
{	
	var pdoc=window.parent.document;	
	pdoc.getElementById('div_lb_pop').style.display='none'; 
	pdoc.getElementById('fade').style.display='none'; 
	curr_lb_div = '';	
	javascript:ViewList(view_page, pdoc.getElementById('div_list'));
}

var manage_page='';
var view_page='';

function ViewList(list_page, div)
{	
	view_page=list_page;
	ajax_do(list_page, div);	
}

function ShowAddForm(add_page_name)
{
	var site_path=GetSitePath();
	document.getElementById('div_save_msg').style.display='none';
	document.getElementById('div_del_msg').style.display='none';
	manage_page=add_page_name;
	div=document.getElementById('div_lb_pop');	
	div.innerHTML='<img src="'+site_path+'images/timer.gif" alt="" />';			
	ajax_do(add_page_name, div);
	ShowSLightBox(div.id);
}
