/*
 * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function registerProductCallback(){

    var objDiv = document.getElementById("registerProduct");
    var objDataElement = this.req.responseXML.getElementsByTagName("return")[0];
    var strHTML = "<h2>Register product</h2>" +
				"<p>Thank you for downloading WSO2 Web Services Application Server v2.1-RC6.</p>" +
				"<p>Technical information requested will help us improve the product and better serve customer needs. Registration will also help us provide fast and effective support services to our users.</p>" +
				"<p>All information will be sent directly to WSO2. Please note that you will be registered in the WSO2 developer portal <a href=\"http://www.wso2.org\" target=\"_blank\">WSO2 Oxygen Tank</a> in the near future as well.</p>" +
				"<p>Kindly use the form below for registration. Note that registration is entirely voluntary and failure to complete or submit this form will not diminish any rights.</p>" +
				"<p>Also it is not mandatory to fill in all the fields in the form for submission.</p>" +
                  "<div id='formset'>" + "<form method='post' action='https://www.wso2.org/project/wsas/java/1.1/registration.php' target='_blank'>" +
                  "<fieldset style='border: 0px;'>" +
                  "<legend>The following information will be sent to WSO2</legend>" +
                    "<br/>" +
                    "<fieldset>" +
                    "<legend>Java VM</legend>" +
					"<div><label>JRE Name</label><input name='registerProductJavaRuntimeName' type='text' value='" + objDataElement.getElementsByTagName("javaRuntimeName")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"<div><label>Java Version</label><input name='registerProductJavaVersion' type='text' value='" + objDataElement.getElementsByTagName("javaVersion")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"<div><label>Java Vendor</label><input name='registerProductJavaVMVendor' type='text' value='" + objDataElement.getElementsByTagName("javaVMVendor")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"<div><label>Java VM Version</label><input name='registerProductJavaVMVersion' type='text' value='" + objDataElement.getElementsByTagName("javaVMVersion")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"</fieldset>" +
					"<fieldset>" +
					"<legend>Operating system</legend>" +
					"<div><label>OS Name</label><input name='registerProductOsName' type='text' value='" + objDataElement.getElementsByTagName("osName")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"<div><label>OS Version</label><input name='registerProductOsVersion' type='text' value='" + objDataElement.getElementsByTagName("osVersion")[0].firstChild.nodeValue + "' size='50'/></div>" +
					"</fieldset>" + 
					"<fieldset>" +
					"<legend>User</legend>" +
					"<div><label>User Country</label><input name='registerProductUserCountry' type='text' value='" + objDataElement.getElementsByTagName("userCountry")[0].firstChild.nodeValue + "' size='50'/></div>" +
                    "<div><label>Contact First Name</label><input name='registerProductContactFirstName' type='text' value='' size='50'/></div>" +
                    "<div><label>Contact Last Name</label><input name='registerProductContactLastName' type='text' value='' size='50'/></div>" +
                    "<div><label>Contact Email</label><input name='registerProductContactEmail' type='text' value='' size='50'/></div>" +
					"<div><label>Company Name</label><input name='registerProductCompanyName' type='text' value='' size='50'/></div>" +
                    "<div><label>Phone Number</label><input name='registerProductContactPhoneNumber' type='text' value='' size='50'/></div>" +
                    "<div><label>Fax</label><input name='registerProductContactFax' type='text' value='' size='50'/></div>" +
					"<div><label>Address</label><input name='registerProductCompanyAddress' type='text' value='' size='50'/></div>" +
					"<div><label>City</label><input name='registerProductCompanyCity' type='text' value='' size='50'/></div>" +
					"<div><label>State</label><input name='registerProductCompanyState' type='text' value='' size='50'/></div>" +
					"<div><label>Zip</label><input name='registerProductCompanyZip' type='text' value='' size='50'/></div>" +
					"<div><label>Industry</label><input name='registerProductIndustry' type='text' value='' size='50'/></div>" +
					"</fieldset>" +
					"<fieldset>" +
					"<legend>Password</legend>" +
					"<div><label>Password</label><input name='registerProductPassword1' id='registerProductPassword1' type='password' value='' size='50'/></div>" +
					"<div><label>Confirm password</label><input name='registerProductPassword2' id='registerProductPassword2' type='password' value='' size='50'/></div>" +
                    "<br/>" +
					"<div class='buttonrow'><input type='submit' value='Register' onclick='javascript:return sendRegistrationInfo();'/></div>" +
					"</fiedset>" +
                  "</fieldset>" +
                  "</form>" +
                  "</div>";
    objDiv.innerHTML = strHTML;
    wso2.wsf.Util.showOnlyOneMain(objDiv);
}

function reportRegisterProduct(){
    var body_xml = ' <ns1:serverRegistered xmlns:ns1="http://org.apache.axis2/xsd"/>\n';
    
    var callURL = serverURL + "/" + GLOBAL_SERVICE_STRING ;
    new wso2.wsf.WSRequest(callURL,"serverRegistered",body_xml,function(){});
}



function sendRegistrationInfo(){
	if (document.getElementById('registerProductPassword1').value != document.getElementById('registerProductPassword2').value){
		wso2.wsf.Util.alertWarning("Passwords entered do not match.");
		return false;
	}
    reportRegisterProduct();
    var regDiv = document.getElementById('divRegisterProductSuccess');
     regDiv.innerHTML='<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><center><h2>You have successfully registered WSO2 Web Services Application Server v2.1-RC6.</h2></center>';
    userNameString = "<nobr>Signed in as <strong>" + userName + "</strong>&nbsp;&nbsp;|&nbsp;&nbsp;<a id='logOutA' href='#' " +
    		"onclick='javascript:wso2.wsf.Util.logout(wso2.wsf.Util.logout[\"callback\"]); " +
    		"return false;'>Sign Out</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='docs/administratorguide.html'>Help</a></nobr>";
    document.getElementById("meta").innerHTML = userNameString;
    wso2.wsf.Util.showOnlyOneMain(regDiv);
    return true;
}
