// ################################################## //
// ===============JavaScript Document================ //
// The belo functions handles modalbox form actions //
// ========created by santrooper@gmail.com=========== //
// ################################################## //
//var wbRoot = getDomain();

function submitForm(formId){
	$(document).ready(function(){
		$('#'+formId).submit();
	});
}

function submitLocationForm(formId, dynUrl){
	$(document).ready(function(){
		dynUrl = (dynUrl)?true:false;
		
		if(dynUrl){
			var oWebRoot = getDomain();
			locnid       = $('#frmtoplid').val();
			locnam       = $("#frmtoplid option:selected").text();
			urlStr       = oWebRoot+'location/'+locnid+'/'+locnam+'-private-home-tutors.html';
			$('#'+formId).attr("action", urlStr);
			$('#'+formId).submit();
		}
		else{
			$('#'+formId).submit();
		}
	});
}

function submitSubjectForm(formId, fldId){
	$(document).ready(function(){
		$('#'+fldId).val($("#subjectid").val());
		$('#'+formId).submit();
	});
}

// ################################################## //

function changeSecurityImage(){
	var wbRoot = getDomain();
	var dt = new Date( );
	rnd = dt.getTime()+Math.random();
	ourl = wbRoot+'library/Thirdparty/capcharesource/imagecapcha.php?t='+rnd;
	//ourl = wbRoot+'/include/capcharesource/imagecapcha.php';
	$(document).ready(function(){
		$('#securityimage').attr('src',ourl);
	});
}

function changeCenterSecurityImage(){
	var wbRoot = getDomain();
	var dt = new Date( );
	rnd = dt.getTime()+Math.random();
	ourl = wbRoot+'library/Thirdparty/capcharesource/imagecapcha.php?t='+rnd;
	//ourl = wbRoot+'/include/capcharesource/imagecapcha.php';
	$(document).ready(function(){
		$('#securityimage').attr('src',ourl);
	});
}


function setPaymentMode(mode, vendor){
	$(document).ready(function(){
		$('#mode').val(mode);
		$('#vendor').val(vendor);
		
		$(".paymentopt").each(function(){
        	$(this).hide();
        });
		
		$('#div_'+vendor).show();
	});
}

function togolSlideDiv(divId){
	$(document).ready(function(){
		$('#'+divId).slideToggle("slow"); 
	});
}

function jqCheckAll( srcobjId, idPrefix ){
   $(document).ready(function(){
	   flag = $('#'+srcobjId).attr('checked');
	   
	   if (flag){
		  $("input[type='checkbox'][id^='"+idPrefix+"']").each(function(i){
			this.checked = true;
		  });
	   }
	   else{
		  $("input[type='checkbox'][id^='"+idPrefix+"']").each(function(i){
			this.checked = false;
		  });
	   }
	   
   });
}

function getAllCheckedBoxGroupedByIdPrefix(prefix){
	try{
		var valArr = new Array();
		var x = 0;
		var valStr = '';
		
		$("input[type='checkbox'][id^='"+prefix+"']").each(function(i){
			if($(this).is(':checked')){
				valArr[x] = $(this).val();
				x++;
			}
		});
		
		if(valArr.length>0){
			valStr = valArr.join('_');
		}
		else{
			valStr = '';
		}
		
		return(valStr);
	}
	catch(err){}
}

function swapImageIcons(targetId, replaceWith){
	 $(document).ready(function(){
		basUrl = getDomain();
		//$("#"+targetId).attr("src", basUrl+"images/"+replaceWith);
		$("#"+targetId).attr("src", replaceWith);
	});
}

function popSendMessageToTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'tutormessage/'+recrId;
			winnam = 'messagetutor'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popPostFeedbackToTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'tutorfeedback/'+recrId;
			winnam = 'feedbacktutor'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popViewTutorFeedback(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'viewtutorfeedback/'+recrId;
			winnam = 'viewtutorfeedback'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendMessageToStudent(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'studentmessage/'+recrId;
			winnam = 'messagestudent'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendApplication(tutnId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'applyfortuition/'+tutnId;
			winnam = 'tuition'+tutnId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendSmsToTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'tutorsms/'+recrId;
			winnam = 'smstutor'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendSmsToStudent(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'studentsms/'+recrId;
			winnam = 'smsstudent'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popViewStudentProfile(recrId, namStr){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'popstudentprofile/'+recrId+'/'+namStr;
			winnam = 'studentprofile'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=600,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function setPaymentMode123456789123456(mode, vendor){
	$(document).ready(function(){
		$('#mode').val(mode);
		$('#vendor').val(vendor);
		
		$(".paymentopt").each(function(){
        	$(this).hide(50);
        });
		
		$('#div_'+vendor).show(200);
	});
}

function bulkDeletePosts(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkpost_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');	
			}
		}
		catch(err){}
	});
}

function bulkDeletePendingPosts(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkpost_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');	
			}
		}
		catch(err){}
	});
}

function bulkDeleteResource(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkres_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');	
			}
		}
		catch(err){}
	});
}

function bulkDeleteMails(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkpost_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');	
			}
		}
		catch(err){}
	});
}

function bulkDeleteHomeWork(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkpost_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');	
			}
		}
		catch(err){}
	});
}

function bulkDeleteSocialApplications(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkaplic_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');
			}
		}
		catch(err){}
	});
}

function bulkDeleteStudentSocialApplications(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkaplic_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select post to delete');
			}
		}
		catch(err){}
	});
}

function showCenterPaymentModes(mode){
   $(document).ready(function(){
	   if(mode=='show'){
	   		$('#div_paymentmodes').show();
	   }
	   else{
		   $('#div_paymentmodes').hide();
		   
		}
	});
}


