// JavaScript Document

// editor pop-up
var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+'');
}

//preload image 

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/////////////////
function change_image(id,arr)
{
    //if(document.getElementById(id))
    //{
        //alert(arr.length);
        split_content=arr.split(",");
        for(i=0; i<split_content.length; i++)
        {
            val=split_content[i];
            if(split_content[i]==id)
            {
                document.getElementById(id).src="SiteImages/Home_Arrow.gif";
            }
            else
            {
                val=split_content[i];
                document.getElementById(val).src="SiteImages/Home_Arrow_Blank.gif";
            }
        }
    //}
}

// up cart quantity
function UpValue(cart_id)
{
    //alert('cart_id = '+cart_id);
    var qid=document.getElementById(cart_id);
    first_value = qid.value;
    //alert('first_value = '+first_value);
    
    if( !isNaN( first_value )) // when not text
    {
        final_value = ++first_value;
        //alert('final_value = '+final_value);
        qid.value=final_value;
        //alert('final = '+qid.value);
    }
    else
    {
        alert('Check Quantity Value');
        qid.focus();
        return false;
    }
}

// down cart quantity
function DownValue(cart_id)
{
    //alert('cart_id = '+cart_id);
    var qid=document.getElementById(cart_id);
    first_value = qid.value;
    //alert('first_value = '+first_value);
    
    if( !isNaN( first_value )) // when not text
    {
        if(first_value==1)
        {
            alert('You Can not Choose Less than 1 Quantity');
            qid.focus();
            return false;
        }
        else
        {
            final_value = --first_value;
            //alert('final_value = '+final_value);
            qid.value=final_value;
            //alert('final = '+qid.value);
        }
    }
    else
    {
        alert('Check Quantity Value');
        qid.focus();
        return false;
    }
}

function Chk_Quantity_Format(cart_id)
{
    var qid=document.getElementById(cart_id);
    first_value = qid.value;
    initial_value=qid.value;
    
    if(isNaN( first_value )) // when text
    {
        alert('Check Quantity Value');
        qid.focus();
        return false;
    }
    else if(first_value=='')    // when empty
    {
        alert('Enter a Quantity Value');
        qid.focus();
        return false;
    }
    if(first_value< 0)
    {
       alert('Please enter a positive number');
       document.getElementById(cart_id).value=initial_value;
       qid.focus();
        return false;

    }

    if(first_value==0)
     {
      alert('Quantity cannot be ZERO');
      document.getElementById(cart_id).value=initial_value;
      qid.focus();
        return false;
     }
}

function blank(id)
{
        document.getElementById(id).value="";
}
function forgot_password(ctype)
{
        location.href="inside.php?type=6&ctype="+ctype;
}
function registration()
{
    if(document.getElementById("name").value == "") 
    {
        alert("Please Enter Your Name");
        document.getElementById("name").focus();
        return false;
    }
    

    /*if(document.getElementById("username1").value == "") 
    {
        alert("Please enter the Username.");
        document.getElementById("username1").focus();
        return false;
    }*/
    //if(document.getElementById("email").value =="")
    //{
    if(!isEmail(document.getElementById("email").value )) 
    {
        alert("Please Check your Email format");
        document.getElementById("email").focus();
        return false;
    }
    //}
    if(document.getElementById("country").value == "") 
    {
        alert("Please Enter Country Name");
        document.getElementById("country").focus();
        return false;
    }
    
    if(document.getElementById("phone_1").value == "") 
    {
        alert("Please Enter Phone Number");
        document.getElementById("phone_1").focus();
        return false;
    }
    if(document.getElementById("password1_").value == "") 
    {
        alert("Please Enter Password");
        document.getElementById("password1_").focus();
        return false;
    }
    if(document.getElementById("confirm_password1").value == "") 
    {
        alert("Please Enter Confirm Password");
        document.getElementById("confirm_password1").focus();
        return false;
    }
        
    if(document.getElementById("password1_").value != document.getElementById("confirm_password1").value) 
    {
        alert("Password and Verify Password must be same");
        document.getElementById("confirm_password1").focus();
        return false;
    }
}

function registration_update()
{
    if(document.getElementById("name").value == "") 
    {
        alert("Please Enter Your Name");
        document.getElementById("name").focus();
        return false;
    }

    /*if(document.getElementById("username1").value == "") 
    {
        alert("Please enter the Username.");
        document.getElementById("username1").focus();
        return false;
    }*/
    //if(document.getElementById("email").value =="")
    //{
    /*if(!isEmail(document.getElementById("email").value )) 
    {
        alert("Please Check your Email format");
        document.getElementById("email").focus();
        return false;
    }*/
    //}
    if(document.getElementById("country").value == "") 
    {
        alert("Please Enter Country Name");
        document.getElementById("country").focus();
        return false;
    }
    
    if(document.getElementById("phone_1").value == "") 
    {
        alert("Please Enter Phone Number");
        document.getElementById("phone_1").focus();
        return false;
    }
    
    // check if clicked change password
    
    if(document.getElementById("change_pass").style.display=="none")
    {
        if(document.getElementById("password_").value == "") 
        {
            alert("Please Enter Password");
            document.getElementById("password_").focus();
            return false;
        }
        if(document.getElementById("confirm_password").value == "") 
        {
            alert("Please Enter Confirm Password");
            document.getElementById("confirm_password").focus();
            return false;
        }
            
        if(document.getElementById("password_").value != document.getElementById("confirm_password").value) 
        {
            alert("Password and Verify Password must be same");
            document.getElementById("confirm_password").focus();
            return false;
        }
    }
}

