var vSType=0
function loadSchool(frm,pmSortName)
{
	vFlag=''
	vType=''
	vAllCheck=0
	vTotal=0
	if(vSType == 0)
	{
		pmSortType='ASC'
		vSType++;
	}
	else if(vSType > 0)
	{
		pmSortType='DESC'
		vSType=0;
	}
	
	if(document.frmSchoolDetails)
	{
		vFlag=document.frmSchoolDetails.flag.value
		vType=document.frmSchoolDetails.type.value
	}
	if(document.frmSchTool)
	{
		vTotal=document.frmSchTool.hidTotalRec.value
		vAllCheck=document.frmSchTool.hidAllCheck.value
	}
	if(frm == '')
		frm=document.frmSchoolSearch;

	if(pmSortName == '')
		vSortName=frm.hidSortName.value
	else
		vSortName=pmSortName
	
	if(pmSortType == '')
		vSortType=frm.hidSortType.value
	else
		vSortType=pmSortType
	var vImg;
	
	if(vSortType == 'DESC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminidown.png' border='0'>"
	if(vSortType == 'ASC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminiup.png' border='0'>"
	
	document.getElementById('School_Name').innerHTML='';
	document.getElementById('School_City').innerHTML='';
	document.getElementById('School_State_abbr').innerHTML='';
	
	document.getElementById(vSortName).innerHTML=vImg
	vName=frm.txtSearchName.value
	if(vName != '')
	{
		if(vName.length < 3 )
		{
			alert("Please enter the school name at leat 3 characters")
			frm.txtSearchName.focus();
			return false;
		}
	}
	document.getElementById("divSchool").innerHTML="<span class='loading'>Loading...</span>";
	vName=vName.replace("&","##");
	vCity=frm.sesCity.value
	
	if(vCity == 0) vCity='';
	
	//vCity=frm.sesCity.value
	//vCity='';
	vState=frm.sesState.value;
	vCurpage=frm.vCurpage.value;
	//if(vName != '' || vCity !='' || vState != '')
	//vCurpage='';
	
	frm.hidSortName.value = vSortName
	frm.hidSortType.value = vSortType
	if(vAllCheck == 1)
	{
	vTotalRec=vTotal
	vCurpage = 1;
	}
	else
	vTotalRec=frm.hidTotalRec.value
	vParam="vName="+vName+"&vCity="+vCity+"&vState="+vState+"&vCurpage="+vCurpage+"&vSortName="+vSortName+"&vSortType="+vSortType+"&vTotalRec="+vTotalRec+"&vFlag="+vFlag+"&vType="+vType+"&vAllCheck="+vAllCheck
	vUrl='sch_list_inner.php';
	//alert(vParam);
	ajaxrequest(vUrl,'displaySchoolList', document.getElementById("divSchool"), 0,'POST',vParam);
	return false;
}

function loadingSchPageing(frm,pmSortName,pmSortType)
{
		if(document.frmSchoolDetails)
	{
		vFlag=document.frmSchoolDetails.flag.value
		vType=document.frmSchoolDetails.type.value
	}
	if(frm == '')
		frm=document.frmSchoolSearch;

	if(pmSortName == '')
		vSortName=frm.hidSortName.value
	else
		vSortName=pmSortName
	
	if(pmSortType == '')
		vSortType=frm.hidSortType.value
	else
		vSortType=pmSortType
	var vImg;
	
	if(vSortType == 'DESC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminidown.png' border='0'>"
	if(vSortType == 'ASC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminiup.png' border='0'>"
	
	document.getElementById('School_Name').innerHTML='';
	document.getElementById('School_City').innerHTML='';
	document.getElementById('School_State_abbr').innerHTML='';
	
	document.getElementById(vSortName).innerHTML=vImg
	
	vName=frm.txtSearchName.value
	if(vName != '')
	{
		if(vName.length < 3 )
		{
			alert("Please enter the school name at leat 3 characters")
			frm.txtSearchName.focus();
			return false;
		}
	}	
	document.getElementById("divSchool").innerHTML="<span class='loading'>Loading...</span>";
	vName=vName.replace("&","##");
	vCity=frm.sesCity.value
	
	if(vCity == 0) vCity='';
	vState=frm.sesState.value;
	vCurpage=frm.vCurpage.value;
	//if(vName != '' || vCity !='' || vState != '')
		//vCurpage='';
	
	frm.hidSortName.value = vSortName
	frm.hidSortType.value = vSortType
	vTotalRec=frm.hidTotalRec.value
	vParam="vName="+vName+"&vCity="+vCity+"&vState="+vState+"&vCurpage="+vCurpage+"&vSortName="+vSortName+"&vSortType="+vSortType+"&vTotalRec="+vTotalRec+"&vFlag="+vFlag+"&vType="+vType
	vUrl='sch_list_inner.php'
	ajaxrequest(vUrl,'displaySchoolList', document.getElementById("divSchool"), 0,'POST',vParam);
	return false;

}
function submitSchoolList(frm,pmSortName,pmSortType)
{
	frm.vCurpage.value=0;
	loadingSchPageing(frm,pmSortName,pmSortType);
	return false
}
function submitSchoolSwitch(frm,pmSortName,pmSortType)
{
	frm.vCurpage.value=0;
	loadSchoolSwitch(frm,pmSortName,pmSortType);
	return false
}
function displaySchoolList(txt,obj)
{
	obj.innerHTML=txt
	buttonizeall(obj);
	return false;
}
function loadSchoolSwitch(frm,pmSortName,pmSortType)
{
	if(frm == '')
		frm=document.frmSchoolSwitch;

	if(pmSortName == '')
		vSortName=frm.hidSortName.value
	else
		vSortName=pmSortName
	
	if(frm.hidSortType.value)
		vSortType=frm.hidSortType.value
	else
		vSortType=pmSortType
	var vImg;
	if(vSType == 0)
	{
		pmSortType='ASC'
		vSType++;
	}
	else if(vSType > 0)
	{
		pmSortType='DESC'
		vSType=0;
	}
	
	if(pmSortType == 'DESC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminidown.png' border='0'>"
	if(pmSortType == 'ASC')
		vImg="<img src='"+frm.hidImgUrl.value+"zminiup.png' border='0'>"
	
	document.getElementById('schl_name').innerHTML=''
	document.getElementById('schl_mailing_stat_abbr').innerHTML=''
	document.getElementById('schl_mailing_city').innerHTML=''
	
	document.getElementById(vSortName).innerHTML=vImg
	
	document.getElementById("divSchool").innerHTML="<span class='loading'>Loading...</span>";
	vName=frm.txtSearchName.value
	//vCity=frm.sesCity.value
	vName=vName.replace("&","##");
	vCity=frm.sesCity.value
	
	if(vCity == 0) vCity='';
	
	vState=frm.sesState.value

	vCurpage=frm.vCurpage.value

	frm.hidSortName.value = vSortName
	frm.hidSortType.value = pmSortType
	vTotalRec=frm.hidTotalRec.value
	vParam="vName="+vName+"&vCity="+vCity+"&vState="+vState+"&vCurpage="+vCurpage+"&vSortName="+vSortName+"&vSortType="+pmSortType+"&vTotalRec="+vTotalRec
	vUrl='sch_switch_inner.php'
	ajaxrequest(vUrl,'displaySchoolSwitch', document.getElementById("divSchool"), 0,'POST',vParam);
	return false;
}
function displaySchoolSwitch(txt,obj)
{
	obj.innerHTML=txt
	return false;
}
function pagingSwitch(pmPageNo)
{
	try
	{
		document.frmSchoolSwitch.vCurpage.value = pmPageNo;
		loadSchoolSwitch(document.frmSchoolSwitch,'','');
	}
	catch(Expection)
	{
		ErrorHandling(Expection);
		return false;
	}
}

function paging(pmPageNo)
{
	try
	{
		document.frmSchoolSearch.vCurpage.value = pmPageNo;
		loadingSchPageing(document.frmSchoolSearch,'','');
	}
	catch(Expection)
	{
		ErrorHandling(Expection);
		return false;
	}
}
function resetList(frm)
{
	frm.hidSortName.value=''
	frm.hidSortType.value=''
	frm.txtSearchName.value=''
	frm.sesState.value=''
	frm.sesCity.value=0
	frm.vCurpage.value=''
	frm.hidTotalRec.value=''
	//loadCity(frm.sesState.value)
	loadingSchPageing('','School_Name','ASC')
}
function resetSwitchList(frm)
{
	frm.hidSortName.value=''
	frm.hidSortType.value=''
	frm.txtSearchName.value=''
	//frm.sesCity.value=''
	frm.sesState.value=''
	frm.vCurpage.value=''
	frm.hidTotalRec.value=''
	loadCityInSwitch(frm.sesState.value)
	loadSchoolSwitch('','schl_name','ASC')
}
function loadSchoolDetails(pmId)
{
	document.frmSchoolDetails.shl.value = pmId;
	/*document.frmSchoolDetails.hidSortName.value=document.frmSchoolSearch.hidSortName.value
	document.frmSchoolDetails.hidSortType.value=document.frmSchoolSearch.hidSortType.value
	document.frmSchoolDetails.hidTotalRec.value=document.frmSchoolSearch.hidTotalRec.value
	document.frmSchoolDetails.vCurpage.value=document.frmSchoolSearch.vCurpage.value*/
	document.frmSchoolDetails.submit();
}
function loadSchoolList()
{
	document.frmSchoolList.submit();
}
function validLogin()
{
	frm=document.frmLogin
	if(trim(frm.username.value) == '')
	{
		alert("Please enter your email id!")
		frm.username.focus();		
	}
	else if(!isEmail(frm.username.value))
	{
		alert("Please enter your correct email id!")
		frm.username.focus();
	}
	else if(trim(frm.password.value) == '')
	{
		alert("Please enter your password!")
		frm.password.focus();		
	}
	else
	{
		vUser=frm.username.value;
		vPass=frm.password.value;
		vParam="Email="+vUser+"&Pass="+vPass
		vUrl='sch_login.php'
		ajaxrequest(vUrl,'displaySuccess', document.getElementById("loadReturn"), 0,'POST',vParam);		
	}
}
function displaySuccess(txt,obj)
{
	frm=document.frmLogin
	if(txt == 0)
	{
		alert("inavlid input!")
		frm.username.focus();
	}
	else if(txt == 2)
	{
		alert("Email id not exists!");
		frm.username.focus();
	}
	else if(txt == 3)
	{
		alert("Invalid password!");
		frm.password.focus();
	}
	else if(txt == 4)
	{
		alert("Member not a user for this school!");
		frm.username.focus();
	}
	else if(txt == 5)
	{
		alert("Email id not approved by admin!");
		frm.username.focus();
	}
	else if(txt == 6)
	{
		alert("member inactive!");
		frm.username.focus();
	}
	else if(txt == 7)
	{
		alert("member deleted!");
		frm.username.focus();
	}
	else
	{
		//alert(window.location.href);
		window.location=window.location.href
	}
}
function isEmail(pmStr)
{
	pmStr = trim(pmStr);
	pmStr  = pmStr.replace('\r\n',"");
	pmStr  = pmStr.replace('\n',"");
	if (pmStr == "") return false;
	if (pmStr.length > 50) return false;
	if (!isRegExpSupported()) return (pmStr.indexOf(".") > 2) && (pmStr.indexOf("@") == 1);
	var vPattern = "^[a-z0-9](([_\\.\\-]?[a-z0-9_]+)*)@([a-z0-9]+)(([\\_.\\-]?[a-z0-9]+)*)\\.([a-z]{2,})$";
	var vRegExp = new RegExp(vPattern);
	return (vRegExp.test(pmStr));
}
function isRegExpSupported()
{
	if (window.RegExp)
	{
		var vTempStr = "a";
		var vTempReg = new RegExp(vTempStr);
		return (vTempReg.test(vTempStr));
	}
	return (false);
}
function trim( value ) 
{
	return value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}			
function doEnter(e,frmObj)
{
	var isIE = navigator.userAgent.indexOf("MSIE") != -1; 
	if(!isIE) 
	{
		var pNumKeyCode = e.which
	}
	else
		var pNumKeyCode = (window.event) ? event.keyCode : e.keyCode;
	if(pNumKeyCode == 13)
		validLogin()
}
function loadIndexSearch()
{
	document.frmSearchSchool.action="sch_list.php"
	document.frmSearchSchool.submit()
}
function changeSchool()
{
	frm = document.frmSwitchSch
	vCnt=0;
	vCount=0;
	if(frm.switchs)
	{
		vCount=frm.switchs.length
		if(vCount > 1)
		{
			for(i=0;i<vCount;i++)
			{
				if(frm.switchs[i].checked)
				{
					vId=frm.switchs[i].value
					vCnt++;
				}
			}
		}
		else
		{
			if(frm.switchs.checked)
			{
				vId=frm.switchs.value
				vCnt++;
			}
		}
	}
	if(vCnt > 0)
	{
		document.frmSchSwitch.vShlId.value=vId;
		document.frmSchSwitch.submit();
	}
	else if(vCount >0 && vCnt == 0)
	{
		alert("Please select the school to switch");
	}
}
function selectSchool()
{
	var parFrm;
	frm = document.frmSchTool
	if(window.parent.document.frmSignup)
		parFrm=window.parent.document.frmSignup
	else if(window.parent.document.frmEditProfile)
		parFrm=window.parent.document.frmEditProfile
	else if(window.parent.document.frmPro)
		parFrm=window.parent.document.frmPro
	else if(window.parent.document.frmfundrise)
		parFrm=window.parent.document.frmfundrise	

	vChoice=document.frmSchoolSearch.vChoice.value
	vCnt=0;
	vCount=0;
	var event_flag = 0;
	 
	
	if(frm.switchs)
	{
		vCount=frm.switchs.length;
 		if(vCount > 1)
		{	
			for(i=0;i<vCount;i++)
			{
				if(frm.switchs[i].checked)
				{
					if(parFrm.txtSchoolName)
					{
						vId=frm.switchs[i].value
						if(vChoice == 1)
						{
							parFrm.txtSchoolName.value=frm.name[i].value
							parFrm.sesSchool.value=frm.switchs[i].value
						}
						else if(vChoice == 2)
						{
							parFrm.txtSchoolName2.value=frm.name[i].value
							parFrm.sesSchool2.value=frm.switchs[i].value							
						}
						else if(vChoice == 3)
						{
							parFrm.txtSchoolName3.value=frm.name[i].value
							parFrm.sesSchool3.value=frm.switchs[i].value							
						}
						else
						{
							parFrm.txtSchoolName.value=frm.name[i].value
							parFrm.sesSchool.value=frm.switchs[i].value
						}
						vCnt++;
					}
				}
			}
		}
		else
		{
			vCount=1;
			if(frm.switchs.checked)
			{
				
				if(vChoice == 1)
				{
					parFrm.txtSchoolName.value=frm.name.value
					parFrm.sesSchool.value=frm.switchs.value
				}
				else if(vChoice == 2)
				{
					parFrm.txtSchoolName2.value=frm.name.value
					parFrm.sesSchool2.value=frm.switchs.value							
				}
				else if(vChoice == 3)
				{
					parFrm.txtSchoolName3.value=frm.name.value
					parFrm.sesSchool3.value=frm.switchs.value							
				}
				else
				{
					parFrm.txtSchoolName.value=frm.name.value
					parFrm.sesSchool.value=frm.switchs.value
				}
				vCnt++;
			}
		}
	}
	
	
	if(vCnt > 0)
	{
				
		window.parent.document.getElementById('lightwindow_container').style.display='none'
		window.parent.document.getElementById('lightwindow_overlay').style.display='none'
		//window.parent.document.getElementById('Events').style.display = "none";
		/*if(frm.event_flag.value == 1)
		{
			window.parent.document.getElementById('Events').style.display = "block";
		}*/
		vControls = window.parent.document.getElementsByTagName("select");
		for( vLoop = 0; vLoop < vControls.length; vLoop++ )
		{
			
			vControls[vLoop].style.visibility = "visible";
			if((vControls[vLoop].id == 'sesEventTyp' || vControls[vLoop].id== 'sesEvent') && frm.event_flag.value == 1)
			{
				
				vControls[vLoop].disabled=false
			}
		}
		
	}
	else if(vCount >0 && vCnt == 0)
	{
		alert("Please select the school");
	}
 }
function loadCity(pmState)
{
	document.frmSchoolSearch.sesCity.options.length=0	
	var combobox = document.getElementById("sesCity");
	var anOption = document.createElement("OPTION");
	if(pmState=='')
	{
 		anOption.value = "";
		anOption.text = "--Select city--";
		combobox.options.add(anOption);
	}else
	{
	
	var vParam="vState="+pmState
	vUrl="getschoolcity.php";
	anOption.value = "Loading"
	anOption.text = "Loading..."
	combobox.options.add(anOption)
	ajaxrequest(vUrl,'displayCity', document.getElementById("sesCity"), 0,'POST',vParam);
	}
}
function loadCityInSwitch(pmState)
{
	var vParam="vState="+pmState
	vUrl="getschoolcity.php";
	document.frmSchoolSwitch.sesCity.options.length=0
	var combobox = document.getElementById("sesCity");
	var anOption = document.createElement("OPTION")
	anOption.value = "Loading"
	anOption.text = "Loading..."
	combobox.options.add(anOption)
	ajaxrequest(vUrl,'displayCity', document.getElementById("sesCity"), 0,'POST',vParam);
}

function displayCity(txt,obj)
{
	aCityDetails=txt.split("##");
	vCnt=aCityDetails.length
	if(vCnt > 1)
	{	obj.options.length=0;
		for(i=0;i<aCityDetails.length;i++)
		{
			aCity=aCityDetails[i].split("||")
			var anOption = document.createElement("OPTION")
			anOption.value = aCity[1]
			anOption.text = aCity[0]
			obj.options.add(anOption)
		}
		
	}
	else
	{	obj.options.length=0;
		aCity=txt.split("||")
		var anOption = document.createElement("OPTION")
		anOption.value = aCity[1]
		anOption.text = aCity[0]	
		obj.options.add(anOption)
	}
	//$('sesCity').value = 11330;
}
function listallrec(frm,pmTotal)
{
	vTotal=document.frmSchTool.hidTotalRec.value
	var frmSearch='';
	if(vTotal > pmTotal)
	{
		alert('There are too many records to display on a single page. Please select another option.')
	}
	else
	{
		if(document.frmSchoolDetails)
		{
			vFlag=document.frmSchoolDetails.flag.value
			vType=document.frmSchoolDetails.type.value
		}
		if(frmSearch == '')
			frmSearch=document.frmSchoolSearch;
	
		vSortName=frmSearch.hidSortName.value
		vSortType=frmSearch.hidSortType.value
		var vImg;
		
		if(vSortType == 'DESC')
			vImg="<img src='"+frmSearch.hidImgUrl.value+"zminidown.png' border='0'>"
		if(vSortType == 'ASC')
			vImg="<img src='"+frmSearch.hidImgUrl.value+"zminiup.png' border='0'>"
		
		document.getElementById('School_Name').innerHTML='';
		document.getElementById('School_City').innerHTML='';
		document.getElementById('School_State_abbr').innerHTML='';
		
		document.getElementById(vSortName).innerHTML=vImg
		document.getElementById("divSchool").innerHTML="<span class='loading'>Loading...</span>";
		vName=frmSearch.txtSearchName.value
		vCity=frmSearch.sesCity.value
		
		if(vCity == 0) vCity='';
		vState=frmSearch.sesState.value;
		vCurpage=frmSearch.vCurpage.value;
		//if(vName != '' || vCity !='' || vState != '')
			//vCurpage='';
		
		frmSearch.hidSortName.value = vSortName
		frmSearch.hidSortType.value = vSortType
		vParam="vName="+vName+"&vCity="+vCity+"&vState="+vState+"&vCurpage="+vCurpage+"&vSortName="+vSortName+"&vSortType="+vSortType+"&vTotalRec="+vTotal+"&vFlag="+vFlag+"&vType="+vType+"&vAllCheck=1"
		vUrl='sch_list_inner.php'
		ajaxrequest(vUrl,'displaySchoolList', document.getElementById("divSchool"), 0,'POST',vParam);
		return false;
	}
}

function funDelay(pmRedirectURL)
{
	//alert('test')
	window.setTimeout('window.location="' + pmRedirectURL + '"',1000);
}

function clearTextfield(pmCommentsText)
{
	var vComments = document.frmfundrise.txtcomment.value;
	
	if(vComments == pmCommentsText)
	{
		document.frmfundrise.txtcomment.value = '';
	}
	else if(vComments == '')
	{
		document.frmfundrise.txtcomment.value = pmCommentsText;
	}
}

