function reg_form(){

//        pas1 = document.getElementById('pass1').value;
//        pas2 = document.getElementById('pass2').value;
        company = document.getElementById('company').value;
        name = document.getElementById('name').value;
        email = document.getElementById('mail').value;
        email2 = document.getElementById('mail2').value;
        position = document.getElementById('position').value;
        address = document.getElementById('address').value;
        phone = document.getElementById('phone').value;
        zip = document.getElementById('zip').value;
        city = document.getElementById('city').value;
        country = document.getElementById('country').value;
        
        if( (email != email2) || ( email == "") ){
                alert("The Email that you have provided doesn't match the confirmation or one Email was not entered");
                return false;
        }
/*        
        if( (pas1 != pas2) || ( pas1 == "") ){
                alert("The password that you have provided doesn't mach the confirmation or one password was not entered");
                return false;
        }
*/
        if(phone == false){
                alert("Please enter your company phone number");
                return false;
        }

        if(address == false){
                alert("Please enter your street address");
                return false;
        }

        if(zip == false){
                alert("Please enter your ZIP/Postcode");
                return false;
        }

        if(company == false){
                alert("Please enter your company name");
                return false;
        }
        
        if(country == false){
                alert("Please state your country");
                return false;
        }
        
        if(city == false){
                alert("Please enter your town/city and/or region");
                return false;
        }

        if(name == false){
                alert("Please enter your name");
                return false;
        }

        var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
        var regexp = new RegExp(emailReg);
        if(regexp){
                if(!regexp.test(email)){
                        alert("Your e-mail is invalid -- " + email);
                        return false;
                }
        }
        
        if(position == false){
                alert("Please state your position at " + company);
                return false;
        }

        document.reg.submit();
}

function submit_form()
{
        document.acnt.submit();
}

function maint_form(){

        pas1 = document.getElementById('pass1').value;
        pas2 = document.getElementById('pass2').value;
//      company = document.getElementById('company').value;
//      name = document.getElementById('name').value;
//      email = document.getElementById('mail').value;
        position = document.getElementById('position').value;
        address = document.getElementById('address').value;
        phone = document.getElementById('phone').value;
        zip = document.getElementById('zip').value;
        city = document.getElementById('city').value;
        country = document.getElementById('country').value;
        
        if( (pas1 != pas2) || ( pas1 == "") ){
                alert("The password that you have provided doesn't mach the confirmation or one password was not entered");
                return false;
        }

        if(phone == false){
                alert("Please enter your company phone number");
                return false;
        }

        if(address == false){
                alert("Please enter your street address");
                return false;
        }

        if(zip == false){
                alert("Please enter your ZIP/Postcode");
                return false;
        }

//      if(company == false){
//              alert("Please enter your company name");
//              return false;
//      }
        
        if(country == false){
                alert("Please state your country");
                return false;
        }
        
        if(city == false){
                alert("Please enter your town/city and/or region");
                return false;
        }

//      if(name == false){
//              alert("Please enter your name");
//              return false;
//      }

//      var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
//      var regexp = new RegExp(emailReg);
//      if(regexp){
//              if(!regexp.test(email)){
//                      alert("Your e-mail is invalid -- " + email);
//                      return false;
//              }
//      }
        
        if(position == false){
                alert("Please state your position");
                return false;
        }

        document.acnt.submit();
}

function validate_radio(frm, btnName){
        var btn = frm[btnName]
        var valid
                        
        for (var x = 0;x < btn.length; x++){
                valid = btn[x].checked
                if (valid) {
                        break
                }
        }
        if(!valid){
                return false;
        }else{
                return true;
        }
}