function registration_step2()
{
        if(document.getElementById("city").value == "") 
    {
        alert("Please Enter Your City");
        document.getElementById("city").focus();
        return false;
    }

    if(document.getElementById("state").value == "") 
    {
        alert("Please enter the State.");
        document.getElementById("state").focus();
        return false;
    }
    if(document.getElementById("zip").value == "") 
    {
        alert("Please Enter Zip");
        document.getElementById("zip").focus();
        return false;
    }
    if(document.getElementById("country").value == "") 
    {
        alert("Please Enter Country");
        document.getElementById("country").focus();
        return false;
    }
    if(document.getElementById("address_1").value == "") 
    {
        alert("Please Enter Address");
        document.getElementById("address_1").focus();
        return false;
    }   
    
}

function registration_step3()
{
    if(document.getElementById("first_name").value == "") 
    {
        alert("Please Enter Your Name");
        document.getElementById("first_name").focus();
        return false;
    }
    if(document.getElementById("city").value == "") 
    {
        alert("Please Enter Your City");
        document.getElementById("city").focus();
        return false;
    }

    
    //if(document.getElementById("email").value =="")
    //{
        //if(!isEmail(document.getElementById("email").value )) 
//      {
//          alert("Please Check your Email format");
//          document.getElementById("email").focus();
//          return false;
//      }
    //}
    if(document.getElementById("zip").value == "") 
    {
        alert("Please Enter Zip");
        document.getElementById("zip").focus();
        return false;
    }
    if(document.getElementById("country").value == "0") 
    {
        alert("Please Enter Country");
        document.getElementById("country").focus();
        return false;
    }
    val=document.getElementById("country").value;
    split_content=val.split(",");
    
    if(split_content[0] != "Bangladesh") // for other country // && split_content[0] != "USA" && split_content[0] != "Canada") 
    {
        if(document.getElementById("state").value == "") 
        {
            alert("Please enter the State.");
            document.getElementById("state").focus();
            return false;
        }
    }
    
    if(split_content[0] == "Bangladesh") // for bangladesh only ( chk area )  
    {
        if(document.getElementById("area").value == "0") 
        {
            alert("Please enter the Area.");
            document.getElementById("area").focus();
            return false;
        }
    }
    
    if(document.getElementById("address_1").value == "") 
    {
        alert("Please Enter Address");
        document.getElementById("address_1").focus();
        return false;
    }   
    if(document.getElementById("phone_1").value != "") 
    {
        if(!IsNumeric(document.getElementById("phone_1").value))
        {
            alert("Phone Number should be numeric.");
            document.getElementById("phone_1").focus();
            return false;
        }
    }
    
    /*var stat;
    stat =  confirm("Are You Sure You Want To Shipping This Address?"); 
    
    if(stat==true)
    {
        return true;
    }
    else
    {
        return false;
    }*/
    
    
}
function isEmail(email) 
{
  if ((email.indexOf('@', 0) == -1) || email.indexOf('.') == -1) 
  {
    return false;
  }
 else { return true; }
}
function IsNumeric(strString)
   //  check for valid numeric strings  
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
function weightIsNumeric(strString)
   //  check for valid numeric strings  
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         alert("Please enter Numeric Value. i.e. 23.56");
         }
      }
   return blnResult;
   }
function add_to_cart(pid,pro_id,ctype)
{
    //alert("pid="+pid+"&pro_id"+pro_id);
    //location.href="inside.php?pid="+pid+"&pro_id"+pro_id+"&type=4";
    location.href="add_to_cart.php?pid="+pid+"&pro_id="+pro_id+"&ctype="+ctype;
}
function add_to_cart_submit(pid,pro_id,ctype)
{
    //alert("test");    
    //document.category.submit();
    if(document.getElementById('product_size'))
    {
        var val=document.getElementById('product_size').value;
        
    }
    else
    {
        val=0;
    }
    
    if(document.getElementById('pro_qty_detail'))
    {
        var pro_qty=document.getElementById('pro_qty_detail').value;
    }
    else
    {
        pro_qty=1;
    }
    //alert('pro_qty = '+pro_qty);
    
    location.href="add_to_cart.php?pid="+pid+"&pro_id="+pro_id+"&ctype="+ctype+"&option="+val+"&pro_qty="+pro_qty;
}
function check_login()
{
    alert('Please Sign In/Register to Checkout!');
    document.login.Username.focus();
}
function row_open()
{
        //if(document.getElementById("change_password").style.display=="none")
        //{
            try
            {
                document.getElementById("pass1").style.display="table-row";
                document.getElementById("pass2").style.display="table-row";
                document.getElementById("pass3").style.display="table-row";
                document.getElementById("pass4").style.display="table-row";
            }
            catch(eIE)
            {
                document.getElementById("pass1").style.display="inline";
                document.getElementById("pass2").style.display="inline";
                document.getElementById("pass3").style.display="inline";
                document.getElementById("pass4").style.display="inline";
            }
            document.getElementById("change_pass").style.display="none";
        
        
}
function Empty_pass(tf)

