/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//Get Context path if any.
var contextPath = document.getElementById('contextPath').value;

function resubmit(formName){
    var form_name = document.forms[formName];
    form_name.action.value = "Resubmit";
    form_name.ajax.value = null;
    form_name.submit();
}
//Set State list of that country
function countryChanged(formName,country){
    callAjax_state_list(contextPath+"/listStates?state_field_name=vendor.state&country=" + this.document.forms[formName][country].value);
    callAjax_currency(contextPath+"/getCurrency?country=" + this.document.forms[formName][country].value)
}

function countryChanged1(formName,country){
    if(country == 'vendorLocationInfo.country'){
        callAjax_state_list(contextPath+"/listStates?state_field_name=vendorLocationInfo.state&country=" + this.document.forms[formName][country].value);
    }else{
        callAjax_state_list(contextPath+"/listStates?state_field_name=vendor.state&country=" + this.document.forms[formName][country].value);
    }
}
//For serch course
function doSearch(formName,courseformName){
    var searchformName = document.getElementById(courseformName).value;
    var searchformAction = contextPath + '/'+ searchformName;
    document.forms[0].action.value = 'Search';
    document.forms[0].pageNumber.value= '1';
    window.location.hash ="ajaxcall";
    document.forms[0].ajax.value="true";
    document.forms[0].checkRecaptcha.value="true";
    var recaptcha = document.getElementById('recaptcha_response_field');
    if(!recaptcha.value == ''){
        document.getElementById('search_result').innerHTML = '<table align="center"><tr> <td style="text-align:center"><img alt="image" src="images/ajax-loader.gif" height="30px"/></td></tr><tr><td style="text-align:center"><b>Searching....</b></td></tr></table>';
    }
    var ele = document.getElementById('search_result');
    ele.focus();
    window.scrollTo(0,0);

    if(recaptcha.value == ''){
        alert("Please enter words!");
        return;
    }
        
    callAjax_search_result(searchformAction, searchformName);

}
function doSearch(formName,courseformName){
    var searchformName = document.getElementById(courseformName).value;
    var searchformAction = contextPath + '/'+ searchformName;
    document.forms[0].action.value = 'Search';
    document.forms[0].pageNumber.value= '1';
    window.location.hash ="ajaxcall";
    document.forms[0].ajax.value="true";
    document.forms[0].checkRecaptcha.value="true";
    var recaptcha = document.getElementById('recaptcha_response_field');
    if(!recaptcha.value == ''){
        document.getElementById('search_result').innerHTML = '<table align="center"><tr> <td style="text-align:center"><img alt="image" src="images/ajax-loader.gif" height="30px"/></td></tr><tr><td style="text-align:center"><b>Searching....</b></td></tr></table>';
    }
    var ele = document.getElementById('search_result');
    ele.focus();
    window.scrollTo(0,0);

    if(recaptcha.value == ''){
        alert("Please enter words!");
        return;
    }
        
    callAjax_search_result(searchformAction, searchformName);

}


function updateLoginSession(formName,cmd, currentPage) {

    if(cmd == "searchVendor" || cmd == "GetPage"){
        var recaptcha = document.getElementById('recaptcha_response_field');
        // var keyword= document.getElementById('keyword');

        // if(!recaptcha.value == '' && !keyword.value==''){
        if(!recaptcha.value == ''){
            document.getElementById('search_result').innerHTML = '<table align="center"><tr> <td style="text-align:center"><img alt="image" src="images/ajax-loader.gif" height="30px"/></td></tr><tr><td style="text-align:center"><b>Searching....</b></td></tr></table>';
        }
        var ele = document.getElementById('search_result');
        ele.focus();
        window.scrollTo(0,0);
        document.forms[formName].elements["command"].value = cmd ;
        document.forms[formName].elements["currentPage"].value = currentPage ;
        document.forms[formName].elements["ajax"].value = "true" ;
        window.location.hash ="ajaxcall";
        if(cmd != "GetPage"){
            if(recaptcha.value == ''){
                alert("Please enter words!");
                return;
            }
            document.forms[formName].elements["checkRecaptcha"].value = "true" ;
        } else {
            document.forms[formName].elements["checkRecaptcha"].value = "false" ;
        }

        callAjax_search_result(contextPath+"/searchVendor");
        callAjax_login(contextPath+"/common/login_details.jsp");
    }
}

