/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("RegExpValEmail").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
function chkAvailibility()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var email = document.getElementById('txtEmail').value;
    if(email == '')
    {
        document.getElementById("RegExpValEmail").innerHTML = "<font color='red'>Email should not be blank</font>";
        return false;
    }
    else
    {
        
        var url="checkemail.php";
        url=url+"?q="+email;
        url=url+"&sid="+Math.random();
        xmlhttp.onreadystatechange=stateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}
function chkFields()
{
    var pass = document.getElementById('txtpass').value;
    var pass1 = document.getElementById('txtconfirmpass').value;
    var chk = document.getElementById('chkagree').checked;
    var email = document.getElementById('txtEmail').value;
    var name = document.getElementById('txtName').value;
    var company = document.getElementById('txtcmpname').value;
    var mob = document.getElementById('txtMobileNo').value;
	document.getElementById("ReqFildValPassword").innerHTML =  "";
	document.getElementById("cmpvldtrpassword").innerHTML = "";
    var flag = 0;
    if(name == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML =  "Name should not be blank";
        return false;
    }
    if(company == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Company should not be blank";
        return false;
    }
    if(mob == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Mobile should not be blank";
        return false;
    }
	if(mob.length != 10)
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Mobile should be 10 digit";
        return false;
    }
    if(email == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Email should not be blank";
        return false;
    }
    if(pass == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Password should not be blank";
        return false;
    }        
    if(pass1 == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Confirm password should not be blank";
        return false;
    }
    if(pass != pass1)
    {        
        document.getElementById("cmpvldtrpassword").innerHTML = "Password and Confirm Password should be same";
        return false;
    }
    if(!chk)
    {
        alert("You can't go further if you are not agree with our terms and condition");
        return false;
    }   
    return true;
}
function chkFieldsEdit()
{

    var pass = document.getElementById('txtpass').value;
    var pass1 = document.getElementById('txtconfirmpass').value;    
    var email = document.getElementById('txtEmail').value;
    var name = document.getElementById('txtName').value;
    var company = document.getElementById('txtcmpname').value;
    var mob = document.getElementById('txtMobileNo').value;
    var flag = 0;
    if(name == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML =  "Name should not be blank";
        return false;
    }
    if(company == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Company should not be blank";
        return false;
    }
    if(mob == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Mobile should not be blank";
        return false;
    }
	if(mob.length != 10)
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Mobile should be 10 digit";
        return false;
    }
    if(email == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Email should not be blank";
        return false;
    }
    if(pass == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Password should not be blank";
        return false;
    }        
    if(pass1 == '')
    {
        document.getElementById("ReqFildValPassword").innerHTML = "Confirm password should not be blank";
        return false;
    }
    if(pass != pass1)
    {        
        document.getElementById("cmpvldtrpassword").innerHTML = "Password and Confirm Password should be same";
        return false;
    }
   
    return true;

}
function login()
{
   document.submit();
}
    function checksell()
	{
	
    var ctype = document.getElementById('txtVerityType').value;
    var squnty = document.getElementById('txtSellQunatity').value;
    var payment = document.getElementById('txtPayment').value;
	var country = document.getElementById('ddlcountry').value;
	var price = document.getElementById('txtPrice').value;
    var msg = "Page refer following error(s).\n";
    var flag = 0;
    //alert("Into the Function");
    if(ctype == '')
    {
        msg = msg + "- Enter cotton type\n";
        //alert("Into the Function");
        flag = 1;
    }
    if(squnty == '')
    {
        msg = msg + "- Enter sell quantity\n";
        flag = 1;
    }        
    if(payment == '')
    {
        msg = msg + "- Enter payment mode\n";
        flag = 1;
    }
	if(country == '')
    {
        msg = msg + "- Select Country\n";
        flag = 1;
    }
	if(price == '')
	{
		msg = msg + "- Enter Price\n";
        flag = 1;
	}
    if(flag == 1)
    {
        alert(msg);
        return false;
    }
    else
        return true;

}
function checkbuy()
{
    var ctype = document.getElementById('txtVerityType').value;
    var squnty = document.getElementById('txtBuyQunatity').value;
    var payment = document.getElementById('txtPayment').value;
	var country=document.getElementById('ddlcountry').value;
	var price = document.getElementById('txtPrice').value;
    var msg = "Page refer following error(s).\n";
    var flag = 0;
    //alert("Into the Function");
    if(ctype == '')
    {
        msg = msg + "- Enter cotton type\n";
        //alert("Into the Function");
        flag = 1;
    }
    if(squnty == '')
    {
        msg = msg + "- Enter buy quantity\n";
        flag = 1;
    }
    if(payment == '')
    {
        msg = msg + "- Enter payment mode\n";
        flag = 1;
    }
	if(country == '')
	{
		msg = msg + "- Select Country\n";
        flag = 1;	
	}
	if(price == '')
	{
		msg = msg + "- Enter Price\n";
        flag = 1;
	}
    if(flag == 1)
    {
        alert(msg);
        return false;
    }
    else
        return true;
}
String.prototype.trim = function()
{
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}
function adminFormValidation()
{
    var form = document.getElementById('formtype').value;
    if(form == "changepassword")
    {
        //alert(form);
        var oldPassword = document.getElementById('txtOldpassword').value.trim();
        document.getElementById('txtOldpassword').value = oldPassword;
        var newPassword = document.getElementById('txtNewpassword').value.trim();
        document.getElementById('txtNewpassword').value = newPassword;
        var verifyPassword = document.getElementById('txtConfirmpassword').value.trim();
        document.getElementById('txtConfirmpassword').value = verifyPassword;
        clearErrMsg();
        var flag = 0;
        if(oldPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtOldpasswordrev').innerHTML = 'Please Enter Old Password';            
            flag = 1;
        }
        else if(oldPassword.length < 6 || oldPassword.length > 20)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtOldpasswordrfv').innerHTML = 'Password should be 6 to 20 charactors';
            flag = 1;
        }
       

        if(newPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtNewpasswordrev').innerHTML = 'Please Enter New Password';
            flag = 1;
        }
        else if(newPassword.length < 6 || newPassword.length > 20)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtNewpasswordrfv').innerHTML = 'Password should be 6 to 20 charactors';
            flag = 1;
        }
          

        if(verifyPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtConfirmpasswordrfv').innerHTML = 'Please Enter Confirm Password';
            flag = 1;
        }
        else if(verifyPassword != newPassword)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtconfirmpasswordcmp').innerHTML = 'New and Confirm Password should be same';
            flag = 1;
        }      
        
        if(flag)
            return false;
        else
            return true;
    }
    return false;
}
function clearErrMsg()
{
    document.getElementById('vldtxtOldpasswordrev').innerHTML = '';
    document.getElementById('vldtxtOldpasswordrfv').innerHTML = '';
    document.getElementById('vldtxtNewpasswordrev').innerHTML = '';
    document.getElementById('vldtxtNewpasswordrfv').innerHTML = '';
    document.getElementById('vldtxtConfirmpasswordrfv').innerHTML = '';
    document.getElementById('vldtxtConfirmpasswordcmp').innerHTML = '';

    return true;
}
function changePasswordVal()
{
        var oldPassword = document.getElementById('txtOldpassword').value.trim();
        document.getElementById('txtOldpassword').value = oldPassword;
        var newPassword = document.getElementById('txtNewpassword').value.trim();
        document.getElementById('txtNewpassword').value = newPassword;
        var verifyPassword = document.getElementById('txtConfirmpassword').value.trim();
        document.getElementById('txtConfirmpassword').value = verifyPassword;
        clearErrMsg();
        var flag = 0;
        if(oldPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtOldpasswordrfv').innerHTML = ' Please Enter Old Password';
            flag = 1;
        }
        else if(oldPassword.length < 6 || oldPassword.length > 20)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtOldpasswordrev').innerHTML = ' Password should be 6 to 20 charactors';
            flag = 1;
        }


        if(newPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtNewpasswordrfv').innerHTML = ' Please Enter New Password';
            flag = 1;
        }
        else if(newPassword.length < 6 || newPassword.length > 20)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtNewpasswordrev').innerHTML = ' Password should be 6 to 20 charactors';
            flag = 1;
        }


        if(verifyPassword == '')
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtConfirmpasswordrfv').innerHTML = ' Please Enter Confirm Password';
            flag = 1;
        }
        else if(verifyPassword != newPassword)
        {
            //alert('Please Enter Old Password');
            document.getElementById('vldtxtConfirmpasswordcmp').innerHTML = ' New and Confirm Password should be same';
            flag = 1;
        }

        if(flag)
            return false;
        else
            document.submit();
}