{

    if(tf.value=="")

        return true;

    else

        return false;

}
function Req_pass()

{

    if(Empty_pass(document.add_listing_prop.m_email)==true)

    {

        alert("Please fill Email...");

        document.add_listing_prop.m_email.focus();

        return false;

    }

    else

    {   

        var vv=document.add_listing_prop.m_email.value;

        var theStr = new String(vv);

        var index = theStr.indexOf("@");

        

        if (index > 0)

        {

            var pindex = theStr.indexOf(".",index);

                

            if (! ((pindex > index+1) && (theStr.length > pindex+1)) )

            {

                alert("Please fill valid Email...");

                document.add_listing_prop.m_email.focus();

                return false;

            }

        }

        else 

        { 

            alert("Please fill valid Email...");

            document.add_listing_prop.m_email.focus();

            return false; 

        }
    }



    return true;
}
function open_row(val)
{
         split_content=val.split(",");
         if(split_content[0]=="Bangladesh")
         {
                try
                {
                    document.getElementById("area_show").style.display="table-row";
                }
                catch(eIE)
                {
                    document.getElementById("area_show").style.display="inline";
                }
                document.getElementById("state_show").style.display="none";
                document.getElementById("state_world").style.display="none";
         }
         else
         {
                //alert('country = '+split_content[0]);
                if(split_content[0]=="USA" || split_content[0]=="Canada")
                {
                    if(document.getElementById("area_show"))
                        document.getElementById("area_show").style.display="none";  
                    if(document.getElementById("state_show"))
                        document.getElementById("state_show").style.display="none"; 
                    
                    try
                    {
                        document.getElementById("state_world").style.display="table-row";
                    }
                    catch(eIE)
                    {
                        document.getElementById("state_world").style.display="inline";
                    }
                    
                    
                }
                else
                {
                    try
                    {
                        document.getElementById("state_show").style.display="table-row";
                    }
                    catch(eIE)
                    {
                        document.getElementById("state_show").style.display="inline";
                    }
                    document.getElementById("area_show").style.display="none";
                    document.getElementById("state_world").style.display="none";
                }
         }
        
}
function vdelete_product(type,page,pid,pro_id,old_type,show) // for Products
{
        var stat;
        stat =  confirm("Are you sure you want to delete?"); 
        
        if(stat==true)
        {
             if(pro_id !="")
             {
                //location.href="inside.php?type="+type+"&page="+page+"&pid="+pid+"&pro_id="+pro_id+"&categ_id="+categ_id+"&mode=delete&goto="+old_type+"&show="+show;
                location.href="inside.php?type="+type+"&page="+page+"&pid="+pid+"&pro_id="+pro_id+"&mode=delete&goto="+old_type+"&show="+show;
             }
        }   
    
}
function vdelete_category(type,page,pid,categ_id)   // for Categories
{
        var stat;
        stat =  confirm("Are you sure you want to delete?"); 
        
        if(stat==true)
        {
             if(categ_id !="")
             {
                location.href="inside.php?type="+type+"&page="+page+"&pid="+pid+"&categ_id="+categ_id+"&mode=delete";
             }
        }   
    
}
function show_additional_info()
{
    try
    {
        document.getElementById("info1").style.display="table-row";
        document.getElementById("info2").style.display="table-row";
        document.getElementById("info3").style.display="table-row";
        document.getElementById("info4").style.display="table-row";
    }
    catch(eIE)
    {
        document.getElementById("info1").style.display="inline";
        document.getElementById("info2").style.display="inline";
        document.getElementById("info3").style.display="inline";
        document.getElementById("info4").style.display="inline";
    }   
}
function hide_additional_info()
{
        document.getElementById("info1").style.display="none";
        document.getElementById("info2").style.display="none";
        document.getElementById("info3").style.display="none";
        document.getElementById("info4").style.display="none";
}
function show_custom()
{
    try
    {
        document.getElementById("custom").style.display="table-row";
        
    }
    catch(eIE)
    {
        document.getElementById("custom").style.display="inline";
    }
}
function hide_custom()
{
    document.getElementById("custom").style.display="none";
    
}
function form_submit()
{
    document.category.submit();
}