﻿function GetXmlHttpObject(handler)
{ 
    var objXmlHttp = null;
    if (!window.XMLHttpRequest)
    {
        // Microsoft

        objXmlHttp = GetMSXmlHttp();
        if (objXmlHttp != null)
        {
            objXmlHttp.onreadystatechange = handler;
        }
    } 
    else
    {
        // Mozilla | Netscape | Safari

        objXmlHttp = new XMLHttpRequest();
        if (objXmlHttp != null)
        {
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler;
        }
    } 
    return objXmlHttp; 
} 

function GetMSXmlHttp()
{
    var xmlHttp = null;
    var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
                 "Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", 
                 "Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
                 "Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
    for(var i=0; i<clsids.length && xmlHttp == null; i++) {
        xmlHttp = CreateXmlHttp(clsids[i]);
    }
    return xmlHttp;
}

function CreateXmlHttp(clsid) {
    var xmlHttp = null;
    try {
        xmlHttp = new ActiveXObject(clsid);
        lastclsid = clsid;
        return xmlHttp;
    }
    catch(e) {}
}

function SendXmlHttpRequest(xmlhttp, url) { 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
}

var xmlHttp;

// Execute the server side call
function ExecuteCall(url)
{ 
	try 
	{ 
		xmlHttp = GetXmlHttpObject(CallbackMethod); 
		SendXmlHttpRequest(xmlHttp, url); 
	}
	catch(e){ alert(e);} 
}

// populate country info
function getStateByCountryID(obj, index)
{
    countryID = obj.value;    
    if(countryID > 0)
    {
        countryIndex = index;
	    try
	    {
		    var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?getStates=" + countryID;
		    ExecuteCallForCountry(httpReuest); 
		    
	    }
	    catch(e) { alert(e)}
	}
}

