// ################################################## //
// ===============JavaScript Document================ //
// The belo functions handles modalbox form actions //
// ========created by santrooper@gmail.com=========== //
// ################################################## //
//var wbRoot = getDomain();

/*
function submitForm(formId){
	$(document).ready(function(){
		try{
			$('#'+formId).submit();
		}
		catch(err){
			alert('Form could not be submited');
		}
	});
}
*/

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{
			//alert($('#'+formId));
			$('#'+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=430, width=700, top=50, left=50, resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendOpenMessageToTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl    = getDomain();
			trgurl    = basUrl + 'opentutormessage/'+recrId;
			winnam    = 'opentutormessage'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0, scrollbars=1, menubar=0, height=732, width=717, top=50, left=50, resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendMessageToOnlineTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'onlinetutormessage/'+recrId;
			winnam = 'messageonlinetutor'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0, height=430, width=700, top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popProductSendMessageToTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'tutor-product-query/'+recrId;
			winnam = 'productmessagetutor'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0, scrollbars=1, menubar=0, height=500, width=680, 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=650,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=550,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=430, width=700, 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=400,width=700,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=550,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 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 bulkDeleteClass(){
	$(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 bulkDeleteCommonAlertMessages(){
	$(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 bulkDeletePack(){
	$(document).ready(function(){
		try{
			idStr = getAllCheckedBoxGroupedByIdPrefix('chkstudy_');
			
			if(jstrim(idStr)!=''){
				if(confirm('Do you really want to delete this')){
					$('#oid').val(idStr);
					submitForm('frmpost');
				}
			}
			else{
				alert('Please select Study Pack 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();
		}
	});
}

function popChangeTutorPrivacy(){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mytutoraccount/changeprivacy';
			winnam = 'changeprivacy';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=265,width=671,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}


function popChangeCenterPrivacy(){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mycenteraccount/changeprivacy';
			winnam = 'changeprivacy';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=265,width=671,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendMessageToCenter(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'centermessage/'+recrId;
			winnam = 'messagecenter'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=550,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popSendOpenMessageToCenter(recrId){
	$(document).ready(function(){
		try{
			basUrl    = getDomain();
			trgurl    = basUrl + 'opencentermessage/'+recrId;
			winnam    = 'opencentermessage'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=732, width=717,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}


function popProductSendMessageToCenter(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'center-product-query/'+recrId;
			winnam = 'productmessagecenter'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=550,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popContactMessageToCenter(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'contactcenter/'+recrId;
			winnam = 'productmessagecenter'+recrId;
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=550,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}



/*function popStudyPackDetails(urlStr){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = urlStr;
			winnam = 'studypackdetails';
			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 popManageBankDetails(){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mytutoraccount/managebankdetails';
			winnam = 'managebankdetails';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=400,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}



function popManageCntrBankDetails(){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mycenteraccount/managebankdetails';
			winnam = 'managebankdetails';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=400,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popTellFriendTutor(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mytutoraccount/tellfriendtutor/promocodeid/'+recrId;
			winnam = 'managebankdetails';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=505,width=669,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function popTellFriendStudent(recrId){
	$(document).ready(function(){
		try{
			basUrl = getDomain();
			trgurl = basUrl + 'mystudentaccount/tellfriendstudent/promocodeid/'+recrId;
			winnam = 'managebankdetails';
			newWindow = window.open(trgurl, winnam, "status=0,scrollbars=1,menubar=0,height=550,width=650,top=50,left=50,resizable=0");
			newWindow.focus();
		}
		catch(err){}
	});
}

function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode;
	
	if (charCode > 31 && (charCode < 44 || charCode > 57 || charCode == 45 || charCode == 47)) return false;
	
	return true;
}

function validateCommonSearch(){
	try{
		frmsbj = jQuery.trim(jQuery('#commonfrmsbj').val());
		
		if(frmsbj=='Subject' || frmsbj==''){
			alert('Please enter a subject');
		}
		else{
			jQuery('#frmcommonsearch').submit()
		}
	}
	catch(err){}
}

function validateCommonSearchCode(){
	try{
		frmutype = jQuery.trim(jQuery('#frmutype').attr('checked'));
		frmsbj = jQuery.trim(jQuery('#tutorcode').val());
		
		if(frmsbj == ''){
			alert('Please enter Numeric value in Code');
		}
		else{
			jQuery('#searchcodeval').submit()
		}
	}
	catch(err){}
}
