// JavaScript Document

//-->
/// <reference path="../messboxcss.css" />



function validate_webform(formType, sucessurl) {

    var Company, Contactname, Email, Phoneno, Postcode, Mobile, Address;
    
    
    Company=document.getElementById('txtcompany').value;
    Contactname=document.getElementById('txtcontactname').value;
    Email=document.getElementById('txtemail').value;
    phoneno=document.getElementById('txtphoneno').value;
    Postcode=document.getElementById('txtpostcode').value;

    Mobile = document.getElementById('txtmobile').value;
    Address = document.getElementById('txtaddress').value;

    
    
    

    if (Company=='' || Contactname=='' || Email=='' || phoneno=='' || Postcode=='') {
        var dialog = new pop_dialog();
        dialog.show_message('Error',
                'Please provide us with your company details.<br><br>'
                + 'The Mandatory fields are <b>CompanyName,Contactname, Phone No and Post Code</b>.');
                

        //alert('Please provide us with your details.\nThe Mandatory fields are CompanyName,Contactname, Phone No, House No and Post Code');
                      
        return false;
    } else {

    submitrequest(formType, sucessurl);
    return true;
    }
     
   }



   function submitNewsLetterSubscribtion() {

       var Company, Contactname, Email;

       Company = document.getElementById('txtNLCompany').value;
       Contactname = document.getElementById('txtNLName').value;
       Email = document.getElementById('txtNLEmail').value;

       //validate

       if (Contactname == '' || Email == '') {

           var dialog = new pop_dialog();
           dialog.show_message('Error ',
                'Please provide us with your valid details to subscribe newsletter.<br><br>'
                + 'The Mandatory fields are <b>Contactname and Email</b>.');
           return false;
       } else {

       var url;
       url = 'ajaxhandler.ashx?form=nl&company=' + Company + '&contactname=' + Contactname + '&email=' + Email + '';
              submitonserver(url, '');

       var dialog = new pop_dialog();
       dialog.show_message('Sucess...',
                'You have been subscribed for Compare Companies newsletter.<br><br>'
                + '<b>Thank you for showing intrest in our services</b>.');

       showhidedivs('divtext', 'divNLform');
       return true;
       }
       
   
   }





function submitrequest(formType,sucessurl) {

    //Check Validate

        
    
        var Company, Contactname, Email, Phoneno, Postcode, Mobile, Address;
        var Other_ind_requirement='';
        Company = document.getElementById('txtcompany').value;
        Contactname = document.getElementById('txtcontactname').value;
        Email = document.getElementById('txtemail').value;
        phoneno = document.getElementById('txtphoneno').value;
        Postcode = document.getElementById('txtpostcode').value;

        Mobile = document.getElementById('txtmobile').value;
        Address = document.getElementById('txtaddress').value;

        try {
            Other_ind_requirement = document.getElementById('txtrequirement').value;
        }
        catch (Error) {
            // do nothing
            Other_ind_requirement = '';
        }

        //document.getElementById('btnsubmit').style.display = "none";

        if (Email != null) {
            if (validateEmailid(Email) == false) { Email = ''; }
        }

        var datasource;

        //datasource='ajaxhandler.ashx?type=jb&fname='+fname+'&em='+em+'&con='+con+'&pcd='+pcd+'&mob='+mob+'&dur='+dur+'&lname='+lname+'&jarea='+jobarea+'&typeofwork='+typeofwork+'&hno='+hno+''+companystring ;
        datasource = 'ajaxhandler.ashx?form=' + formType +'&company=' + Company + '&contactname=' + Contactname + '&email=' + Email + '&phoneno=' + phoneno + '&postcode=' + Postcode + '&mobile=' + Mobile + '&address=' + Address + '&req=' + Other_ind_requirement + '';
        //alert(datasource);

        submitonserver(datasource, sucessurl);
       
        return true;   

}




function submitsupplierForm(formType, sucessurl) {

    var Company, Contactname, Email, Phoneno, Postcode, Mobile, Address,City,Industry,Comment;
    
    Company = document.getElementById('txtcompany').value;
    Contactname = document.getElementById('txtContactname').value;
    Address = document.getElementById('txtaddress').value;	
	City = document.getElementById('txtcity').value;
	Postcode = document.getElementById('txtpostcode').value;
	Email = document.getElementById('txtemail').value;
    Phoneno = document.getElementById('txtphoneno').value;
	
	Industry = document.getElementById('txtindustry').value;
	Comment = document.getElementById('txtcomment').value;
        
    
    //validate

	if (Company == '' || Contactname == '' || City == '' || Phoneno == '' || Email == '') {
		    var dialog = new pop_dialog();
			dialog.show_message('Error',
                'Please provide us with your correct company details.<br><br>'
                + 'The Mandatory fields are <b>CompanyName,Contact name, City,Address,Emailid , Phone No and Post Code</b>.');
			return false;
		}
	

    
    //document.getElementById('btnsubmit').style.display = "none";

    if (Email != null) {
        if (validateEmailid(Email) == false) { Email = ''; }
    }

    var datasource;

    //datasource='ajaxhandler.ashx?type=jb&fname='+fname+'&em='+em+'&con='+con+'&pcd='+pcd+'&mob='+mob+'&dur='+dur+'&lname='+lname+'&jarea='+jobarea+'&typeofwork='+typeofwork+'&hno='+hno+''+companystring ;
    datasource = 'ajaxhandler.ashx?form=' + formType + '&company=' + Company + '&Contactname=' + Contactname + '&email=' + Email + '&phoneno=' + Phoneno + '&postcode=' + Postcode + '&city=' + City + '&address=' + Address + '&industry=' + Industry + '&comment=' + Comment + '';
    //alert(datasource);

    submitonserver(datasource, sucessurl);

    return true;

}




