﻿function RunMe(URL)
{
    eval(URL);
};
String.format = function(){ if( arguments.length == 0 ) return null;
var str = arguments[0];
for(var i=1;i<arguments.length;i++){
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    } return str; 
};
function format(str)
{for(i=0;i<arguments.length;i++)
{var re=new RegExp('\\{'+(i)+'\\}','gm');str=str.replace(re,arguments[i+1]);}
return str;}
function MultiSelectControl()
{this.ControlSuffix="NewMultiSelect";this.Name=new Array();this.Value=new Array();this.Width="30px";this.DropDownWidth="44px";this.DropDownHeight="60";this.BackgroundColor="#ffffff";this.PicturePath="pics";this.TextColor="#000000";this.WatermarkText="Select Values...";this.FontSize="8pt";this.drawInto=function(DivName,HiddenField)
{var innerHTML="";if(this.Name&&this.Name.length>0)
{var requiredHeight=(this.Name.length+1)*18;if(requiredHeight<this.DropDownHeight)
this.DropDownHeight=requiredHeight;innerHTML=format('<table id="idMultiSelectCombo_{0}" cellspacing="2px" style="border: 1px solid #BBB; width:{1}; height:20px;'+'margin: 0;padding:0" onclick="ExpandMe(\'dropDownBox_{0}\',\'{2}\');">'+'<tr> <td> <div id="idListBox_{0}" style="width: {1}; overflow: hidden; white-space: nowrap; font-size:{4}; margin:0px; padding:0px" nowrap="nowrap"'+'unselectable="on" ></div> </td>'+'<td style="width: 12px" id="idDivTable_{0}">'+'<img id="idComboButton_{0}" src="{3}/dropdwn_arrw.gif" align="absmiddle" alt=""'+' unselectable="on" /> </td></tr></table>',this.ControlSuffix,this.Width,this.DropDownHeight,this.PicturePath,this.FontSize);var dropDownDivString=format("<div id='dropDownBox_{0}' onmouseover=\"OnDivOver('{0}')\" onmouseout=\"OnDivOut('{0}');\" "+" style='z-index:100; height:{2}px;color:{4};width:{1}; position: absolute; background-color:{3}; "+"display: none;border: solid 1px gray; padding:0; margin:0;overflow:auto;overflow-y: auto;overflow-x:hidden;' >"+"<table style='height:100%; width:100%; border-collapse:collapse' cellspacing='0px' cellpadding='0'>",this.ControlSuffix,this.DropDownWidth,this.DropDownHeight,this.BackgroundColor,this.TextColor);innerHTML=innerHTML+dropDownDivString;var SelectAllCheckBoxString=format("<tr style='overflow:hidden;cursor: pointer;' id='ListTD_{0}_All' onmouseover=\"OnTdOver('{0}_All','{4}','{5}')\""+" onmouseout=\"OnTdOut('{0}_All','{4}','{5}')\" nowrap='nowrap' onclick=\"OnCheckAll('{0}','{2}','{3}','{6}')\"  ><td style='width:24px'>"+" <input type='checkbox' id='{0}_Check_All' onclick=\"ToggleCheckBox('{0}_Check_All')\" /></td><td>"+" <span id='SPAN_{0}_All' style='font-family: tahoma,helvetica,verdana;font-size:{7}; ' unselectable='on'>"+" All</span></td> </tr>",this.ControlSuffix,this.Width,this.Name.length,HiddenField,this.BackgroundColor,this.TextColor,this.WatermarkText,this.FontSize);innerHTML=innerHTML+SelectAllCheckBoxString;for(icount=0;icount<this.Name.length;icount++)
{var sName=this.Name[icount];var sValue=this.Value[icount];var SelectCheckBoxString=format("<tr style='overflow:hidden;cursor: pointer;' id=\"ListTD_{0}_{4}\" onmouseover=\"OnTdOver('{0}_{4}','{7}','{8}')\""+" onmouseout=\"OnTdOut('{0}_{4}','{7}','{8}')\" nowrap='nowrap' "+" onclick=\"CheckRelatedCheckBox('{0}_Check_{4}','{0}','{2}','{3}','{9}')\" ><td style='width:24px'>"+" <input type='checkbox' id='{0}_Check_{4}' onclick=\"ToggleCheckBox('{0}_Check_{4}')\" name='{5}' value='{6}'/></td><td>"+" <span id='SPAN_{0}_{4}' style='font-family: tahoma,helvetica,verdana; overflow:hidden; white-space:nowrap;z-index:100;"+"  font-size:{10}; cursor: pointer;' unselectable='on'>"+"{5}</span></td> </tr>",this.ControlSuffix,this.Width,this.Name.length,HiddenField,icount,sName,sValue,this.BackgroundColor,this.TextColor,this.WatermarkText,this.FontSize);innerHTML=innerHTML+SelectCheckBoxString;}
innerHTML=innerHTML+"</table></div>";}
document.getElementById(DivName).innerHTML=innerHTML;if(this.Name.length>0)
{setInitListBox(this.ControlSuffix,this.Name.length,HiddenField,this.WatermarkText);}}}
var oMultiSelectComboBox=false;var SelectedDropDown_ID=null;function ExpandMe(dropDownDivName,DropDownHeight)
{var dropDownDiv=document.getElementById(dropDownDivName);if(dropDownDiv)
{if(dropDownDiv.style.display=="none")
{if(SelectedDropDown_ID!==null&&SelectedDropDown_ID!==dropDownDivName)
{var oldSelectedDropDown=document.getElementById(SelectedDropDown_ID);oldSelectedDropDown.style.display="none";}
SelectedDropDown_ID=dropDownDivName;ExpandDropDown(1,dropDownDivName,DropDownHeight);}
else
{SelectedDropDown_ID=null;dropDownDiv.style.display="none";}}}
function CollapseDropDown(dropDownDivName)
{var dropDownDiv=document.getElementById(dropDownDivName);if(dropDownDiv!==null&&dropDownDiv.style.display!=="none")
dropDownDiv.style.display="none";}
function ExpandDropDown(iHeight,dropDownDivName,DropDownHeight)
{var dropDownDiv=document.getElementById(dropDownDivName);dropDownDiv.style.display="block";iHeight+=24.4;var functionname="ExpandDropDown("+iHeight+",'"+dropDownDiv.id+"',"+DropDownHeight+")";if(iHeight<=DropDownHeight+25)
{window.setTimeout(functionname,2);}}
function CheckValueExist(ArrayOfValues,Value)
{for(x in ArrayOfValues)
if(ArrayOfValues[x]==Value)
return true;return false;}
function setInitListBox(ComName,TotalCount,ValueBox,WaterMarkText)
{var oAllCheckBox=document.getElementById(ComName+"_Check_All");var oCmdList=document.getElementById("idListBox_"+ComName);var selectedbox=document.getElementById(ValueBox);var ComboBoxId=document.getElementById("idMultiSelectCombo_"+ComName);var SelectedValues=new Array();if(selectedbox.value!=="")
SelectedValues=selectedbox.value.split(",");var TotalValuesSelected=0;RemoveAll(oCmdList,selectedbox);for(var i=0;i<TotalCount;i++)
{var oTempCheckBox=document.getElementById(ComName+"_Check_"+i);if(CheckValueExist(SelectedValues,oTempCheckBox.value))
{TotalValuesSelected++;oTempCheckBox.checked=true;if(oCmdList.innerHTML=="")
{oCmdList.innerHTML=oTempCheckBox.name;selectedbox.value=oTempCheckBox.value;ComboBoxId.title="Selected Values:\n\r"+oTempCheckBox.name;}
else
{oCmdList.innerHTML+=", "+oTempCheckBox.name;selectedbox.value+=","+oTempCheckBox.value;ComboBoxId.title+=",\n"+oTempCheckBox.name;}}
else
oTempCheckBox.checked=false;}
if(TotalValuesSelected==TotalCount)
oAllCheckBox.checked=true;if(selectedbox.value=="")
{oCmdList.style.color="#A0A0A0";oCmdList.innerHTML=WaterMarkText
ComboBoxId.title="Selected Values:\n\r None"}
else
{oCmdList.style.color=document.getElementById("idMultiSelectCombo_"+ComName).style.color;}}
function setMainListBox(ComName,TotalCount,ValueBox,WaterMarkText)
{var oAllCheckBox=document.getElementById(ComName+"_Check_All");var oCmdList=document.getElementById("idListBox_"+ComName);var selectedbox=document.getElementById(ValueBox);var ComboBoxId=document.getElementById("idMultiSelectCombo_"+ComName);RemoveAll(oCmdList,selectedbox);for(var i=0;i<TotalCount;i++)
{var oTempCheckBox=document.getElementById(ComName+"_Check_"+i);if(oTempCheckBox.checked==true)
{if(oCmdList.innerHTML=="")
{oCmdList.innerHTML=oTempCheckBox.name;selectedbox.value=oTempCheckBox.value;ComboBoxId.title="Selected Values:\n\r"+oTempCheckBox.name;}
else
{oCmdList.innerHTML+=", "+oTempCheckBox.name;selectedbox.value+=","+oTempCheckBox.value;ComboBoxId.title+=",\n"+oTempCheckBox.name;}}}
if(selectedbox.value=="")
{oCmdList.style.color="#A0A0A0";oCmdList.innerHTML=WaterMarkText;ComboBoxId.title="Selected Values:\n\r None";}
else
{oCmdList.style.color=document.getElementById("idMultiSelectCombo_"+ComName).style.color;}}
function RemoveAll(ListBoxId,SelectedValuesBox)
{ListBoxId.innerHTML="";SelectedValuesBox.value="";}
function CheckRelatedCheckBox(CheckBoxId,ComName,TotalCount,ValueBox,WaterMarkText)
{ToggleCheckBox(CheckBoxId);var oAllCheckBox=document.getElementById(ComName+"_Check_All");if(oAllCheckBox.checked==true&&document.getElementById(CheckBoxId).checked==false)
{oAllCheckBox.checked=false;}
var bAllChecked=true;for(var i=0;i<TotalCount;i++)
{var oTempCheckBox=document.getElementById(ComName+"_Check_"+i);if(oTempCheckBox.checked==false)
{bAllChecked=false;}}
if(bAllChecked==true)
{oAllCheckBox.checked=false;OnCheckAll(ComName,TotalCount,ValueBox,WaterMarkText);return true;}
setMainListBox(ComName,TotalCount,ValueBox,WaterMarkText);}
function ToggleCheckBox(CheckBoxId)
{document.getElementById(CheckBoxId).checked=!document.getElementById(CheckBoxId).checked;}
function OnCheckAll(ComName,TotalCount,ValueBox,WaterMarkText)
{var oAllCheckBox=document.getElementById(ComName+"_Check_All");ToggleCheckBox(ComName+"_Check_All");for(var i=0;i<TotalCount;i++)
{var oTempCheckBox=document.getElementById(ComName+"_Check_"+i);oTempCheckBox.checked=oAllCheckBox.checked;}
setMainListBox(ComName,TotalCount,ValueBox,WaterMarkText);}
function IsDropDownExpanded(ComName)
{var dropDownDiv=document.getElementById("dropDownBox_"+ComName);if(dropDownDiv.style.display=="block")
{return true;}
else
{return false;}}
function validateMultiSelectCombo(sName,bSupressMessage,ComName)
{var idMainListBox=document.getElementById("idListBox_"+ComName);if(idMainListBox.length==0||idMainListBox.options[0].value=="-1")
{if(bSupressMessage==null||bSupressMessage==false)
{alert("The "+sName+" field is blank. Please enter a value.");}
return false;}
return true;}
function GetDataListFromMultiSelectCombo(ComName)
{var idMainListBox=document.getElementById("idListBox_"+ComName);var sValue="";for(var i=0;i<idMainListBox.length;i++)
{if(sValue!=="")
{sValue+=";"}
sValue+=idMainListBox.options[i].value;}
return sValue;}
function OnDivOver()
{oMultiSelectComboBox=true;}
function OnDivOut()
{oMultiSelectComboBox=false;}
document.onmousedown=function MouseDown(event)
{if(oMultiSelectComboBox==false)
{var elementName="";if(!event)
{if(window.event.srcElement)
elementName=window.event.srcElement.id;}
else
{if(event.target)
elementName=event.target.id;}
if(SelectedDropDown_ID!==null&&elementName.indexOf("idComboButton_")<0&&elementName.indexOf("idListBox_")<0&&elementName.indexOf("idDivTable_")<0)
{CollapseDropDown(SelectedDropDown_ID);SelectedDropDown_ID=null;}}
return true;}
function OnTdOver(controlId,back,front)
{var oTDCntrl=document.getElementById("ListTD_"+controlId);var oSpanCntrl=document.getElementById("SPAN_"+controlId);oTDCntrl.bgColor="#0000CC";oSpanCntrl.style.color="#FFFFFF";return true;}
function OnTdOut(controlId,back,front)
{var oTDCntrl=document.getElementById("ListTD_"+controlId);var oSpanCntrl=document.getElementById("SPAN_"+controlId);oTDCntrl.bgColor=back;oSpanCntrl.style.color=front;return true;}
var SearchResultJsonObject = null;
function initSearchPage()
{
	MultiSelectInit();
};
function initMultiSelect(DivName, DivHiddenControl, DivWaterMark, NameArray, ValueArray, Width, DropDownWidth, PicturePath,Height, InitialValue)
{
    var MultiSelectControlItem = new MultiSelectControl();
    MultiSelectControlItem.Width = Width;
    // MultiSelectControlItem.DropDownWidth = DropDownWidth;
    MultiSelectControlItem.WatermarkText= DivWaterMark;
    MultiSelectControlItem.ControlSuffix =DivName;
    MultiSelectControlItem.DropDownHeight = Height;
    MultiSelectControlItem.Name = NameArray;
    MultiSelectControlItem.Value = ValueArray;
    MultiSelectControlItem.PicturePath = PicturePath;
    if(InitialValue!=null)
        document.getElementById(DivHiddenControl).value = InitialValue;
    MultiSelectControlItem.drawInto(DivName,DivHiddenControl);
}
function MultiSelectInit()
{
	var BranchArray = ['Electrical & Electronics Engineering','Chemical Engineering','Civil Engineering','Computer Science Engineering','Information Technology','MCA','Mechanical Engineering','Others'];
	var BranchValueArray = [1,2,3,4,5,6,7,255];
    initMultiSelect('RegionSelected','RegionSelectedValue','Select Region',new Array("Punjab","Rajasthan","Karnataka","Haryana"), new Array(1,2,3,4), '200px','220px', 'pics',75,[1,2]);
    initMultiSelect('GraduationYearSelected','GraduationYearSelectedValue','Graduation Year',new Array(2008,2009,2010), new Array(1,2), '200px','220px', 'pics',75,[1,2]);
    initMultiSelect('DegreeSelected','DegreeSelectedValue','Select Programme',new Array("B.E. / B.Tech","MCA", "MBA", "B.Sc.", "B.A.", "BBA"), new Array(1,2,3,4,5,6), '200px','220px', 'pics',75,[1,2,3]);
    initMultiSelect('BranchSelected','BranchSelectedValue','Select Branch',BranchArray, BranchValueArray, '200px','220px', 'pics',75,[1,2,3,5]);
}
function flashsliderchange(divId, start,end)
{
	$('#'+divId+'range').html("("+parseFloat(start) + " to " + parseFloat(end)+")");
	$('#'+divId+'HiddenID').val(parseFloat(start)+ ',' + parseFloat(end));
}
function flashsliderSinglechange(divId, start,end)
{
	$('#'+divId+'range').html(parseFloat(end));
	$('#'+divId+'HiddenID').val(parseFloat(start)+ ',' + parseFloat(end));
}
function MakeResultVisible()
{
	var Region=$('#RegionSelectedValue').val();
    var Batch= $('#GraduationYearSelectedValue').val();
    var Degree=$('#DegreeSelectedValue').val();
    var Branch=$('#BranchSelectedValue').val();
    var SliderE=$('#sliderEYDivrange');
    var Slider10th=$('#slider10thDivrange');
    var Slider12th=$('#slider12thDivrange');
    var SliderFinal=$('#sliderFinalYearDivrange');
    var SliderBLog=$('#sliderBLDivrange');
    if(Region!="" && Batch!="" && Degree!="" && Branch!="")
    {		  
		  $.post("WebServices/CommonService.asmx/SearchStudents",{"Region":Region,"Batch":Batch,"Degree":Degree,"Branch":Branch,"Establish":SliderE.html(),
		    "TenthMks":Slider10th.html(),"TwelthMks":Slider12th.html(),"FinalMks":SliderFinal.html(),"Backlogs":SliderBLog.html()},RunMe);
	}
}