function getPage(pageNum){       
    var form_name = window.document.courseSearchForm;
    form_name.action.value = "GetPage";
    form_name.pageNumber.value = pageNum;
    form_name.ajax.value=true;
    callAjax_search_result(contextPath+"/searchStudentCourses");

}
//Sorting columns of serch course result.
function sortByColumn(columnName){
    var form_name = document.forms["courseSearchForm"];
    form_name.action.value = "Search";
    form_name.sortColumnName.value = columnName;
    form_name.ajax.value=true;
    callAjax_search_result(contextPath+"/searchStudentCourses");
}
//provider add course change delivery method
function resubmitCourse(){
    var form_name = window.document.courseDetailsForm;
    form_name.ajax.value = true;
    form_name.action.value = "Resubmit";
    callAjax_search_result(contextPath+"/saveCourse?a_l1_tab=Manage Course&a_l1_menu=Publish Course&a_l2_menu=Add Course&active_menu=Add Course&ajax=true&formatId="+this.document.forms['courseDetailsForm']['course.deliveryMethodId'].value);
    window.location.hash ="ajaxcall";
}

//Serch vendor here.
function doSearchVendor(formName,cmd, currentPage) {

    if(cmd == "searchVendor" || cmd == "GetPage"){
        var recaptcha = document.getElementById('recaptcha_response_field');
        // var keyword= document.getElementById('keyword');

        // if(!recaptcha.value == '' && !keyword.value==''){
        if(!recaptcha.value == ''){
            document.getElementById('search_result').innerHTML = '<table align="center"><tr> <td style="text-align:center"><img alt="image" src="images/ajax-loader.gif" height="30px"/></td></tr><tr><td style="text-align:center"><b>Searching....</b></td></tr></table>';
        }
        var ele = document.getElementById('search_result');
        ele.focus();
        window.scrollTo(0,0);
        document.forms[formName].elements["command"].value = cmd ;
        document.forms[formName].elements["currentPage"].value = currentPage ;
        document.forms[formName].elements["ajax"].value = "true" ;
        window.location.hash ="ajaxcall";
        if(cmd != "GetPage"){
            if(recaptcha.value == ''){
                alert("Please enter words!");
                return;
            }
            document.forms[formName].elements["checkRecaptcha"].value = "true" ;
        } else {
            document.forms[formName].elements["checkRecaptcha"].value = "false" ;
        }

        callAjax_search_result(contextPath+"/searchVendor");
    }
}

function getSelectedOptions(formName,selectItem){
    var i;
    var j = 0;
    var outlist = "";
    for (i = 0; i < document.forms[formName].elements[selectItem].options.length; i++) {
        if (document.forms[formName].elements[selectItem].options[i].selected) {
            if(document.forms[formName].elements[selectItem].options[i].value != ""){
                outlist = outlist + document.forms[formName].elements[selectItem].options[i].value;
                outlist = outlist + ",";
            }
        }
    }
    alert(outlist);
    if(outlist.length > 0){
        return outlist;
    }

}

function countryChangedFromDemandAggregation(){
    callAjax_state_list1(contextPath+"/listStates?state_field_name=user.state&country=" + this.document.forms['demandAggregationForm']['user.country'].value);
}

function countryChangedFromContactProvider(){
    callAjax_state_list(contextPath+"/listStates?state_field_name=contactProvider.state&country=" + this.document.forms['contactProviderForm']['contactProvider.country'].value);
}

function countryChangedFromCaptureStudentInformation(){
    var contextPat = document.getElementById('contextPath').value;
    callAjax_state_list(contextPat+"/listStates?state_field_name=captureStudentInformationInfo.state&country=" + this.document.forms['captureStudentInformationForm']['captureStudentInformationInfo.country'].value);
} 

function countryChanged_common(formName,fieldName){
   
    var country = fieldName + ".country" ;
    if(fieldName == "course"){
        callAjax_state_list(contextPath+"/listStates?state_field_name="+fieldName+".state&country=" + this.document.forms[formName][country].value);
        callAjax_currency(contextPath+"/getCurrency?currency_field_name=course.currency&country=" + this.document.forms['courseDetailsForm']['course.country'].value)
    }else if(fieldName != "onlinePaymentInfo") {
        callAjax_state_list(contextPath+"/listStates?state_field_name="+fieldName+".state&country=" + this.document.forms[formName][country].value);
    }else {
        callAjax_state_list(contextPath+"/listStates?state_field_name="+fieldName+".state&countryCode=" + this.document.forms[formName][country].value);
    } 
}

// serch vendor call function at page loading or reset page.
function doNothing(formName,cmd){   
    document.forms[formName].elements["command"].value = cmd ;
    document.forms[formName].submit();
}