function add_asset(kind,must_agree){
        desc = document.getElementById('description').value;
        id = document.getElementById('identifier').value;
        url = document.getElementById('url').value;
        url4 = url.substr(0,4);
        url4 = url4.toUpperCase();
        urlColon = url.indexOf(":");
        edr = document.getElementById('edr').value;
        edr4 = edr.substr(0,4);
        edr4 = edr4.toUpperCase();
        edrColon = edr.indexOf(":");
        if(must_agree == true){
                agree = document.getElementById('agree').checked;
        }
//        oil = document.getElementById('play[oil]').checked;
//        gas = document.getElementById('play[gas]').checked;
//        condensate = document.getElementById('play[condensate]').checked;
//        cbm = document.getElementById('play[cbm]').checked;
//        shale_gas = document.getElementById('play[shale_gas]').checked;
//        tar = document.getElementById('play[tar]').checked;
        
        if(document.getElementById("lat_degree").value != false || document.getElementById("lat_minute").value != false &&
           document.getElementById("lon_degree").value != false || document.getElementById("lon_minute").value != false){
                lat = document.getElementById("sel_lat").value + " " + document.getElementById("lat_degree").value + " " + document.getElementById("lat_minute").value;
                lon = document.getElementById("sel_lon").value + " " + document.getElementById("lon_degree").value + " " + document.getElementById("lon_minute").value;
                ar = lon.split(" ");
                lon_c = eval(ar[1] + "+" + (ar[2]/60));
                if(ar[0] == "W"){
                        lon_c = "-" + lon_c;
                }
                ar = lat.split(" ");
                lat_c = eval(ar[1] + "+" + (ar[2]/60));
                if(ar[0] == "S"){
                        lat_c = "-" + lat_c;
                }
                document.getElementById("c_x").value = lon_c;
                document.getElementById("c_y").value = lat_c;
        }
        
        if(id == false){
                alert("Project identifier is needed!");
                return false;
        }

        if(!validate_radio(document.asset,"deal")){
                alert("Please select the type of deal");
                return false;
        }
        if(kind == "1"){
                if(!validate_radio(document.asset,"tasset")){
                        alert("Please select the type of project.");
                        return false;
                }
                if(!validate_radio(document.asset,"location")){
                        alert("Please select the location.");
                        return false;
                }
 //               if(oil==false && gas==false && condensate==false && cbm==false && shale_gas==false && tar==false){
 //                       alert("Please select at least one type of play.");
 //                       return false;
 //               }
        }
        
        if(desc == false){
                alert("A short description is needed!");
                return false;
        }
        
        if(desc.length > 1000){
                alert("Description exceeds 1000 charachters!");
                return false;
        }
        
        if(url4=="HTTP"){
                alert("Company URL must be without the \"http://\" part.");
                return false;
        }
        
        if(urlColon>=0 && urlColon < 6){
                alert("Protocol specification not allowed in the Company URL.");
                return false;
        }
        
        if(edr4=="HTTP"){
                alert("EzDataRoom URL must be without the \"http://\" part.");
                return false;
        }
        
        if(edrColon>=0 && edrColon < 6){
                alert("Protocol specification not allowed in the EzDataRoom URL.");
                return false;
        }
        
        if(must_agree && agree == false){
                alert("You must agree to our Terms and Conditions of use.");
                return false;
        }

        document.getElementById("submit_button").value="Storing...";
        document.asset.submit();
}