function DisplaySearchResults(ResultJsonString)
{
	 if(ResultJsonString!=null)
	 {
		  var JsonObject = eval("("+ ResultJsonString + ")");
		  $('#TotalCollegeSelectedDiv').html("0");
		  $('#TotalStudentAvailable').html("0");
		  $('#ResultBranchSelected').html(JsonObject.Branches);
		  RenderTable(JsonObject.Results, JsonObject.OrderBy);    
		  $('#NoSelectionMadeDiv').hide();
		  $('#ResultAvailableDiv').show();
	 }
}

function RenderTable(TableData, OrderBy)
{
    if(TableData && TableData.length && TableData.length>0)
    {
	     SearchResultJsonObject = TableData;
	     var ResultInnerHTML = new Array();
              ResultInnerHTML.push('<table cellspaceing="5px"><thead><tr style="background-color:#204757; color:#ffffff;height:25px;"><td></td><td>&nbsp;</td><td>College</td><td style="width:70px; text-align:center;">Established</td><td style="width:70px; text-align:center;">Students</td></tr></thead><tbody>');
	     for(var i=0;i<TableData.length;i++)
	     {
		      var JsonItem = TableData[i];
		      ResultInnerHTML.push(String.format('<tr><td style="width:50px" ><input type="checkbox" onclick="SelectCheckBox({0})" id="CollegeSelectCB{0}">'+
									     '</td><td style="width:75px"><img width="75px" style="padding:0;margin:0; vertical-align:middle" alt="Logo" src="{1}">'+
									     '</td><td style="text-align:left;" ><a href="{6}" target="_blank">{2}</a></td><td style="text-align:left; width:70px; text-align:center;" >{4}</td><td style="width:70px; text-align:center;"><strong>{3}</strong></td></tr>',
									     i,JsonItem.ImageUrl, JsonItem.Name,
									     JsonItem.TotalStudents, JsonItem.Established, JsonItem.checked, 
									     JsonItem.website));
	     }
         ResultInnerHTML.push('</tbody></table>');
	     if(TableData.length>0)
	     {
		     $('#SearchResultDiv').html(ResultInnerHTML.join(""));
		     for(var j=0;j<TableData.length;j++)
		     {
				    $("#CollegeSelectCB"+j).attr("checked",TableData[j].checked);
		     }
	     }
	 }
}