var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function submitonserver(datasource,sucessurl) {
    if (XMLHttpRequestObject) {
        XMLHttpRequestObject.open("GET", datasource);

        XMLHttpRequestObject.onreadystatechange = function() {
            if (XMLHttpRequestObject.readyState == 4 &&
              XMLHttpRequestObject.status == 200) {
               
              if (sucessurl!=''){
                window.location=sucessurl;
              }else{
               // window.location='requestsent.aspx';
              }

             }
        }

        XMLHttpRequestObject.send(null);
    }


}





function jb(datasource) {
    var tiddatasource;
    tiddatasource = document.getElementById('jbno').innerHTML;
    tiddatasource = datasource+tiddatasource;

    if (XMLHttpRequestObject) {
        XMLHttpRequestObject.open("GET", tiddatasource);


        XMLHttpRequestObject.send(null);
    }


}

function UpdateQuestions() {
    var DtDeliveryDate, dtDateofCollection, Leadid;
    var opt1, opt2, opt3, opt4, opt5, opt6;
    var skipsizeselected;
    opt1 = document.getElementById('rbtnoption1').checked;
    opt2 = document.getElementById('rbtnoption2').checked;
    opt3 = document.getElementById('rbtnoption3').checked;
    opt4 = document.getElementById('rbtnoption4').checked;
    opt5 = document.getElementById('rbtnoption5').checked;
    opt6 = document.getElementById('rbtnoption6').checked;

    skipsizeselected = document.getElementById('lblSkipSize')


    Leadid = document.getElementById('jbno').innerHTML;


    var url = "ajaxhandler.ashx?type=q&q1="+opt1+"&q2="+opt2+"&q3="+opt3+"&q4="+opt4+"&q5="+opt5+"&q6="+opt6+"&tid="+Leadid;

    if (opt1 == true) {
        skipsizeselected.innerHTML = '2 Cubic Yard Mini skip';
        showhideskipsizes(1);
    }
    else if (opt2 == true) {
        skipsizeselected.innerHTML = '4 Cubic Yard Mini skip';
        showhideskipsizes(2);
    }
    else if (opt3 == true) {
        skipsizeselected.innerHTML = '6 Cubic Yard Mini skip';
        showhideskipsizes(3);
    }
    else if (opt4 == true) {
        skipsizeselected.innerHTML = '8 Cubic Yard Mini skip';
        showhideskipsizes(4);
    }
    else if (opt5 == true) {
        skipsizeselected.innerHTML = '10 Cubic Yard Mini skip';
        showhideskipsizes(5);
    }
    else if (opt6 == true) {
        skipsizeselected.innerHTML = '12 Cubic Yard Mini skip';
        showhideskipsizes(6);
    }
    else {
        skipsizeselected.innerHTML = 'You have not selected any skip size';

    }


    if (XMLHttpRequestObject) {
        XMLHttpRequestObject.open("GET", url);

        XMLHttpRequestObject.onreadystatechange = function() {
            if (XMLHttpRequestObject.readyState == 4 &&
              XMLHttpRequestObject.status == 200) {



            }
        }

        XMLHttpRequestObject.send(null);
    }




    showhidedivs('divcompaniesSelectedList', 'questiontable');
    //window.location='confirmrequestsubmit.aspx';

}

function assignbusiness(coname) {
    var businessname, Leadid;
    businessname = document.getElementById(coname).value;
    Leadid = document.getElementById('ddDateofPrefferedCollection_textBox').value;

    Leadid = document.getElementById('jbno').innerHTML;


    var url = "ajaxhandler.ashx?type=assignbusiness&deldate="+DtDeliveryDate+"&coldate="+dtDateofCollection+"&deliveryadd="+DeliveryAddress+"&tid="+Leadid;

    if (XMLHttpRequestObject) {
        XMLHttpRequestObject.open("GET", url);

        XMLHttpRequestObject.onreadystatechange = function() {
            if (XMLHttpRequestObject.readyState == 4 &&
              XMLHttpRequestObject.status == 200) { }
        }

        XMLHttpRequestObject.send(null);
    }




    //showhidedivs('divcompaniesSelectedList','questiontable');                
    window.location = 'http://comparecompanies.co.uk/confirmrequestsubmit.aspx';

}