function gmap(){
        var map = new GMap(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.centerAndZoom(new GPoint(41.831543,11.573283), 16);
        return map;
}

function createMarker(point, size, number, company, identifier, url) {
        
        // Create our marker icon
        var icon = new GIcon();
        if (url!='')
                icon.image = "i/mm_50_red.png";
        else
                icon.image = "i/mm_50_red.png";
        icon.shadow = "i/mm_50_shadow.png";
        icon.iconSize = new GSize(size, size*1.5);
        icon.shadowSize = new GSize(size*2, size*1.5);
        icon.iconAnchor = new GPoint(size/2,size*3/2);      // new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(size/2, size/2);

        var marker = new GMarker(point,icon);
        var first5 = company.substring(0,5);
        var html,html2,html3;
        if (first5 == "Zebra")
                html = '<b>'+company+'</b>: '+identifier;
        else
//                html = '<b>'+company+'</b>: '+identifier+'<br><a href="?ez=details&id='+ number + '" title="Click to see details for this project">See details</a>';
                html = '<b>'+company+'</b>: '+identifier+'<br><br><center><input type="button" name="Button" value="See details" onClick="window.location=\'?ez=details&id='+ number + '\'"></center>';
        if (url!='')
        {
                if (first5 == "Zebra")
                {
                        html2 = '<b>'+company+'</b>: '+identifier+'<br><center><a href="http://'+url+'" target="_blank" title="Click to open Web Link">Open web link</a></center>';
                        html3 = '<b>'+company+'</b>: '+identifier+'<br><center><a href="http://'+url+'" target="_blank" title="Click to go to the Online EzDataroom"><image src="data_room_32c_192.png" height="26" width="72" alt="Open EzDataRoom"></a></center>';

                } else
                {
        //                html2 = '<b>'+company+'</b>: '+identifier+'<br><a href="?ez=details&id='+ number + '" title="Click to see details for this project">See details</a>&nbsp;&nbsp;<a href="http://'+url+'" target="_blank" title="Click to open Web Link">Open web link</a>';
                        html2 = '<b>'+company+'</b>: '+identifier+'<br><center><table><tr><td><input type="button" name="Button" value="See details" onClick="window.location=\'?ez=details&id='+ number + '\'"></td><td>&nbsp;&nbsp;<a href="http://'+url+'" target="_blank" title="Click to open Web Link">Open web link</a></td></tr></table></center>';
        //                html3 = '<b>'+company+'</b>: '+identifier+'<br><a href="?ez=details&id='+ number + '" title="Click to see details for this project">See details</a>&nbsp;&nbsp;<a href="http://'+url+'" target="_blank" title="Click to go to the Online EzDataroom"><image src="data_room_32c_192.png" height="17" width="48" alt="Open EzDataRoom"></a>';
                        html3 = '<b>'+company+'</b>: '+identifier+'<br><center><table><tr><td><input type="button" name="Button" value="See details" onClick="window.location=\'?ez=details&id='+ number + '\'"></td><td>&nbsp;&nbsp;<a href="http://'+url+'" target="_blank" title="Click to go to the Online EzDataroom"><image src="data_room_32c_192.png" height="26" width="72" alt="Open EzDataRoom"></a></td></tr></table></center>';
                }
                var address = url.substring(0,4);
        
                if (address == "ezda" ||
                    address == "webd" ||
                    address == "onli" ||
                    address == "live")
                {
                        GEvent.addListener(marker, "click", function() {
                                marker.openInfoWindowHtml(html3);
                        });
                } else
                {
                        GEvent.addListener(marker, "click", function() {
                                marker.openInfoWindowHtml(html2);
                        });
                }
        } else
        {
                GEvent.addListener(marker, "click", function() {
                        marker.openInfoWindowHtml(html);
                });
        }

        return marker;
}

function test_co(){
        document.getElementById('map').style.display = "block";
        var map = new GMap(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        //x = document.getElementById("x").value;
        //y = document.getElementById("y").value;
        lat = document.getElementById("sel_lat").value + " " + document.getElementById("lat_degree").value + " " + document.getElementById("lat_minute").value;
        lon = document.getElementById("sel_lon").value + " " + document.getElementById("lon_degree").value + " " + document.getElementById("lon_minute").value;
        ar = lon.split(" ");
        lon_c = eval(ar[1] + "+" + (ar[2]/60));
        if(ar[0] == "W"){
                lon_c = "-" + lon_c;
        }
        ar = lat.split(" ");
        lat_c = eval(ar[1] + "+" + (ar[2]/60));
        if(ar[0] == "S"){
                lat_c = "-" + lat_c;
        }
        //alert("LAT" + lat_c + " LON: " + lon_c);

        point = new GPoint(lon_c,lat_c);
        var marker = new GMarker(point);
        var html = '<b>Your project</b>';
        GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(html);
        });
        map.centerAndZoom(point, 12);
        map.addOverlay(marker);
}