// populate companyInfo
function getCompanyInfo(companyID, controlList)
{
    if(companyID > 0)
    {
	    try
	    {
		    var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?CompanyID=" + companyID + "&ControlList=" + controlList;
		    ExecuteCallForCompany(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

    
function ExecuteAjaxCall(url)
{
    try 
    { 
        //alert(httpHandler)
        xmlHttp = GetXmlHttpObject(SaveControlValues); 
        //alert(xmlHttp)
        SendXmlHttpRequest(xmlHttp, url); 
    }
    catch(e){}     
}

function ExecuteAjaxCallForDelete(url)
{
    try 
    { 
        //alert(httpHandler)
        xmlHttp = GetXmlHttpObject(DeleteHandler); 
        //alert(xmlHttp)
        SendXmlHttpRequest(xmlHttp, url); 
    }
    catch(e){}     
}

function deletecomanyinfo(personcompanyid, index)
{
    companyIndex = index;
    //var personcompanyid = document.getElementById(IDControl).value;
    //alert(personcompanyid)
    if(personcompanyid > 0)
    {
	    try
	    {
	        var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?deletecompanyforperson=yes&personcompanyid=" + personcompanyid;
		    //alert(httpReuest)
		    ExecuteAjaxCallForDelete(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

/* Delete Person web site information  */
function deletPersonWebsiteinfo(personWebsiteID)
{    
    if(personWebsiteID > 0)
    {
	    try
	    {
		    var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?DeletePersonWebsite=" + personWebsiteID;
		    //alert(httpReuest)
		    ExecuteAjaxCallForDeleteWebsite(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

// save person's website information on by ajax call

function SaveWebsiteInformation(saveparam)
{
   
    try
    {
	    var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?PersonWebsite=" + saveparam;		   
	    ExecuteAjaxCall(httpReuest); 
    }
    catch(e) { alert(e)}
	
}


// Set Person's Current Company/University Id
function SetCompanyUniversityInformationInPersonEntity(CompanyORUniversityID)
{    
    if(CompanyORUniversityID > 0)
    {
	    try
	    {
	        var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?CurrentCompanyOrUniversityID=" + CompanyORUniversityID;		   
		    ExecuteAjaxCall(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

function deleteuniversityinfo(personuniversityid, index)
{
    universityIndex = index;
    if(personuniversityid > 0)
    {
	    try
	    {
	        var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?deleteuniversityforperson=yes&personuniversityid=" + personuniversityid;		    
		    ExecuteAjaxCallForDelete(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

function saveuniversityinfo(IDControl, fieldname, fieldvalue)
{
    var personuniversityid = document.getElementById(IDControl).value;
    //alert(personcompanyid)
    if(personuniversityid > 0)
    {
	    try
	    {
	        var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?universityforperson=yes&personuniversityid=" + personuniversityid + "&fieldname=" + fieldname + "&fieldvalue=" + fieldvalue;
		    //alert(httpReuest)
		    ExecuteAjaxCall(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}

    
function savecomanyinfo(IDControl, fieldname, fieldvalue)
{
    var personcompanyid = document.getElementById(IDControl).value;
    //alert(personcompanyid)
    if(personcompanyid > 0)
    {
	    try
	    {
	        var httpReuest = "../Profile/FacultyProfileAjaxHandler.aspx?companyforperson=yes&personcompanyid=" + personcompanyid + "&fieldname=" + fieldname + "&fieldvalue=" + fieldvalue;    
		    //alert(httpReuest)
		    ExecuteAjaxCall(httpReuest); 
	    }
	    catch(e) { alert(e)}
	}
}


// save single value
function saveUserValue(attr, value)
{
	try
	{
		//var httpReuest = "../GMU/HandleAjax.aspx?Attribute=" + attr + "&AppInfoID=0&AttributeValue=" + value;  
		var httpReuest = "../Applications/HandleAjax.aspx?Attribute=" + attr + "&SaveInfo=0&AttributeValue=" + value;    	  		
		ExecuteCall(httpReuest);
	}
	catch(e) { alert(e)}
}

//  save user phone number
function saveUserPhone(attr, value, attr1, value1, attr2, value2)
{
	try
	{
		var httpReuest = "HandleAjax.aspx?SaveInfo=200&Attribute=" + attr + "&AttributeValue=" + value + "&Attribute1=" + attr1 + "&AttributeValue1=" + value1 + "&Attribute2=" + attr2 + "&AttributeValue2=" + value2;    
		ExecuteCall(httpReuest); 
	}
	catch(e) { alert(e)}
}

// save address value on Ajax call with 2 parameter
function saveUserAddressID2(attr, value)
{
	try
	{
		var httpReuest = "HandleAjax.aspx?SaveInfo=300&Attribute=" + attr + "&AttributeValue=" + value;
		ExecuteCall(httpReuest); 
	}
	catch(e) { alert(e)}
}

// save address value on Ajax call with 4 parameter
function saveUserAddressID(attr, value, attr1, value1)
{
	try
	{
		var httpReuest = "HandleAjax.aspx?SaveInfo=300&Attribute=" + attr + "&AttributeValue=" + value + "&Attribute1=" + attr1 + "&AttributeValue1=" + value1;
		ExecuteCall(httpReuest); 
	}
	catch(e) { alert(e)}
}

// save double values
function saveUserDoubleValue(attr, attr1, value)
{
	try
	{
		var httpReuest = "HandleAjax.aspx?Attribute=" + attr + "&Attribute1=" + attr1 + "&AppInfoID=0&AttributeValue=" + value;    
		ExecuteCall(httpReuest); 
	}
	catch(e) { alert(e)}
}

// save university value
function saveUniversityData(attr, value, uniPersonID)
{
	try
	{                
		var httpReuest = "HandleAjax.aspx?Attribute=" + attr + "&AppInfoID=100&RecordNo=" + uniPersonID + "&AttributeValue=" + value;                    
		ExecuteCall(httpReuest);                 
	}
	catch(e) { alert(e)}
}
		
		
// check numeric value
function checkNumeric(val)
{
	var reDt1 = /^[[0-9]*[,]?[0-9]*]*[.[0-9]{0,3}]?$/;     
	var b = reDt1.test(val)
	return b;
}

// save numeric value on Ajax call
function saveNumericValue(attr, value)
{
	var reDt1 = /^[[0-9]*[,]?[0-9]*]*[.[0-9]{0,3}]?$/;
	var b = reDt1.test(value)
	
	if(b)
	{
		saveSingleValue(attr, value);
	}
}

// save checkbox as 0 or 1
function saveCheckboxValue(attr, chkField)
{
	if(chkField.checked)
	{
		saveSingleValue(attr, 1);
	}
	else saveSingleValue(attr, 0);
}

// check numeric value Required
function checkNValue(value)
{
	value = trim(value);
	if(value.length < 1)
	{
		return false;
	}
	if(checkNumeric(value))
	{
		return true;
	}
	return false;
}


// check numeric value Required -- Hayek Fund
function checkHayekAmReqValue(value)
{
	//document.write(parseInt(value));
	value = trim(value);
	if(value.length < 1)
	{
		return false;
	}
	if(!checkNumeric(value))
	{
		return false;
	}
	if(parseInt(value) > 750)
	{
		return false;
	}
	return true;
}


// check numeric value Not Required
function checkNValueNotRequired(value)
{
	value = trim(value);
	if(checkNumeric(value))
	{
		return true;
	}
	return false;
}

// move user to next tab
function ShowNextStep(id)
{
	for(var i=1; i<=10; i++)
	{
		try
		{
			var allObj = document.getElementById("dvStep" + i);              
			allObj.style.display = "none";
		}
		catch(e){ }
	}
	
	var obj = document.getElementById("dvStep" + id);
	obj.style.display = "block";
}		
		
// save person's two db fields value on Ajax call
function saveUserDoubleValueForDropDown(itemID, dbField, dbField1, value)
{
	var conVal = document.getElementById(itemID);
	saveUserDoubleValue(dbField, dbField1, conVal.value);
}

// save person's address on Ajax call
function saveUserAddress(primaryAddressID, secondaryAddressID, isPrimary)
{
	var priObj = document.getElementById(primaryAddressID);
	var secObj = document.getElementById(secondaryAddressID);
	
	if(priObj.value == secObj.value && priObj.value != '')
	{
		if(isPrimary == 0)
		{
			priObj.selectedIndex = 0;
		}
		else
		{
			secObj.selectedIndex = 0;	
		}
		alert("Same address types are not allowed for mailing and permanent/secondary addresses.")
	}	

	saveAllAddresses();
	/*
	if(priObj.value == '')
	{
		return;
	}
	else if(secObj.value == '')
	{
		saveUserAddressID2(priObj.value, PID)
	}
	else if(priObj.value == secObj.value)
	{            
		saveUserAddressID2(priObj.value, PID)
	}
	else
	{
		saveUserAddressID(priObj.value, PID, secObj.value, SID)        
	}
	*/
}    

// save person's phone number on Ajax call
function savePhoneNumber(countryObjID, countryDBField, areaObjID, areaDBField, numberObjID, numberDBField)
{
	var countryObj = document.getElementById(countryObjID);
	var areaObj = document.getElementById(areaObjID);
	var numberObj = document.getElementById(numberObjID);
	
	var countryCode = "1";        
	if (countryObj.value != "")
	{
		countryCode = countryObj.value;
	}
	
	var areaCode = "1";
	if (areaObj.value != "")
	{
		areaCode = areaObj.value;
	}

	if (numberObj.value != "")
	{       
		saveUserPhone(areaDBField, areaCode, countryDBField, countryCode, numberDBField, numberObj.value)        
	}        
}

// save drop down menu's value on Ajax call
function saveUserValueForDropDown(itemID, dbField, value)
{
	var conVal = document.getElementById(itemID);            
	saveUserValue(dbField,conVal.value);
}    

// save drop down menu's text on Ajax call
function saveUserValueForDropDownText(itemID, dbField, value)
{
	var conVal = document.getElementById(itemID);            
	saveUserValue(dbField,conVal.options[conVal.selectedIndex].text);
}     		

// validate Date of Birth and Save on Ajax call
function saveBDateValue(field)
{
	dvst = document.getElementById('dvstartdate'); 
	var startDate = document.getElementById(dobTxtBoxID); 
	var dvBirthdayDatePrompt = document.getElementById('dvBirthdayDatePrompt');   
	if(validateDate(startDate.value))
	{
		saveUserValue(field, startDate.value) 
		dvst.className = "dtwhitebg";                 
		dvBirthdayDatePrompt.innerHTML = "";
		return true;
	}
	else
	{            
		dvBirthdayDatePrompt.innerHTML = "Date of birth is not valid.";
		dvst.className = "dtgreybg";                
		return false;
	}
}  		
		
		
function SavePostData(attribute, fckObjID, recordId, appInfoID)
{
    var xhr;
    if (window.XMLHttpRequest)     // Object of the current windows
    { 
        xhr = new XMLHttpRequest();     // Firefox, Safari, ...
    } 
    else 
    if (window.ActiveXObject)   // ActiveX version
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    }
    xhr.open("POST", "HandleAjax.aspx", true); 
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
    xhr.send("Attribute=" + attribute + "&fckValueData=" + replaceCharacter(FCKeditorAPI.GetInstance(fckObjID).GetXHTML(true)) + "&RecordNo=" + recordId + "&AppInfoID=" + appInfoID);
}	

function replaceCharacter(val)
{
    while(val.indexOf("<") >= 0)
    {
        val = val.replace("<","!~1~!");
    }     
    while(val.indexOf(">") >= 0)
    {
        val = val.replace(">","!~2~!");
    } 	
    while(val.indexOf("&") >= 0)
    {
        val = val.replace("&","!~3~!");
    } 	
    while(val.indexOf("'") >= 0)
    {
        val = val.replace("'","!~4~!");
    } 	
	
	return val;
}


function UniCallbackMethod() 
{ 
	try
	{
		if (xmlHttp.readyState == 4 || 
			xmlHttp.readyState == 'complete')
		{
			var response = xmlHttp.responseText; 
			if (response.length > 0)
			{
				//alert(response.value)
				//update page
				//var label = document.getElementById('<%=lblText.ClientID %>');
				//if(response.value != "1")
				//{
				//   label.innerHTML = res.value;            
				//} 
			} 
		}
	}
	catch(e){}
}

function saveUniversityOnAjaxWithParam(uniPersonObjID, appInfoID, personUniversityID, universityName, universityID, otherUniversityID, firstMajor, firstMajorSpec, secondMajor, secondMajorSpec, degree, location, cgpa, cgpaOutOf, isCgpa, courseStartYear, courseStartMonth, courseEndYear, courseEndMonth, gradYear, gradMonth)
{
	if(trim(universityID) == "" || trim(universityID) < 0)
	{
		return; 	
	}
	var formData = "appInfoID=" + appInfoID +  "&personUniversityID=" + personUniversityID  +  "&universityName=" + universityName +  "&universityID=" + universityID +  "&otherUniversityID=" + otherUniversityID;
	formData = formData + "&firstMajor=" + firstMajor + "&firstMajorSpec=" + firstMajorSpec + "&secondMajor=" + secondMajor + "&secondMajorSpec=" + secondMajorSpec; 
	formData = formData + "&degree=" + degree + "&location=" + location + "&cgpa=" + cgpa + "&cgpaOutOf=" + cgpaOutOf + "&isCgpa=" + isCgpa;  	
	formData = formData + "&courseStartYear=" + courseStartYear + "&courseStartMonth=" + courseStartMonth + "&gradYear=" + gradYear + "&gradMonth=" + gradMonth; 		
	formData = formData + "&courseEndMonth=" + courseEndMonth + "&courseEndYear=" + courseEndYear;
	
	
	/*ExecuteCallForUniversity("HandleAjax.aspx?" + formData);*/
	
    var xhr;
    if (window.XMLHttpRequest)     // Object of the current windows
    { 
        xhr = new XMLHttpRequest();     // Firefox, Safari, ...
    } 
    else 
    if (window.ActiveXObject)   // ActiveX version
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    }
    xhr.open("POST", "HandleAjax.aspx", true); 
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	
	xhr.onreadystatechange = function() 
	{
		if(xhr.readyState == 4 && xhr.status == 200) 
		{
			var val = xhr.responseText;
			if(val.indexOf("end") > 0)
			{
				if(parseInt(val.substring(0,val.indexOf("end"))) > 0)
				{
					document.getElementById(uniPersonObjID).value = val.substring(0,val.indexOf("end"));
				}
			}
		}
	}

	xhr.send(formData);	
	//ExecutePostCall("HandleAjax.aspx", formData)
}


function saveExternalReview(recordNo, fieldname, fieldvalue)
{
	var formData = "fieldValue=" + fieldvalue +  "&fieldName=" + fieldname  +  "&itemId=" + recordNo;
	formData = formData + "&externalreview=yes"; 		

	var xhr;
	if (window.XMLHttpRequest)     // Object of the current windows
	{ 
		xhr = new XMLHttpRequest();     // Firefox, Safari, ...
	} 
	else 
	if (window.ActiveXObject)   // ActiveX version
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
	}
	xhr.open("POST", "HandleAjax.aspx", true); 
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	
	xhr.onreadystatechange = function() 
	{
		if(xhr.readyState == 4 && xhr.status == 200) 
		{
			var val = xhr.responseText;
		}
	}

	xhr.send(formData);	
}


function saveAddressOnAjaxWithParam(primaryType, secondaryType, primaryAdd1, primaryAdd2, primaryCity, primaryState, primaryZip, primaryCountry, secondaryAdd1, secondaryAdd2, secondaryCity, secondaryState, secondaryZip, secondaryCountry)
{
	//alert(primaryType + " :" + secondaryType + " :" + primaryAdd1 + " :" + primaryAdd2 + " :" + primaryCity + " :" + primaryState + " :" + primaryZip + " :" + primaryCountry + " :" + secondaryAdd1 + " :" + secondaryAdd2 + " :" + secondaryCity + " :" + secondaryState + " :" + secondaryZip + " :" + secondaryCountry)
	var formData = "primaryType=" + primaryType +  "&secondaryType=" + secondaryType  +  "&primaryAdd1=" + primaryAdd1 +  "&primaryAdd2=" + primaryAdd2 +  "&primaryCity=" + primaryCity;
	formData = formData + "&primaryState=" + primaryState + "&primaryCountry=" + primaryCountry + "&secondaryAdd1=" + secondaryAdd1 + "&secondaryAdd2=" + secondaryAdd2; 
	formData = formData + "&secondaryCity=" + secondaryCity + "&secondaryState=" + secondaryState + "&secondaryCountry=" + secondaryCountry + "&primaryZip=" + primaryZip + "&secondaryZip=" + secondaryZip;
	formData = formData + "&adddress=yes"; 		

	
	
	/*ExecuteCallForUniversity("HandleAjax.aspx?" + formData);*/
	
    var xhr;
    if (window.XMLHttpRequest)     // Object of the current windows
    { 
        xhr = new XMLHttpRequest();     // Firefox, Safari, ...
    } 
    else 
    if (window.ActiveXObject)   // ActiveX version
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    }
    xhr.open("POST", "HandleAjax.aspx", true); 
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	
	xhr.onreadystatechange = function() 
	{
		if(xhr.readyState == 4 && xhr.status == 200) 
		{
			var val = xhr.responseText;
			/*if(val.indexOf("end") > 0)
			{
				if(parseInt(val.substring(0,val.indexOf("end"))) > 0)
				{
					document.getElementById(uniPersonObjID).value = val.substring(0,val.indexOf("end"));
				}
			}
			*/
		}
	}

	xhr.send(formData);	
	//ExecutePostCall("HandleAjax.aspx", formData)
}


function savePlacementInfo(appid, cannotAttendList, orderList, idList)
{
	//alert(primaryType + " :" + secondaryType + " :" + primaryAdd1 + " :" + primaryAdd2 + " :" + primaryCity + " :" + primaryState + " :" + primaryZip + " :" + primaryCountry + " :" + secondaryAdd1 + " :" + secondaryAdd2 + " :" + secondaryCity + " :" + secondaryState + " :" + secondaryZip + " :" + secondaryCountry)
	var formData = "appid=" + appid +  "&cannotAttendList=" + cannotAttendList  +  "&orderList=" + orderList +  "&idList=" + idList;
	formData = formData + "&placement=yes"; 		

	
	
	/*ExecuteCallForUniversity("HandleAjax.aspx?" + formData);*/
	
    var xhr;
    if (window.XMLHttpRequest)     // Object of the current windows
    { 
        xhr = new XMLHttpRequest();     // Firefox, Safari, ...
    } 
    else 
    if (window.ActiveXObject)   // ActiveX version
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    }
    xhr.open("POST", "HandleAjax.aspx", true); 
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	
	xhr.onreadystatechange = function() 
	{
		if(xhr.readyState == 4 && xhr.status == 200) 
		{
			var val = xhr.responseText;
		}
	}

	xhr.send(formData);	
}

function ExecuteCallForUniversity(url)
{ 
	try 
	{ 
		xmlHttp = GetXmlHttpObject(UniCallbackMethod); 
		SendXmlHttpRequest(xmlHttp, url); 
	}
	catch(e){} 
}