function changeValue(changeDiv)
{
	 var value = new Array(2);
	 value[0]= 3;
	 value[1] = 4;
	 changeDiv.tag.setValue(value);
}

function SelectCheckBox(id)
{    
    var collegediv = $('#TotalCollegeSelectedDiv');
    var studentdiv = $('#TotalStudentAvailable');
    var SelectedCollegesId = $('#CollegeSelectedValue');
    var nocolleges=parseInt(collegediv.html());
    var cnostudents=parseInt(studentdiv.html());
    var SelectedCB = $('#CollegeSelectCB'+ id);
    
    if(SelectedCB.attr("checked"))
    {
        nocolleges++;
        cnostudents+=parseInt(SearchResultJsonObject[id].TotalStudents);
        SelectedCollegesId.val(SelectedCollegesId.val() + "[" + SearchResultJsonObject[id].CollegeId + "]");
        SearchResultJsonObject[id].checked="true";
    }
    else 
    {
        if(nocolleges>0)
        {
            nocolleges--;
            cnostudents-=parseInt(SearchResultJsonObject[id].TotalStudents);
            SelectedCollegesId.val(SelectedCollegesId.val().replace("[" + SearchResultJsonObject[id].CollegeId + "]", ""));
            SearchResultJsonObject[id].checked="";
        }
    }
    collegediv.html(nocolleges.toString());
    studentdiv.html(cnostudents.toString());
    if(nocolleges>0)
			$('#PayPostDiv').show();
	else
			$('#PayPostDiv').hide();
}    

function doAllChecks(obj)
{
    var rowcount=document.getElementById('resulttable').rows.length;
        for(var i=0; i<rowcount; i++)            
        {
            var checkbox = $('#RTcheckbox_'+i);
            if(checkbox.attr("checked")!=obj.checked)
            {
                checkbox.attr("checked",$('#'+obj).attr("checked"));
                SelectCheckBox(checkbox);
            }
        }                      
}
