//var cpath='http://tringula.com';// live
var cpath;
if(document.domain=='www.tringula.com' || document.domain=='tringula.com'){
	cpath='http://www.tringula.com';	
}
else{
	cpath='http://midas1/tringula/site';		
}

function memberlogin(strURL,formname,responsediv,responsemsg) {
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	/*if(document.MyLoginForm.email.value==''){
		alert('Please enter e-mail id.');
		document.MyLoginForm.email.focus();
		return false;
	}
	if(document.MyLoginForm.password.value==''){
		alert('Please enter password.');
		document.MyLoginForm.password.focus();
		return false;
	}*/
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            updateloginpage(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			updateloginpage(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}
function postForm(strURL,formname,responsediv,responsemsg) 
{
	var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			var responsetxt = self.xmlHttpReq.responseText.split(',');
			if(responsetxt[0]==1){
				window.location='myonlinetests.php';
			}
			else if(responsetxt[0]=='testId'){
				window.location="testquestions.php?testId="+responsetxt[1];	
			}
			else{
				if(self.xmlHttpReq.responseText=='You are not authorized, please do login.'){
					document.getElementById(responsediv).innerHTML = '';
					showPopWin('ajax-login-popup.php', 500, 150	, null);
					return false;
				}
				else{
					document.getElementById(responsediv).innerHTML = self.xmlHttpReq.responseText;
				}
			}
        }
		else{
			getResponse(responsemsg,responsediv);
		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function finishExam(strURL,formname,responsediv,responsemsg) 
{
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            updatepageFinishExam(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			updatepageFinishExam(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function postFormWithRedirect(strURL,formname,responsediv,responsemsg,redirectURL) 
{
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            getResultUsingAjax(self.xmlHttpReq.responseText,responsediv,redirectURL);
        }
		else{
			getResultUsingAjax(responsemsg,responsediv,redirectURL);
		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}
function xmlhttpPost(strURL,formname,responsediv,responsemsg) 
{
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            updatepage(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			updatepage(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function getquerystring(formname) {
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}
function updatepageFinishExam(str,responsediv)
{
	document.getElementById(responsediv).innerHTML = str;
	window.location="examresult.php";
}

function getResultUsingAjax(str,responsediv,redirectURL)
{
	document.getElementById(responsediv).innerHTML = str;
	setTimeout(function(){window.location=redirectURL;}, 1000);
	return false;
}
function updatepage(str,responsediv)
{
	

	var tempStr = str.split('|');
	//reviewRatingForm
	if(tempStr[1]=='reviewRatingForm')
	{
		var redirectURL='review-rating-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='otherSubject')
	{
		var serverURL='ajax_submit/ajax-request.php?moduleType=getUserSubjectList';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){jqueryAjaxRequest(serverURL,'divSpecialization');}, 1000);
	}
	else if(tempStr[1]=='businessNews')
	{
		var redirectURL='announcements.php?type=news&tab=newsTab';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='businessEvents')
	{
		var redirectURL='announcements.php?type=events&tab=eventsTab';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='addScholarship')
	{
		var redirectURL='scholarship-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='addfaculties')
	{
		var redirectURL='faculties-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='businessInstitutes')
	{
		var redirectURL='business-other-features-list.php?institute_id='+tempStr[2]+'&step=2';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='boardOfDirector')
	{
		var redirectURL='board-of-director-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='myClassList')
	{
		var redirectURL='myclasses.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='uploadContents')
	{
		var redirectURL='mycontents.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='experience')
	{
		var redirectURL='experience-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='references')
	{
		var redirectURL='myreferences.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='askExperts')
	{
		var redirectURL='mypostedquestion.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='jobs')
	{
		var redirectURL='postnewjobs.php?next='+tempStr[3]+'&jobid='+tempStr[2]+'';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='OtherAnnouncement')
	{
		var redirectURL='announcements.php?type=other&tab=otherTab';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='educations')
	{
		var redirectURL='education-info-list.php';
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='BusinessJobs')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'jobs/ajax-business-jobs.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='TeachingJobs')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'jobs/ajax-teaching-jobs.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='Teacher')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-paging-get-teacher-list.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='Student')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-paging-get-student-list.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='Institute')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-paging-get-institutes-list.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='School')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-paging-get-schools-list.php','displayMsg');}, 1000);
	}
	else if(tempStr[1]=='Content')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-search-content.php','main_edit_detail');}, 1000);
	}
	else if(tempStr[1]=='Class')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-search-with-paging.php','search_without_login');}, 1000);
	}
	else if(tempStr[1]=='Tests')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'onlinetests/ajax-onlinetests.php','myOnlineTests');}, 1000);
	}
	else if(tempStr[1]=='Inbox')
	{
		document.getElementById(responsediv).innerHTML = tempStr[0];
		setTimeout(function(){pagination(0,'ajax_submit/ajax-inbox.php','displayMessage');}, 1000);
	}
	else if(tempStr[1]=='instituteCourse')
	{
		var redirectURL='courses.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='customSectionBusiness')
	{
		var redirectURL='business-other-features-list.php?step=2&institute_id='+tempStr[2];
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='GalleryMessage')
	{
		//var redirectURL='courses.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		//setTimeout(function(){window.location=redirectURL;}, 1000);*/
		pagination(0,'gallery/ajax-gallery.php','branchList');
		jqueryAjaxRequest('ajax_submit/ajax-request.php?moduleType=galleryCategoryBox','categorySelectBoxDiv');
	}
	else if(tempStr[1]=='ViewAllPhotoMessage')
	{
		//var redirectURL='courses.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		//setTimeout(function(){window.location=redirectURL;}, 1000);*/
		pagination(0,'gallery/ajax-view-allphotos.php','photoListId');
	}
	else if(tempStr[1]=='mypostedjobs')
	{
		//if(tempStr[2]=='Featured')
		//{
			var redirectURL='postjobpriview.php?jobid='+tempStr[3];
		/*}
		else
		{
			var redirectURL='mypostedjobs.php';
		}*/
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='composeMessage')
	{
		var redirectURL='inbox.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='draftMessage')
	{
		var redirectURL='inbox.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='replyMessage')
	{
		var redirectURL='inbox.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='myMatchesTeachersRightIncUpdate')
	{
		//var redirectURL='mysetting-student.php';
		document.getElementById(responsediv).innerHTML = '<span class="orange">'+tempStr[0]+'</span>';
		pagination(0,'mysettings/ajax-matches-teachers.php','resultTeacherClassDiv');
		//document.getElementById('myMatchesRightInc').innerHTML = '';
		//setTimeout(function(){window.location=redirectURL;}, 1000);
	}
	else if(tempStr[1]=='timeZone'){
		document.getElementById(responsediv).innerHTML = tempStr[0];
		document.getElementById(tempStr[3]).innerHTML = tempStr[2];
	}
	else
	{
    	document.getElementById(responsediv).innerHTML = tempStr[0];
		
		/*if(tempStr[0]=='You are not authorized, please do login.')
		{
			document.getElementById(responsediv).innerHTML = '';
			//showPopWin('ajax-login-popup.php', 500, 150	, null);
			//window.location='login.php';
			return false;		
		}
		else
		{
			document.getElementById(responsediv).innerHTML = tempStr[0];
		}*/
	}
}

function updateloginpage(str,responsediv){
	if(str==1)//change-password.php
	{
		window.location=cpath+"/business_contactinfo.php";
	}
	else if(str==2)//personal-information.php
	{
		window.location=cpath+"/edit-personal-info.php";
	}
	else if(str==3)//personal-information.php
	{
		//window.location.replace="http://midas1/tringula/site/edit-personal-info.php";
		window.location=cpath+"/edit-personal-info.php";
	}
	else if(str==5)//become-a-member.php
	{
		window.location=cpath+"/become-a-member.php";
	}
	/*else if(str==4)//contact information
	{
		//window.location="edit-subject.php";
		window.location="profile-edit.php";
	}
	else if(str==0)//profile-edit.php
	{
		window.location="profile-edit.php";
	}*/
	else
	{
		document.getElementById(responsediv).innerHTML = str;
	}
}

function becomeAMember(strURL,formname,responsediv,responsemsg) {
	
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            responseBecomeAMember(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			responseBecomeAMember(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function responseBecomeAMember(str,responsediv)
{
	//business_contactinfo.php
	if(str==1)
	{
		window.location="profile-edit.php";
	}
	else if(str==2)
	{
		window.location="business_contactinfo.php";
	}
	else if(str==3)
	{
		window.location="become-a-member.php";// registration from get an account within miniute
	}
	else if(str==4)
	{
		document.getElementById('myJoinasResult').innerHTML='<span class="orange">Your password has been successfully created.</span>';
		document.getElementById('box_white').style.display='';
	}
	else if(str==5)
	{
		document.getElementById('customFormStepAwayResult').innerHTML='<table width="100%" border="0" cellpadding="1" cellpadding="1"><tr><td colspan="3" align="center" class="orange">Your account has been created successfully.</td></tr><tr><td width="33.33%"><input name="joinas" type="radio" value="Teacher" id="Teacher" onclick="redirectPage(\'Teacher\');" />Teacher</td><td width="33.33%"><input name="joinas" type="radio" value="Student" id="Student"  onclick="redirectPage(\'Student\');"/>Student</td><td width="33.33%"><input name="joinas" type="radio" value="Business" id="Business"  onclick="redirectPage(\'Business\');"/>School/Institute</td>			  </tr></table>';
		document.getElementById('customFormStepAwayAjaxResult').style.display="none";
	}
	else if(str==6)
	{
		window.location="edit-personal-info.php";// registration from get an account within miniute
	}
	else if(str==7)
	{
		window.location='business_contactinfo.php';
	}
	else
	{
    	document.getElementById(responsediv).innerHTML = str;
	}
	
}

function insertContactInfo(strURL,formname,responsediv,responsemsg) {
	
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            responseInsertContactInfo(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			responseInsertContactInfo(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function responseInsertContactInfo(str,responsediv)
{
	if(str==0)
	{
		document.getElementById(responsediv).innerHTML = str;
	}
	else if(str==1)
	{
		window.location="select-subject.php";
	}
}

function contactUs(strURL,formname,responsediv,responsemsg) {
	
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
       
	   if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            responseContactUs(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			responseContactUs(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function responseContactUs(str,responsediv)
{
	if(str!=1)
	{
		document.getElementById(responsediv).innerHTML = str;
	}
	else if(str==1)
	{
		window.location="thanks.php";
	}
}
function getResponse(str,responsediv)
{
	if(str=='You are not authorized, please do login.')
	{
		document.getElementById(responsediv).innerHTML = '';
		window.location='login.php';
		return false;
	}
	else
	{
		document.getElementById(responsediv).innerHTML = str;
	}
}