function Updateorderdetails() {
    var DtDeliveryDate, dtDateofCollection, Leadid, DeliveryAddress;
    DtDeliveryDate = document.getElementById('ddDateofDelivery_textBox').value;
    dtDateofCollection = document.getElementById('ddDateofPrefferedCollection_textBox').value;
    DeliveryAddress = document.getElementById('txtDeliveryAddress').value;

    Leadid = document.getElementById('jbno').innerHTML;


    var url = "ajaxhandler.ashx?type=order&deldate="+DtDeliveryDate+"&coldate="+dtDateofCollection+"&deliveryadd="+DeliveryAddress+"&tid="+Leadid;

    if (XMLHttpRequestObject) {
        XMLHttpRequestObject.open("GET", url);

        XMLHttpRequestObject.onreadystatechange = function() {
            if (XMLHttpRequestObject.readyState == 4 &&
              XMLHttpRequestObject.status == 200) { }
        }

        XMLHttpRequestObject.send(null);
    }




    //showhidedivs('divcompaniesSelectedList','questiontable');                
    window.location = 'http://comparecompanies.co.uk/confirmrequestsubmit.aspx';

}

function validateEmailid(mailids) {
    var arr = new Array('.com', '.net', '.org', '.biz', '.coop', '.info', '.museum', '.name', '.pro'
, '.edu', '.gov', '.int', '.mil', '.ac', '.ad', '.ae', '.af', '.ag', '.ai', '.al',
'.am', '.an', '.ao', '.aq', '.ar', '.as', '.at', '.au', '.aw', '.az', '.ba', '.bb',
'.bd', '.be', '.bf', '.bg', '.bh', '.bi', '.bj', '.bm', '.bn', '.bo', '.br', '.bs',
'.bt', '.bv', '.bw', '.by', '.bz', '.ca', '.cc', '.cd', '.cf', '.cg', '.ch', '.ci',
'.ck', '.cl', '.cm', '.cn', '.co', '.cr', '.cu', '.cv', '.cx', '.cy', '.cz', '.de',
'.dj', '.dk', '.dm', '.do', '.dz', '.ec', '.ee', '.eg', '.eh', '.er', '.es', '.et',
'.fi', '.fj', '.fk', '.fm', '.fo', '.fr', '.ga', '.gd', '.ge', '.gf', '.gg', '.gh',
'.gi', '.gl', '.gm', '.gn', '.gp', '.gq', '.gr', '.gs', '.gt', '.gu', '.gv', '.gy',
'.hk', '.hm', '.hn', '.hr', '.ht', '.hu', '.id', '.ie', '.il', '.im', '.in', '.io',
'.iq', '.ir', '.is', '.it', '.je', '.jm', '.jo', '.jp', '.ke', '.kg', '.kh', '.ki',
'.km', '.kn', '.kp', '.kr', '.kw', '.ky', '.kz', '.la', '.lb', '.lc', '.li', '.lk',
'.lr', '.ls', '.lt', '.lu', '.lv', '.ly', '.ma', '.mc', '.md', '.mg', '.mh', '.mk',
'.ml', '.mm', '.mn', '.mo', '.mp', '.mq', '.mr', '.ms', '.mt', '.mu', '.mv', '.mw',
'.mx', '.my', '.mz', '.na', '.nc', '.ne', '.nf', '.ng', '.ni', '.nl', '.no', '.np',
'.nr', '.nu', '.nz', '.om', '.pa', '.pe', '.pf', '.pg', '.ph', '.pk', '.pl', '.pm',
'.pn', '.pr', '.ps', '.pt', '.pw', '.py', '.qa', '.re', '.ro', '.rw', '.ru', '.sa',
'.sb', '.sc', '.sd', '.se', '.sg', '.sh', '.si', '.sj', '.sk', '.sl', '.sm', '.sn',
'.so', '.sr', '.st', '.sv', '.sy', '.sz', '.tc', '.td', '.tf', '.tg', '.th', '.tj',
'.tk', '.tm', '.tn', '.to', '.tp', '.tr', '.tt', '.tv', '.tw', '.tz', '.ua', '.ug',
'.uk', '.um', '.us', '.uy', '.uz', '.va', '.vc', '.ve', '.vg', '.vi', '.vn', '.vu',
'.ws', '.wf', '.ye', '.yt', '.yu', '.za', '.zm', '.zw');
    var mai = mailids;
    var val = true;

    var dot = mai.lastIndexOf(".");
    var ext = mai.substring(dot, mai.length);
    var at = mai.indexOf("@");
    var dom = dot - at;
    var sp = mai.indexOf(" ");

    if (dom >= 4 && at > 1 && sp == -1) {
        for (var i = 0; i < arr.length; i++) {
            if (ext == arr[i]) {
                val = true;
                break;
            }
            else {
                val = false;
            }
        }
        if (val == false) {
            //alert("Your Emaild "+mai+" is not corrrrect");
            return false;
        }
    }
    else {
        //alert("Your maild "+mai+" is not correct");
        return false;
    }
    return true;
}
